Update Swagger UI paths and add POST /todo endpoint

Changed Swagger UI configuration paths for improved clarity and consistency. Added a new POST /todo endpoint to allow creation of Todo items in the database.
This commit is contained in:
Tony Bark 2025-11-27 12:28:19 -05:00
parent dc4af28f97
commit 725d4bdeaf

View file

@ -16,8 +16,8 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUi(cfg =>
{
cfg.DocumentTitle = "BarkAPI";
cfg.Path = "/api";
cfg.DocumentPath = "/api/{documentName}/swagger.json}";
cfg.Path = "/swagger";
cfg.DocumentPath = "/swagger/{documentName}/swagger.json}";
cfg.DocExpansion = "list";
});
}
@ -68,4 +68,12 @@ app.MapGet("/todo/{id}", async (int id, TodoDb db) =>
return Results.NotFound();
});
app.MapPost("/todo", async (Todo todo, TodoDb db) =>
{
db.Todos.Add(todo);
await db.SaveChangesAsync();
return Results.Created($"/todo/{todo.Id}", todo);
});
app.Run();