Skip to content

Commit

Permalink
Merge pull request #314 from bcgov/GRAD2-2465-km
Browse files Browse the repository at this point in the history
GRAD2-2465 - Delete a student and related data
  • Loading branch information
kamal-mohammed authored Mar 18, 2024
2 parents 5474a2e + e415675 commit 6c218fa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
@RequestMapping(EducGradTraxApiConstants.GRAD_TRAX_COMMON_URL_MAPPING)
@OpenAPIDefinition(info = @Info(title = "API for TRAX Data.", description = "This API is for TRAX.", version = "1"))
public class TraxCommonController {
private static Logger logger = LoggerFactory.getLogger(TraxCommonController.class);
private static final String BEARER = "Bearer ";
private static final Logger logger = LoggerFactory.getLogger(TraxCommonController.class);

@Autowired
TraxCommonService traxCommonService;
Expand Down Expand Up @@ -105,11 +104,19 @@ public ResponseEntity<List<GradCourse>> getCourseRequirements() {
return response.GET(traxCommonService.loadGradCourseRequirementsDataFromTrax());
}

@PostMapping(EducGradTraxApiConstants.POST_SAVE_TRAX_STUDENT_NO_MAPPING)
@PostMapping(EducGradTraxApiConstants.SAVE_TRAX_STUDENT_NO_MAPPING)
@PreAuthorize(PermissionsConstants.UPDATE_GRAD_TRAX_STUDENT_DATA)
@Operation(summary = "Save TraxStudentNo", description = "Save TraxStudentNo", tags = {"Student"})
public ResponseEntity<TraxStudentNo> saveTraxStudentNo(@RequestBody TraxStudentNo traxStudentNo) {
logger.debug("saveTraxStudentNo : ");
return response.GET(traxCommonService.saveTraxStudentNo(traxStudentNo));
}

@PutMapping(EducGradTraxApiConstants.SAVE_TRAX_STUDENT_NO_MAPPING)
@PreAuthorize(PermissionsConstants.UPDATE_GRAD_TRAX_STUDENT_DATA)
@Operation(summary = "Update TraxStudentNo status", description = "Update TraxStudentNo status", tags = {"Student"})
public ResponseEntity<TraxStudentNo> updateTraxStudentNo(@RequestBody TraxStudentNo traxStudentNo) {
logger.debug("updateTraxStudentNo : ");
return response.GET(traxCommonService.updateTraxStudentNo(traxStudentNo));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ public TraxStudentNo saveTraxStudentNo(TraxStudentNo traxStudentNo) {
return traxStudentNo;
}

@Transactional
public TraxStudentNo updateTraxStudentNo(TraxStudentNo traxStudentNo) {
Optional<TraxStudentNoEntity> optional = traxStudentNoRepository.findById(traxStudentNo.getStudNo());
if (optional.isPresent()) {
TraxStudentNoEntity entity = optional.get();
entity.setStatus(traxStudentNo.getStatus());
entity.setReason(traxStudentNo.getReason());
return traxStudentNoTransformer.transformToDTO(traxStudentNoRepository.save(entity));
}
return null;
}

private List<ConvGradStudent> buildConversionGradStudents(List<Object[]> traxStudents) {
List<ConvGradStudent> students = new ArrayList<>();
traxStudents.forEach(result -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class EducGradTraxApiConstants {
public static final String GET_TOTAL_NUMBER_OF_TRAX_STUDENT_NO_LIST_MAPPING = "/student-no-list/total-count";
public static final String GET_COURSE_RESTRICTION_LIST_MAPPING = "/course-restrictions";
public static final String GET_COURSE_REQUIREMENT_LIST_MAPPING = "/course-requirements";
public static final String POST_SAVE_TRAX_STUDENT_NO_MAPPING = "/trax-student-no";
public static final String SAVE_TRAX_STUDENT_NO_MAPPING = "/trax-student-no";

//Default Attribute value constants
public static final String DEFAULT_CREATED_BY = "API_GRAD_TRAX";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public class TraxCommonControllerTest {

@Mock
ResponseHelper response;

@InjectMocks
private TraxCommonController traxCommonController;

@Mock
GradValidation validation;

@Mock
MessageHelper messagesHelper;

Expand Down Expand Up @@ -145,6 +145,17 @@ public void testSaveTraxStudentNo() {
Mockito.verify(traxCommonService).saveTraxStudentNo(obj);
}

@Test
public void testUpdateTraxStudentNo() {
final String pen = "123456789";
TraxStudentNo obj = new TraxStudentNo();
obj.setStudNo(pen);

Mockito.when(traxCommonService.updateTraxStudentNo(obj)).thenReturn(obj);
traxCommonController.updateTraxStudentNo(obj);
Mockito.verify(traxCommonService).updateTraxStudentNo(obj);
}

// @Test
// public void testGetStudentIsGraduatedByPen() {
// Mockito.when(traxCommonService.isGraduatedStudent("123456789")).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,23 @@ public void testSaveTraxStudentNo() {
assertThat(traxStudentNo.getStatus()).isEqualTo(result.getStatus());
}

@Test
public void updateSaveTraxStudentNo() {
TraxStudentNo traxStudentNo = new TraxStudentNo();
traxStudentNo.setStudNo("123456789");
traxStudentNo.setStatus(null);

TraxStudentNoEntity traxStudentNoEntity = traxStudentNoTransformer.transformToEntity(traxStudentNo);

when(traxStudentNoRepository.findById(traxStudentNo.getStudNo())).thenReturn(Optional.of(traxStudentNoEntity));
when(traxStudentNoRepository.save(traxStudentNoEntity)).thenReturn(traxStudentNoEntity);

var result = traxCommonService.updateTraxStudentNo(traxStudentNo);
assertThat(result).isNotNull();
assertThat(traxStudentNo.getStudNo()).isEqualTo(result.getStudNo());
assertThat(traxStudentNo.getStatus()).isNull();
}

// @Test
// public void testStudentIsNotGraduated() {
// // Student is graduated or not
Expand Down

0 comments on commit 6c218fa

Please sign in to comment.