diff --git a/api/src/main/java/ca/bc/gov/educ/eas/api/controller/v1/AssessmentStudentController.java b/api/src/main/java/ca/bc/gov/educ/eas/api/controller/v1/AssessmentStudentController.java index 8bb19c7..effc6b0 100644 --- a/api/src/main/java/ca/bc/gov/educ/eas/api/controller/v1/AssessmentStudentController.java +++ b/api/src/main/java/ca/bc/gov/educ/eas/api/controller/v1/AssessmentStudentController.java @@ -14,7 +14,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; @@ -56,12 +55,6 @@ public AssessmentStudent createStudent(AssessmentStudent assessmentStudent) { return mapper.toStructure(studentService.createStudent(mapper.toModel(assessmentStudent))); } - @Override - public ResponseEntity deleteStudent(UUID assessmentStudentID) { - this.studentService.deleteStudent(assessmentStudentID); - return ResponseEntity.noContent().build(); - } - @Override public CompletableFuture> findAll(Integer pageNumber, Integer pageSize, String sortCriteriaJson, String searchCriteriaListJson) { final List sorts = new ArrayList<>(); diff --git a/api/src/main/java/ca/bc/gov/educ/eas/api/endpoint/v1/AssessmentStudentEndpoint.java b/api/src/main/java/ca/bc/gov/educ/eas/api/endpoint/v1/AssessmentStudentEndpoint.java index 1e46a41..c356e44 100644 --- a/api/src/main/java/ca/bc/gov/educ/eas/api/endpoint/v1/AssessmentStudentEndpoint.java +++ b/api/src/main/java/ca/bc/gov/educ/eas/api/endpoint/v1/AssessmentStudentEndpoint.java @@ -5,7 +5,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import org.springframework.data.domain.Page; -import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -32,11 +31,6 @@ public interface AssessmentStudentEndpoint { @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "NOT FOUND"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")}) AssessmentStudent createStudent(@Validated @RequestBody AssessmentStudent assessmentStudent); - @DeleteMapping("/{assessmentStudentID}") - @PreAuthorize("hasAuthority('SCOPE_DELETE_EAS_STUDENT')") - @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "NO CONTENT"), @ApiResponse(responseCode = "404", description = "NOT FOUND"), @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR.")}) - ResponseEntity deleteStudent(@PathVariable UUID assessmentStudentID); - @GetMapping(URL.PAGINATED) @PreAuthorize("hasAuthority('SCOPE_READ_EAS_STUDENT')") @Transactional(readOnly = true) diff --git a/api/src/main/java/ca/bc/gov/educ/eas/api/service/v1/AssessmentStudentService.java b/api/src/main/java/ca/bc/gov/educ/eas/api/service/v1/AssessmentStudentService.java index 5305180..8488e4c 100644 --- a/api/src/main/java/ca/bc/gov/educ/eas/api/service/v1/AssessmentStudentService.java +++ b/api/src/main/java/ca/bc/gov/educ/eas/api/service/v1/AssessmentStudentService.java @@ -74,12 +74,4 @@ public AssessmentStudentEntity createStudent(AssessmentStudentEntity assessmentS throw new EntityExistsException("Assessment student with StudentID::"+assessmentStudentEntity.getStudentID()+" and Session ID::"+sessionEntity.getSessionID()+" already exists"); } } - - @Transactional(propagation = Propagation.REQUIRES_NEW) - public void deleteStudent(UUID assessmentStudentID) { - AssessmentStudentEntity currentAssessmentStudentEntity = this.assessmentStudentRepository.findById(assessmentStudentID).orElseThrow(() -> - new EntityNotFoundException(AssessmentStudentEntity.class, "AssessmentStudent", assessmentStudentID.toString()) - ); - this.assessmentStudentRepository.delete(currentAssessmentStudentEntity); - } } diff --git a/api/src/test/java/ca/bc/gov/educ/eas/api/controller/v1/AssessmentStudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/eas/api/controller/v1/AssessmentStudentControllerTest.java index 3d36442..ee43674 100644 --- a/api/src/test/java/ca/bc/gov/educ/eas/api/controller/v1/AssessmentStudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/eas/api/controller/v1/AssessmentStudentControllerTest.java @@ -32,7 +32,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.assertj.core.api.Assertions.assertThat; class AssessmentStudentControllerTest extends BaseEasAPITest { @@ -208,22 +207,6 @@ void testCreateStudent_GivenValidPayload_ShouldReturnStudent() throws Exception .andExpect(MockMvcResultMatchers.jsonPath("$.updateUser", equalTo("EAS_API"))); } - @Test - void testDeleteStudent_GivenIDExists_ShouldDeleteStudent() throws Exception { - final GrantedAuthority grantedAuthority = () -> "SCOPE_DELETE_EAS_STUDENT"; - final SecurityMockMvcRequestPostProcessors.OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); - - SessionEntity session = sessionRepository.save(createMockSessionEntity()); - AssessmentStudent student = AssessmentStudentMapper.mapper.toStructure(studentRepository.save(createMockStudentEntity(session))); - - this.mockMvc.perform( - delete(URL.BASE_URL_STUDENT + "/" + student.getAssessmentStudentID()).with(mockAuthority)) - .andDo(print()) - .andExpect(status().isNoContent()); - - assertThat(studentRepository.findById(UUID.fromString(student.getAssessmentStudentID()))).isEmpty(); - } - @Test void testFindAll_GivenAssessmentCodeAndSessionMonth_ShouldReturnStudent() throws Exception { final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_EAS_STUDENT"; diff --git a/api/src/test/java/ca/bc/gov/educ/eas/api/service/v1/AssessmentStudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/eas/api/service/v1/AssessmentStudentServiceTest.java index 6ad3894..c3d7d47 100644 --- a/api/src/test/java/ca/bc/gov/educ/eas/api/service/v1/AssessmentStudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/eas/api/service/v1/AssessmentStudentServiceTest.java @@ -159,28 +159,4 @@ void testUpdateStudent_WhenSessionIDDoesNotExistInDB_ShouldThrowError() { //then throw exception assertThrows(EntityNotFoundException.class, () -> service.updateStudent(student)); } - - @Test - void testDeleteStudent_WhenIDDoesNotExistInDB_ShouldThrowError() { - //when attempting to delete to session id that does not exist - UUID id = UUID.randomUUID(); - - //then throw exception - assertThrows(EntityNotFoundException.class, () -> service.deleteStudent(id)); - } - - @Test - void testDeleteStudent_WhenIDExistInDB_ShouldDeleteStudent() { - //given student existing in db - SessionEntity sessionEntity = sessionRepository.save(SessionEntity.builder().sessionID(UUID.randomUUID()).activeFromDate(LocalDateTime.now()).activeUntilDate(LocalDateTime.now()).statusCode(StatusCodes.OPEN.getCode()).updateDate(LocalDateTime.now()).updateUser("USER").build()); - - AssessmentStudentEntity student = repository.save(AssessmentStudentEntity.builder().assessmentTypeCode(AssessmentTypeCodes.LTF12.getCode()).pen("120164447").schoolID(UUID.randomUUID()).studentID(UUID.randomUUID()).sessionEntity(SessionEntity.builder().sessionID(sessionEntity.getSessionID()).build()).build()); - - //when attempting to delete assessment student - service.deleteStudent(student.getAssessmentStudentID()); - - //then student is deleted - var results = repository.findById(student.getAssessmentStudentID()); - assertThat(results).isEmpty(); - } } diff --git a/tools/config/update-configmap.sh b/tools/config/update-configmap.sh index 7fecc3e..ab0df99 100644 --- a/tools/config/update-configmap.sh +++ b/tools/config/update-configmap.sh @@ -42,7 +42,7 @@ echo Removing EAS API client if exists curl -sX DELETE "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/clients/$EAS_APIServiceClientID" \ -H "Authorization: Bearer $TKN" -echo Writing scope WRITE_EAS_STUDENTT +echo Writing scope WRITE_EAS_STUDENT curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scopes" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $TKN" \ @@ -54,12 +54,6 @@ curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scope -H "Authorization: Bearer $TKN" \ -d "{\"description\": \"Read Assessment Students\",\"id\": \"READ_EAS_STUDENT\",\"name\": \"READ_EAS_STUDENT\",\"protocol\": \"openid-connect\",\"attributes\" : {\"include.in.token.scope\" : \"true\",\"display.on.consent.screen\" : \"false\"}}" -echo Writing scope DELETE_EAS_STUDENT -curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scopes" \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $TKN" \ - -d "{\"description\": \"Delete Assessment Students\",\"id\": \"DELETE_EAS_STUDENT\",\"name\": \"DELETE_EAS_STUDENT\",\"protocol\": \"openid-connect\",\"attributes\" : {\"include.in.token.scope\" : \"true\",\"display.on.consent.screen\" : \"false\"}}" - if [[ -n "$EAS_APIServiceClientID" && -n "$EAS_APIServiceClientSecret" && ("$envValue" = "dev" || "$envValue" = "test") ]]; then echo echo Creating client eas-api-service with secret