mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add .NET 8 templated projects.
This commit is contained in:
33
Aaru.Server.Api/Program.cs
Normal file
33
Aaru.Server.Api/Program.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
var builder = WebApplication.CreateSlimBuilder(args);
|
||||
|
||||
builder.Services.ConfigureHttpJsonOptions(options =>
|
||||
{
|
||||
options.SerializerOptions.TypeInfoResolverChain.Insert(0,
|
||||
AppJsonSerializerContext.Default);
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
var sampleTodos = new Todo[]
|
||||
{
|
||||
new(1, "Walk the dog"), new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
|
||||
new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))), new(4, "Clean the bathroom"),
|
||||
new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2)))
|
||||
};
|
||||
|
||||
var todosApi = app.MapGroup("/todos");
|
||||
todosApi.MapGet("/", () => sampleTodos);
|
||||
|
||||
todosApi.MapGet("/{id}",
|
||||
(int id) => sampleTodos.FirstOrDefault(a => a.Id == id) is {} todo
|
||||
? Results.Ok(todo)
|
||||
: Results.NotFound());
|
||||
|
||||
app.Run();
|
||||
|
||||
public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false);
|
||||
|
||||
[JsonSerializable(typeof(Todo[]))]
|
||||
internal partial class AppJsonSerializerContext : JsonSerializerContext {}
|
||||
Reference in New Issue
Block a user