diff --git a/core/src/main/java/nl/tudelft/ewi/auta/core/controller/SubmissionController.java b/core/src/main/java/nl/tudelft/ewi/auta/core/controller/SubmissionController.java index 26e4f58d62c4f7b5831f8380738defecb6ca14c7..824686b6c102963b9ca007666254122eefad54ea 100644 --- a/core/src/main/java/nl/tudelft/ewi/auta/core/controller/SubmissionController.java +++ b/core/src/main/java/nl/tudelft/ewi/auta/core/controller/SubmissionController.java @@ -125,7 +125,8 @@ public class SubmissionController extends ControllerBase { public ResponseEntity<Response> getAllSubmissions( final @PathVariable String aid, final @RequestParam(value = "page", required = false) Optional<Integer> pageNum, - final @RequestParam(value = "size", required = false) Optional<Integer> pageSize + final @RequestParam(value = "size", required = false) Optional<Integer> pageSize, + final @RequestParam(value = "iid", required = false) Optional<String> iid ) { final var res = new Response(); @@ -145,13 +146,20 @@ public class SubmissionController extends ControllerBase { map.put("id", submission.getId()); map.put("name", submission.getName()); + map.put("identity", identityRepository.findById(submission.getId()).orElse(null)); return map; }) + .filter(submission -> { + final var optionalIdentity = (IdentityContainer) submission.get("identity"); + return iid.isEmpty() || optionalIdentity.getIdentifier().equals(iid.get()); + }) .collect(Collectors.toList()); + + res.put("numPages", page.getTotalPages()); res.put("page", pageIndex + 1); res.put("submissions", submissions); diff --git a/core/src/test/java/nl/tudelft/ewi/auta/core/controller/SubmissionControllerTest.java b/core/src/test/java/nl/tudelft/ewi/auta/core/controller/SubmissionControllerTest.java index b7e8b818b701de587ffe227ca5c7813dd6f0860d..2da79a9a786468c941b4e86cabc880a089c6b3c1 100644 --- a/core/src/test/java/nl/tudelft/ewi/auta/core/controller/SubmissionControllerTest.java +++ b/core/src/test/java/nl/tudelft/ewi/auta/core/controller/SubmissionControllerTest.java @@ -3,12 +3,13 @@ package nl.tudelft.ewi.auta.core.controller; import freemarker.template.TemplateException; import nl.tudelft.ewi.auta.common.model.entity.ProjectEntity; import nl.tudelft.ewi.auta.core.database.AssignmentRepository; -import nl.tudelft.ewi.auta.core.database.EntityContainer; -import nl.tudelft.ewi.auta.core.database.EntityRepository; -import nl.tudelft.ewi.auta.core.database.IdentityRepository; import nl.tudelft.ewi.auta.core.database.Repositories; import nl.tudelft.ewi.auta.core.database.ResultsRepository; import nl.tudelft.ewi.auta.core.database.SubmissionRepository; +import nl.tudelft.ewi.auta.core.database.EntityRepository; +import nl.tudelft.ewi.auta.core.database.EntityContainer; +import nl.tudelft.ewi.auta.core.database.IdentityRepository; +import nl.tudelft.ewi.auta.core.database.IdentityContainer; import nl.tudelft.ewi.auta.core.jobs.JobQueue; import nl.tudelft.ewi.auta.core.model.Assignment; import nl.tudelft.ewi.auta.core.model.FileStore; @@ -53,6 +54,7 @@ public class SubmissionControllerTest { private static final String SUBMISSION_NAME = "test submission"; private static final String UNIQUE_ASSIGNMENT_ID = "UNIQUE_ASSIGNMENT_ID"; private static final String UNIQUE_SUBMISSION_ID = "UNIQUE_SUBMISSION_ID"; + private static final String UNIQUE_IDENTITY_ID = "UNIQUE_IDENTITY_ID"; private static final String UNIQUE_RESULTSCONTAINER_ID = "UNIQUE_RESULTSCONTAINER_ID"; private static final String FILENAME_WITHOUT_ERROR = "filename"; private static final String HTML_STRING = "HTML"; @@ -151,6 +153,10 @@ public class SubmissionControllerTest { ) ).thenReturn(new PageImpl<>(Collections.singletonList(this.submission))); + Mockito.when( + this.identityRepository.findById(Mockito.eq(UNIQUE_SUBMISSION_ID)) + ).thenReturn(Optional.of(new IdentityContainer(UNIQUE_SUBMISSION_ID, UNIQUE_IDENTITY_ID))); + this.report = this.setUpReport(); Mockito.when(this.htmlReportGenerator.generateReport(Mockito.any())) @@ -212,6 +218,25 @@ public class SubmissionControllerTest { .andExpect(jsonPath("$.submissions[0].id", equalTo(UNIQUE_SUBMISSION_ID))); } + @Test + public void testgetAllByIid() throws Exception { + this.mvc.perform(request(HttpMethod.GET, + "/api/v1/assignment/" + UNIQUE_ASSIGNMENT_ID + + "/submission?iid=" + UNIQUE_IDENTITY_ID)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.errors", hasSize(0))) + .andExpect(jsonPath("$.submissions", hasSize(1))); + } + + @Test + public void testGetByIidNoSubmission() throws Exception { + this.mvc.perform(request(HttpMethod.GET, + "/api/v1/assignment/" + UNIQUE_ASSIGNMENT_ID + "/submission?iid=FAKE_ID")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.errors", hasSize(0))) + .andExpect(jsonPath("$.submissions", hasSize(0))); + } + @Test public void testAddSubmission() throws Exception { String content = "stuff"; diff --git a/doc/api/proposal/index.html b/doc/api/proposal/index.html index 9436dce9c5d7d98f60be9d53267c29508d6e2400..3d41bb7def8facaecf9d0960cc4b415fa0607258 100644 --- a/doc/api/proposal/index.html +++ b/doc/api/proposal/index.html @@ -657,6 +657,12 @@ Content-Type: application/json <td>no</td> <td>the number of submissions per page. Defaults to 25, and at most 1000.</td> </tr> + <tr> + <td>iid</td> + <td>string</td> + <td>no</td> + <td>the identity of the submissions you would like to receive</td> + </tr> </table> </div>