Initial commit
This commit is contained in:
commit
49d2d70965
19 changed files with 4912 additions and 0 deletions
10
server/BooksServer.csproj
Normal file
10
server/BooksServer.csproj
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
62
server/Program.cs
Normal file
62
server/Program.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
const string CorsPolicy = "_corsAllowAll";
|
||||
|
||||
var builder = WebApplication.CreateSlimBuilder(args);
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(CorsPolicy,
|
||||
b =>
|
||||
{
|
||||
b.AllowAnyOrigin();
|
||||
b.AllowAnyMethod();
|
||||
b.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
app.UseCors(CorsPolicy);
|
||||
|
||||
Book[] books =
|
||||
[
|
||||
new ("To Kill a Mockingbird", "Harper Lee", "J. B. Lippincott & Co.", 1960, "9780965773607"),
|
||||
new ("1984", "George Orwell", "Secker & Warburg", 1949, "9780436410550"),
|
||||
new ("The Great Gatsby", "F. Scott Fitzgerald", "Charles Scribner's Sons", 1925, "9780684717609"),
|
||||
new ("The Catcher in the Rye", "J.D. Salinger", "Little, Brown and Company", 1951, "9780316769488"),
|
||||
new ("The Hobbit", "J.R.R. Tolkien", "Allen & Unwin", 1937, "9780048231543"),
|
||||
new ("The Lord of the Rings", "J.R.R. Tolkien", "Allen & Unwin", 1954, "9780048230454"),
|
||||
new ("Brave New World", "Aldous Huxley", "Chatto & Windus", 1932, "9780701107918"),
|
||||
new ("Moby-Dick", "Herman Melville", "Harper & Brothers", 1851, "9781122714389"),
|
||||
new ("War and Peace", "Leo Tolstoy", "The Russian Messenger", 1869, "9781535299534"),
|
||||
new ("Crime and Punishment", "Fyodor Dostoevsky", "The Russian Messenger", 1866, "9789352763160"),
|
||||
new ("Pride and Prejudice", "Jane Austen", "T. Egerton, Whitehall", 1813, "9781532995842"),
|
||||
new ("The Odyssey", "Homer", "Penguin Classics", -800, "9780140449112"),
|
||||
new ("One Hundred Years of Solitude", "Gabriel García Márquez", "Harper & Row", 1967, "9780060114183"),
|
||||
new ("Ulysses", "James Joyce", "Sylvia Beach", 1922, "9783518472279"),
|
||||
new ("Don Quixote", "Miguel de Cervantes", "Francisco de Robles", 1605, "9798595886857"),
|
||||
new ("Madame Bovary", "Gustave Flaubert", "Michel Lévy Frères", 1857, "9781543023039"),
|
||||
new ("Wuthering Heights", "Emily Brontë", "Thomas Cautley Newby", 1847, "9781549501296"),
|
||||
new ("The Brothers Karamazov", "Fyodor Dostoevsky", "The Russian Messenger", 1880, "9780553212167"),
|
||||
new ("Anna Karenina", "Leo Tolstoy", "The Russian Messenger", 1877, "9781535299008"),
|
||||
new ("The Adventures of Huckleberry Finn", "Mark Twain", "Charles L. Webster and Company", 1884, "9780486443225"),
|
||||
new ("The Iliad", "Homer", "Penguin Classics", -762, "9780140445923"),
|
||||
new ("Hamlet", "William Shakespeare", "Folger", 1603, "9781451669411"),
|
||||
new ("The Divine Comedy", "Dante Alighieri", "Benedetto Cairoli", 1320, "9780451208637"),
|
||||
new ("Middlemarch", "George Eliot", "William Blackwood and Sons", 1871, "9781362391845"),
|
||||
new ("Remembrance of Things Past", "Marcel Proust", "Grasset and Gallimard", 1913, "9782070754922"),
|
||||
new ("Great Expectations", "Charles Dickens", "Chapman & Hall", 1861, "9781503275188"),
|
||||
new ("Gulliver's Travels", "Jonathan Swift", "Benjamin Motte", 1726, "9783150108215"),
|
||||
new ("Bleak House", "Charles Dickens", "Bradbury & Evans", 1853, "9780141439723"),
|
||||
new ("Les Misérables", "Victor Hugo", "A. Lacroix, Verboeckhoven & Ce", 1862, "9781271955978"),
|
||||
new ("The Sound and the Fury", "William Faulkner", "Jonathan Cape and Harrison Smith", 1929, "9789123412167"),
|
||||
new ("Frankenstein", "Mary Shelley", "Lackington, Hughes, Harding, Mavor & Jones", 1818, "9780441439472"),
|
||||
new ("The Picture of Dorian Gray", "Oscar Wilde", "Ward, Lock and Company", 1890, "9780241439571")
|
||||
];
|
||||
|
||||
app.MapGet("/books", () =>
|
||||
{
|
||||
return books.OrderBy(b => b.Year);
|
||||
});
|
||||
|
||||
await app.RunAsync();
|
||||
|
||||
public sealed record Book(string Title, string Author, string Publisher, int Year, string ISBN);
|
||||
4
server/books.http
Normal file
4
server/books.http
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
@Host = http://localhost:5000
|
||||
|
||||
### Get all books
|
||||
GET {{Host}}/books
|
||||
40
server/run.ps1
Normal file
40
server/run.ps1
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
$dotnetVersionStr = (& dotnet --version).Trim()
|
||||
try {
|
||||
$dotnetVersion = [version]$dotnetVersionStr
|
||||
} catch {
|
||||
Write-Error "Unable to parse dotnet version: $dotnetVersionStr"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$csprojFile = Get-ChildItem -Path . -Filter *.csproj | Select-Object -First 1
|
||||
if (-not $csprojFile) {
|
||||
Write-Host "No csproj file found in the current directory."
|
||||
exit 1
|
||||
}
|
||||
|
||||
[xml]$csprojXml = Get-Content $csprojFile.FullName
|
||||
$targetFramework = $csprojXml.Project.PropertyGroup.TargetFramework
|
||||
if (-not $targetFramework) {
|
||||
Write-Host "TargetFramework element not found in $($csprojFile.Name)."
|
||||
exit 1
|
||||
}
|
||||
if ($targetFramework -match 'net(\d+(\.\d+)?)') {
|
||||
$requiredVersionStr = $matches[1]
|
||||
try {
|
||||
$requiredVersion = [version]$requiredVersionStr
|
||||
} catch {
|
||||
Write-Host "Unable to parse required version: $requiredVersionStr"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Unrecognized TargetFramework format: $targetFramework"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($dotnetVersion -lt $requiredVersion) {
|
||||
Write-Warning "Your dotnet version ($dotnetVersion) is outdated. Go to https://get.dot.net and download the latest SDK"
|
||||
} else {
|
||||
Write-Host "Your dotnet version ($dotnetVersion) is up to date"
|
||||
Write-Host "Starting the server - keep the console window open!"
|
||||
dotnet run
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue