Standardize service errors with ProblemDetails envelope
This commit is contained in:
@@ -48,11 +48,11 @@ internal sealed class AdminWorkflowService(AppDbContext db)
|
||||
{
|
||||
var player = await db.Players.FirstOrDefaultAsync(p => p.Id == request.PlayerId);
|
||||
if (player is null)
|
||||
return Results.NotFound(new { error = "Player not found." });
|
||||
return EndpointHelpers.NotFoundError("Player not found.");
|
||||
|
||||
var phase = await EndpointHelpers.GetCurrentPhaseAsync(db, player.Id);
|
||||
if (phase != Phase.Vote)
|
||||
return Results.BadRequest(new { error = "Player must be in the Vote phase to receive a joker." });
|
||||
return EndpointHelpers.BadRequestError("Player must be in the Vote phase to receive a joker.");
|
||||
|
||||
player.HasJoker = true;
|
||||
player.VotesFinal = false;
|
||||
@@ -65,7 +65,7 @@ internal sealed class AdminWorkflowService(AppDbContext db)
|
||||
{
|
||||
var player = await db.Players.Include(p => p.Suggestions).FirstOrDefaultAsync(p => p.Id == playerId);
|
||||
if (player is null)
|
||||
return Results.NotFound(new { error = "Player not found." });
|
||||
return EndpointHelpers.NotFoundError("Player not found.");
|
||||
|
||||
await using var tx = await db.Database.BeginTransactionAsync();
|
||||
|
||||
@@ -95,20 +95,20 @@ internal sealed class AdminWorkflowService(AppDbContext db)
|
||||
return EndpointHelpers.PhaseMismatch(Phase.Vote, phase);
|
||||
|
||||
if (request.SourceSuggestionId == request.TargetSuggestionId)
|
||||
return Results.BadRequest(new { error = "Pick two different games to link." });
|
||||
return EndpointHelpers.BadRequestError("Pick two different games to link.");
|
||||
|
||||
var suggestions = await db.Suggestions.ToListAsync();
|
||||
var source = suggestions.FirstOrDefault(s => s.Id == request.SourceSuggestionId);
|
||||
var target = suggestions.FirstOrDefault(s => s.Id == request.TargetSuggestionId);
|
||||
if (source is null || target is null)
|
||||
return Results.NotFound(new { error = "Suggestion not found." });
|
||||
return EndpointHelpers.NotFoundError("Suggestion not found.");
|
||||
|
||||
var rootIndex = EndpointHelpers.BuildLinkRoots(suggestions.Select(s => (s.Id, s.ParentSuggestionId)));
|
||||
if (!rootIndex.TryGetValue(source.Id, out var sourceRoot) || !rootIndex.TryGetValue(target.Id, out var targetRoot))
|
||||
return Results.NotFound(new { error = "Suggestion not found." });
|
||||
return EndpointHelpers.NotFoundError("Suggestion not found.");
|
||||
|
||||
if (sourceRoot == targetRoot)
|
||||
return Results.BadRequest(new { error = "These games are already linked." });
|
||||
return EndpointHelpers.BadRequestError("These games are already linked.");
|
||||
|
||||
var affectedRootIds = new HashSet<int>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user