Allow deleting own suggestions in Suggest phase and surface delete chip
This commit is contained in:
16
Program.cs
16
Program.cs
@@ -205,6 +205,22 @@ api.MapPost("/suggestions", async ([FromBody] SuggestionRequest request, HttpCon
|
||||
return Results.Created($"/api/suggestions/{suggestion.Id}", new { suggestion.Id });
|
||||
});
|
||||
|
||||
api.MapDelete("/suggestions/{id:int}", async (int id, HttpContext ctx, AppDbContext db) =>
|
||||
{
|
||||
var phase = await GetPhase(db);
|
||||
if (phase != Phase.Suggest)
|
||||
return PhaseMismatch(Phase.Suggest, phase);
|
||||
|
||||
var player = await GetOrCreatePlayer(ctx, db);
|
||||
var suggestion = await db.Suggestions.FirstOrDefaultAsync(s => s.Id == id && s.PlayerId == player.Id);
|
||||
if (suggestion == null)
|
||||
return Results.NotFound(new { error = "Suggestion not found." });
|
||||
|
||||
db.Suggestions.Remove(suggestion);
|
||||
await db.SaveChangesAsync();
|
||||
return Results.NoContent();
|
||||
});
|
||||
|
||||
api.MapGet("/suggestions/all", async (AppDbContext db) =>
|
||||
{
|
||||
var phase = await GetPhase(db);
|
||||
|
||||
Reference in New Issue
Block a user