@@ -6,7 +6,7 @@ namespace Feature.Form.Submissions.GetByIdV2;
66public class Endpoint (
77 IAuthorizationService authorizationService ,
88 INpgsqlConnectionFactory dbConnectionFactory ,
9- IFileStorageService fileStorageService ) : Endpoint < Request , Results < Ok < FormSubmissionView > , NotFound > >
9+ IFileStorageService fileStorageService ) : Endpoint < Request , Results < Ok < FormSubmissionViewV2 > , NotFound > >
1010{
1111 public override void Configure ( )
1212 {
@@ -18,7 +18,7 @@ public override void Configure()
1818 Policies ( PolicyNames . NgoAdminsOnly ) ;
1919 }
2020
21- public override async Task < Results < Ok < FormSubmissionView > , NotFound > > ExecuteAsync ( Request req ,
21+ public override async Task < Results < Ok < FormSubmissionViewV2 > , NotFound > > ExecuteAsync ( Request req ,
2222 CancellationToken ct )
2323 {
2424 var authorizationResult =
@@ -30,70 +30,63 @@ public override async Task<Results<Ok<FormSubmissionView>, NotFound>> ExecuteAsy
3030
3131 var sql = """
3232 WITH submissions AS
33- (SELECT psi."Id" AS "SubmissionId",
34- 'PSI' AS "FormType",
35- 'PSI' AS "FormCode",
36- psi."PollingStationId",
37- psi."MonitoringObserverId",
38- psi."Answers",
39- (SELECT "Id"
40- FROM "PollingStationInformationForms"
41- WHERE "ElectionRoundId" = @electionRoundId) AS "FormId",
42- psi."FollowUpStatus" as "FollowUpStatus",
43- '[]'::jsonb AS "Attachments",
44- '[]'::jsonb AS "Notes",
45- "LastUpdatedAt" AS "TimeSubmitted",
46- psi."ArrivalTime",
47- psi."DepartureTime",
48- psi."Breaks",
49- psi."IsCompleted"
50- FROM "PollingStationInformation" psi
51- INNER JOIN "GetAvailableMonitoringObservers"(@electionRoundId, @ngoId, 'Coalition') AMO on AMO."MonitoringObserverId" = psi."MonitoringObserverId"
52- WHERE psi."Id" = @submissionId and psi."ElectionRoundId" = @electionRoundId
53- UNION ALL
54- SELECT
55- fs."Id" AS "SubmissionId",
56- f."FormType" AS "FormType",
57- f."Code" AS "FormCode",
58- fs."PollingStationId",
59- fs."MonitoringObserverId",
60- fs."Answers",
61- f."Id" AS "FormId",
62- fs."FollowUpStatus",
63- COALESCE((select jsonb_agg(jsonb_build_object('QuestionId', "QuestionId", 'FileName', "FileName", 'MimeType', "MimeType", 'FilePath', "FilePath", 'UploadedFileName', "UploadedFileName", 'TimeSubmitted', "LastUpdatedAt"))
64- FROM "Attachments" a
65- WHERE
66- (
67- (A."FormId" = FS."FormId" AND FS."PollingStationId" = A."PollingStationId") -- backwards compatibility
68- OR A."SubmissionId" = FS."Id"
69- )
70- AND a."MonitoringObserverId" = fs."MonitoringObserverId"
71- AND a."IsDeleted" = false
72- AND a."IsCompleted" = true),'[]'::JSONB) AS "Attachments",
33+ (SELECT psi."Id" AS "SubmissionId",
34+ psi."PollingStationId",
35+ psi."MonitoringObserverId",
36+ psi."Answers",
37+ psif."Id" AS "FormId",
38+ psi."FollowUpStatus" as "FollowUpStatus",
39+ '[]'::jsonb AS "Attachments",
40+ '[]'::jsonb AS "Notes",
41+ "LastUpdatedAt" AS "TimeSubmitted",
42+ psi."ArrivalTime",
43+ psi."DepartureTime",
44+ psi."Breaks",
45+ psi."IsCompleted"
46+ FROM "PollingStationInformation" psi
47+ INNER JOIN "GetAvailableMonitoringObservers"(@electionRoundId, @ngoId, 'Coalition') AMO on AMO."MonitoringObserverId" = psi."MonitoringObserverId"
48+ INNER JOIN "PollingStationInformationForms" psif on psi."ElectionRoundId" = psif."ElectionRoundId"
49+ WHERE psi."Id" = @submissionId and psi."ElectionRoundId" = @electionRoundId
50+ UNION ALL
51+ SELECT
52+ fs."Id" AS "SubmissionId",
53+ fs."PollingStationId",
54+ fs."MonitoringObserverId",
55+ fs."Answers",
56+ f."Id" AS "FormId",
57+ fs."FollowUpStatus",
58+ COALESCE((select jsonb_agg(jsonb_build_object('QuestionId', "QuestionId", 'FileName', "FileName", 'MimeType', "MimeType", 'FilePath', "FilePath", 'UploadedFileName', "UploadedFileName", 'TimeSubmitted', "LastUpdatedAt"))
59+ FROM "Attachments" a
60+ WHERE
61+ (
62+ (A."FormId" = FS."FormId" AND FS."PollingStationId" = A."PollingStationId") -- backwards compatibility
63+ OR A."SubmissionId" = FS."Id"
64+ )
65+ AND a."MonitoringObserverId" = fs."MonitoringObserverId"
66+ AND a."IsDeleted" = false
67+ AND a."IsCompleted" = true),'[]'::JSONB) AS "Attachments",
7368
74- COALESCE((select jsonb_agg(jsonb_build_object('QuestionId', "QuestionId", 'Text', "Text", 'TimeSubmitted', "LastUpdatedAt"))
75- FROM "Notes" n
76- WHERE
77- (
78- (N."FormId" = FS."FormId" AND FS."PollingStationId" = N."PollingStationId") -- backwards compatibility
79- OR N."SubmissionId" = FS."Id"
80- )
81- AND n."MonitoringObserverId" = fs."MonitoringObserverId"), '[]'::JSONB) AS "Notes",
82-
83- "LastUpdatedAt" AS "TimeSubmitted",
84- NULL AS "ArrivalTime",
85- NULL AS "DepartureTime",
86- '[]'::jsonb AS "Breaks",
87- fs."IsCompleted"
88- FROM "FormSubmissions" fs
89- INNER JOIN "GetAvailableMonitoringObservers"(@electionRoundId, @ngoId, 'Coalition') AMO on AMO."MonitoringObserverId" = FS."MonitoringObserverId"
90- INNER JOIN "Forms" f ON f."Id" = fs."FormId"
91- WHERE fs."Id" = @submissionId and fs."ElectionRoundId" = @electionRoundId)
69+ COALESCE((select jsonb_agg(jsonb_build_object('QuestionId', "QuestionId", 'Text', "Text", 'TimeSubmitted', "LastUpdatedAt"))
70+ FROM "Notes" n
71+ WHERE
72+ (
73+ (N."FormId" = FS."FormId" AND FS."PollingStationId" = N."PollingStationId") -- backwards compatibility
74+ OR N."SubmissionId" = FS."Id"
75+ )
76+ AND n."MonitoringObserverId" = fs."MonitoringObserverId"), '[]'::JSONB) AS "Notes",
77+
78+ "LastUpdatedAt" AS "TimeSubmitted",
79+ NULL AS "ArrivalTime",
80+ NULL AS "DepartureTime",
81+ '[]'::jsonb AS "Breaks",
82+ fs."IsCompleted"
83+ FROM "FormSubmissions" fs
84+ INNER JOIN "GetAvailableMonitoringObservers"(@electionRoundId, @ngoId, 'Coalition') AMO on AMO."MonitoringObserverId" = FS."MonitoringObserverId"
85+ INNER JOIN "Forms" f ON f."Id" = fs."FormId"
86+ WHERE fs."Id" = @submissionId and fs."ElectionRoundId" = @electionRoundId)
9287 SELECT s."SubmissionId",
9388 s."FormId",
9489 s."TimeSubmitted",
95- s."FormCode",
96- s."FormType",
9790 ps."Id" AS "PollingStationId",
9891 ps."Level1",
9992 ps."Level2",
@@ -117,20 +110,20 @@ UNION ALL
117110 s."Breaks",
118111 s."IsCompleted"
119112 FROM submissions s
120- INNER JOIN "PollingStations" ps ON ps."Id" = s."PollingStationId"
121- INNER JOIN "GetAvailableMonitoringObservers"(@electionRoundId, @ngoId, 'Coalition') AMO on AMO."MonitoringObserverId" = s."MonitoringObserverId"
113+ INNER JOIN "PollingStations" ps ON ps."Id" = s."PollingStationId"
114+ INNER JOIN "GetAvailableMonitoringObservers"(@electionRoundId, @ngoId, 'Coalition') AMO on AMO."MonitoringObserverId" = s."MonitoringObserverId"
122115 """ ;
123116
124117 var queryArgs = new
125118 {
126119 electionRoundId = req . ElectionRoundId , ngoId = req . NgoId , submissionId = req . SubmissionId
127120 } ;
128121
129- FormSubmissionView submission = null ;
122+ FormSubmissionViewV2 submission = null ;
130123
131124 using ( var dbConnection = await dbConnectionFactory . GetOpenConnectionAsync ( ct ) )
132125 {
133- submission = await dbConnection . QueryFirstOrDefaultAsync < FormSubmissionView > ( sql , queryArgs ) ;
126+ submission = await dbConnection . QueryFirstOrDefaultAsync < FormSubmissionViewV2 > ( sql , queryArgs ) ;
134127 }
135128
136129 if ( submission is null )
0 commit comments