Skip to content

Commit

Permalink
EAC-9 - removes delete endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mightycox committed Oct 8, 2024
1 parent 211c687 commit 195cbe1
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,12 +55,6 @@ public AssessmentStudent createStudent(AssessmentStudent assessmentStudent) {
return mapper.toStructure(studentService.createStudent(mapper.toModel(assessmentStudent)));
}

@Override
public ResponseEntity<Void> deleteStudent(UUID assessmentStudentID) {
this.studentService.deleteStudent(assessmentStudentID);
return ResponseEntity.noContent().build();
}

@Override
public CompletableFuture<Page<AssessmentStudent>> findAll(Integer pageNumber, Integer pageSize, String sortCriteriaJson, String searchCriteriaListJson) {
final List<Sort.Order> sorts = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Void> deleteStudent(@PathVariable UUID assessmentStudentID);

@GetMapping(URL.PAGINATED)
@PreAuthorize("hasAuthority('SCOPE_READ_EAS_STUDENT')")
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 1 addition & 7 deletions tools/config/update-configmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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
Expand Down

0 comments on commit 195cbe1

Please sign in to comment.