Refactor Card Model to manage endpoint routing

This commit is contained in:
2025-12-29 17:12:08 -06:00
parent 41d1cc4fc0
commit b01ff470ac
4 changed files with 43 additions and 42 deletions

View File

@@ -37,34 +37,6 @@ if (app.Environment.IsDevelopment())
app.UseHttpsRedirection();
app.MapPost("/card", async (CardInput input, ICardModel card) =>
{
var newCard = await card.CreateAsync(input);
return Results.Created($"/card/{newCard.Id}", newCard);
});
app.MapGet("/card", async (ICardModel card) =>
{
var result = await card.GetAllAsync();
return Results.Ok(result);
});
app.MapGet("/card/{id}", async (int id, ICardModel card) =>
{
var newCard = await card.GetByIdAsync(id);
return newCard is not null ? Results.Ok(newCard) : Results.NotFound();
});
app.MapPut("/card/{id}", async (int id, CardInput input, ICardModel card) =>
{
var newCard = await card.UpdateAsync(id, input);
return newCard is not null ? Results.Ok(newCard) : Results.NotFound();
});
app.MapDelete("/card/{id}", async (int id, ICardModel card) =>
{
var success = await card.DeleteAsync(id);
return success ? Results.NoContent() : Results.NotFound();
});
CardModel.MapEndpoints(app);
app.Run();