ex-ex-02-books/server/Program.cs
github-classroom[bot] 49d2d70965
Initial commit
2025-06-03 15:21:16 +00:00

62 lines
No EOL
3.6 KiB
C#

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);