Skip to content

Commit 9e7be30

Browse files
authored
add missing endpoint (#1037)
1 parent 70d2fb1 commit 9e7be30

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

api/src/Feature.Form.Submissions/SetCompletion/Endpoint.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Feature.Form.Submissions.SetCompletion;
55

6+
[Obsolete("Will be removed in future version")]
67
public class Endpoint(IAuthorizationService authorizationService, VoteMonitorContext context)
78
: Endpoint<Request, Results<NoContent, NotFound>>
89
{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Vote.Monitor.Core.Security;
2+
3+
namespace Feature.Form.Submissions.SetCompletionV2;
4+
5+
public class Request
6+
{
7+
public Guid ElectionRoundId { get; set; }
8+
9+
[FromClaim(ApplicationClaimTypes.UserId)]
10+
public Guid ObserverId { get; set; }
11+
public Guid SubmissionId { get; set; }
12+
public bool IsCompleted { get; set; }
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Feature.Form.Submissions.SetCompletionV2;
2+
3+
public class Validator : Validator<Request>
4+
{
5+
public Validator()
6+
{
7+
RuleFor(x => x.ElectionRoundId).NotEmpty();
8+
RuleFor(x => x.ObserverId).NotEmpty();
9+
RuleFor(x => x.SubmissionId).NotEmpty();
10+
}
11+
}

0 commit comments

Comments
 (0)