Refactor Card Model to manage endpoint routing
This commit is contained in:
@@ -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();
|
||||
Reference in New Issue
Block a user