-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from bcgov/feature/eas-13
Creates endpoint for fetching student merges
- Loading branch information
Showing
9 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
api/src/main/java/ca/bc/gov/educ/eas/api/controller/v1/StudentMergeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ca.bc.gov.educ.eas.api.controller.v1; | ||
|
||
import ca.bc.gov.educ.eas.api.endpoint.v1.StudentMergeEndpoint; | ||
import ca.bc.gov.educ.eas.api.service.v1.StudentMergeService; | ||
import ca.bc.gov.educ.eas.api.struct.v1.StudentMerge; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@RestController | ||
public class StudentMergeController implements StudentMergeEndpoint { | ||
private final StudentMergeService studentMergeService; | ||
|
||
public StudentMergeController(StudentMergeService studentMergeService){ | ||
this.studentMergeService = studentMergeService; | ||
} | ||
|
||
@Override | ||
public List<StudentMerge> getMergedStudentsForDateRange(String createDateStart, String createDateEnd){ | ||
return studentMergeService.getMergedStudentsForDateRange(createDateStart, createDateEnd); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
api/src/main/java/ca/bc/gov/educ/eas/api/endpoint/v1/StudentMergeEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ca.bc.gov.educ.eas.api.endpoint.v1; | ||
|
||
import ca.bc.gov.educ.eas.api.constants.v1.URL; | ||
import ca.bc.gov.educ.eas.api.struct.v1.StudentMerge; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import java.util.List; | ||
|
||
@RequestMapping(URL.BASE_URL + "/student-merges") | ||
public interface StudentMergeEndpoint { | ||
|
||
@GetMapping() | ||
@PreAuthorize("hasAuthority('SCOPE_READ_EAS_STUDENT')") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) | ||
@Tag(name = "PEN Records", description = "Endpoints to retrieve PEN records.") | ||
List<StudentMerge> getMergedStudentsForDateRange(@RequestParam(name = "createDateStart") String createDateStart, @RequestParam(name = "createDateEnd") String createDateEnd) throws JsonProcessingException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
api/src/main/java/ca/bc/gov/educ/eas/api/service/v1/StudentMergeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ca.bc.gov.educ.eas.api.service.v1; | ||
|
||
import ca.bc.gov.educ.eas.api.rest.RestUtils; | ||
import ca.bc.gov.educ.eas.api.struct.v1.StudentMerge; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@Slf4j | ||
public class StudentMergeService { | ||
|
||
private final RestUtils restUtils; | ||
|
||
@Autowired | ||
public StudentMergeService(RestUtils restUtils){ | ||
this.restUtils = restUtils; | ||
} | ||
|
||
public List<StudentMerge> getMergedStudentsForDateRange(String createDateStart, String createDateEnd){ | ||
UUID correlationID = UUID.randomUUID(); | ||
log.info("Fetching student merge records created between {} and {} with correlation ID: {}", createDateStart, createDateEnd, correlationID); | ||
return restUtils.getMergedStudentsForDateRange(correlationID, createDateStart, createDateEnd); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
api/src/main/java/ca/bc/gov/educ/eas/api/struct/v1/StudentMerge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ca.bc.gov.educ.eas.api.struct.v1; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* The type Student merge. | ||
*/ | ||
@EqualsAndHashCode(callSuper = true) | ||
@Data | ||
@SuperBuilder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class StudentMerge extends BaseRequest implements Serializable { | ||
/** | ||
* The constant serialVersionUID. | ||
*/ | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* The Student merge id. | ||
*/ | ||
@NotNull(message = "Student Merge ID cannot be null") | ||
String studentMergeID; | ||
/** | ||
* The Student id. | ||
*/ | ||
@NotNull(message = "Student ID cannot be null.") | ||
String studentID; | ||
/** | ||
* The Merge student id. | ||
*/ | ||
@NotNull(message = "Merge Student ID cannot be null.") | ||
String mergeStudentID; | ||
/** | ||
* The Student merge direction code. | ||
*/ | ||
@NotNull(message = "Student Merge Direction Code cannot be null.") | ||
String studentMergeDirectionCode; | ||
/** | ||
* The Student merge source code. | ||
*/ | ||
@NotNull(message = "Student Merge Source Code cannot be null.") | ||
String studentMergeSourceCode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
api/src/test/java/ca/bc/gov/educ/eas/api/service/v1/StudentMergeServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ca.bc.gov.educ.eas.api.service.v1; | ||
|
||
import ca.bc.gov.educ.eas.api.exception.EasAPIRuntimeException; | ||
import ca.bc.gov.educ.eas.api.rest.RestUtils; | ||
import ca.bc.gov.educ.eas.api.struct.v1.StudentMerge; | ||
import lombok.val; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.*; | ||
|
||
class StudentMergeServiceTest { | ||
|
||
@Mock | ||
private RestUtils restUtils; | ||
|
||
@InjectMocks | ||
private StudentMergeService studentMergeService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void testGetMergedStudentsForDateRange_ShouldReturnMergedStudents() { | ||
String createDateStart = "2024-02-01T00:00:00"; | ||
String createDateEnd = "2024-09-01T00:00:00"; | ||
List<StudentMerge> mockMergedStudents = List.of( | ||
StudentMerge.builder().studentMergeID(UUID.randomUUID().toString()).studentID(UUID.randomUUID().toString()).mergeStudentID(UUID.randomUUID().toString()).studentMergeDirectionCode("FROM").studentMergeSourceCode("MI").build(), | ||
StudentMerge.builder().studentMergeID(UUID.randomUUID().toString()).studentID(UUID.randomUUID().toString()).mergeStudentID(UUID.randomUUID().toString()).studentMergeDirectionCode("TO").studentMergeSourceCode("API").build() | ||
); | ||
when(restUtils.getMergedStudentsForDateRange(any(UUID.class), eq(createDateStart), eq(createDateEnd))) | ||
.thenReturn(mockMergedStudents); | ||
|
||
val result = studentMergeService.getMergedStudentsForDateRange(createDateStart, createDateEnd); | ||
|
||
assertEquals(mockMergedStudents, result); | ||
verify(restUtils, times(1)).getMergedStudentsForDateRange(any(UUID.class), eq(createDateStart), eq(createDateEnd)); // Use any(UUID.class) here | ||
} | ||
|
||
@Test | ||
void testGetMergedStudentsForDateRange_WhenRestUtilsThrowsException_ShouldThrowEasAPIRuntimeException() { | ||
String createDateStart = "2024-02-01T00:00:00"; | ||
String createDateEnd = "2024-09-01T00:00:00"; | ||
|
||
when(restUtils.getMergedStudentsForDateRange(any(UUID.class), eq(createDateStart), eq(createDateEnd))) | ||
.thenThrow(new EasAPIRuntimeException("PEN Services API failed")); | ||
|
||
assertThrows(EasAPIRuntimeException.class, () -> studentMergeService.getMergedStudentsForDateRange(createDateStart, createDateEnd)); | ||
verify(restUtils, times(1)).getMergedStudentsForDateRange(any(UUID.class), eq(createDateStart), eq(createDateEnd)); // Use any(UUID.class) here | ||
} | ||
} |