|
| 1 | +using Microsoft.EntityFrameworkCore; |
| 2 | +using Vote.Monitor.Domain; |
| 3 | + |
| 4 | +namespace Feature.Form.Submissions.SetCompletionV2; |
| 5 | + |
| 6 | +public class Endpoint(IAuthorizationService authorizationService, VoteMonitorContext context) |
| 7 | + : Endpoint<Request, Results<NoContent, NotFound>> |
| 8 | +{ |
| 9 | + public override void Configure() |
| 10 | + { |
| 11 | + Put("/api/election-rounds/{electionRoundId}/form-submissions/{submissionId}:setCompletion"); |
| 12 | + DontAutoTag(); |
| 13 | + Options(x => x.WithTags("form-submissions", "mobile")); |
| 14 | + Summary(s => { s.Summary = "Updates completion status status for a submission"; }); |
| 15 | + |
| 16 | + Policies(PolicyNames.ObserversOnly); |
| 17 | + } |
| 18 | + |
| 19 | + public override async Task<Results<NoContent, NotFound>> ExecuteAsync(Request req, CancellationToken ct) |
| 20 | + { |
| 21 | + var authorizationResult = |
| 22 | + await authorizationService.AuthorizeAsync(User, new MonitoringObserverRequirement(req.ElectionRoundId)); |
| 23 | + if (!authorizationResult.Succeeded) |
| 24 | + { |
| 25 | + return TypedResults.NotFound(); |
| 26 | + } |
| 27 | + |
| 28 | + await context.FormSubmissions |
| 29 | + .Where(x => x.MonitoringObserver.ObserverId == req.ObserverId |
| 30 | + && x.MonitoringObserver.ElectionRoundId == req.ElectionRoundId |
| 31 | + && x.ElectionRoundId == req.ElectionRoundId |
| 32 | + && x.Id == req.SubmissionId |
| 33 | + && x.Form.ElectionRoundId == req.ElectionRoundId) |
| 34 | + .ExecuteUpdateAsync(x => x.SetProperty(p => p.IsCompleted, req.IsCompleted), cancellationToken: ct); |
| 35 | + |
| 36 | + return TypedResults.NoContent(); |
| 37 | + } |
| 38 | +} |
0 commit comments