Standardize service errors with ProblemDetails envelope
This commit is contained in:
@@ -29,17 +29,17 @@ internal sealed class VoteWorkflowService(AppDbContext db)
|
||||
public async Task<IResult> UpsertAsync(Player player, VoteRequest request)
|
||||
{
|
||||
if (request.Score is < 0 or > 10)
|
||||
return Results.BadRequest(new { error = "Score must be between 0 and 10." });
|
||||
return EndpointHelpers.BadRequestError("Score must be between 0 and 10.");
|
||||
|
||||
if (player.VotesFinal)
|
||||
return Results.BadRequest(new { error = "Votes are finalized. Unfinalize before changing scores." });
|
||||
return EndpointHelpers.BadRequestError("Votes are finalized. Unfinalize before changing scores.");
|
||||
|
||||
var phase = await EndpointHelpers.GetCurrentPhaseAsync(db, player.Id);
|
||||
if (phase != Phase.Vote)
|
||||
return EndpointHelpers.PhaseMismatch(Phase.Vote, phase);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(player.DisplayName))
|
||||
return Results.BadRequest(new { error = "Set a display name before voting." });
|
||||
return EndpointHelpers.BadRequestError("Set a display name before voting.");
|
||||
|
||||
var linkMap = await db.Suggestions
|
||||
.AsNoTracking()
|
||||
@@ -51,7 +51,7 @@ internal sealed class VoteWorkflowService(AppDbContext db)
|
||||
.ToListAsync();
|
||||
var rootIndex = EndpointHelpers.BuildLinkRoots(linkMap.Select(s => (s.Id, s.ParentSuggestionId)));
|
||||
if (!rootIndex.ContainsKey(request.SuggestionId))
|
||||
return Results.BadRequest(new { error = "Suggestion not found." });
|
||||
return EndpointHelpers.BadRequestError("Suggestion not found.");
|
||||
|
||||
var linkedIds = EndpointHelpers.LinkedIdsFor(request.SuggestionId, rootIndex);
|
||||
if (linkedIds.Count == 0)
|
||||
|
||||
Reference in New Issue
Block a user