Skip to content

Commit

Permalink
GRAD2-2638 - Institute - Create V2 endpoints for School data
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal-mohammed committed Aug 7, 2024
1 parent 2b021e2 commit 81b0315
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public List<SchoolDetail> getAllSchoolDetails() {
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<SchoolDetail> getSchoolDetailsByMincode(@PathVariable String minCode) {
log.debug("getSchoolDetails : ");
SchoolDetail schoolDetailResponse = schoolService.getSchoolDetailByIdFromInstituteApi(minCode);
SchoolDetail schoolDetailResponse = schoolService.getSchoolDetailByMincodeFromRedisCache(minCode);
if(schoolDetailResponse != null) {
return response.GET(schoolDetailResponse);
}else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface SchoolDetailRedisRepository extends CrudRepository<SchoolDetail
String HASH_KEY = "SchoolDetail";

List<SchoolDetailEntity> findBySchoolCategoryCode(String schoolCategoryCode);

SchoolDetailEntity findByMincode(String mincode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public List<SchoolDetail> getSchoolDetailsFromRedisCache() {
return schoolDetailTransformer.transformToDTO(schoolDetailRedisRepository.findAll());
}

public SchoolDetail getSchoolDetailByMincodeFromRedisCache(String mincode) {
log.debug("**** Getting school Details By Mincode from Redis Cache.");
return schoolDetailTransformer.transformToDTO(schoolDetailRedisRepository.findByMincode(mincode));
}

public void initializeSchoolDetailCache(boolean force) {
serviceHelper.initializeCache(force, CacheKey.SCHOOL_DETAIL_CACHE, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ public void whenGetAllSchools_ReturnsListOfSchools() {
Mockito.verify(schoolServiceV2).getSchoolsFromRedisCache();
}

@Test
public void whenGetSchoolByMincode_ReturnsSchool() {
String mincode = "12345678";
ca.bc.gov.educ.api.trax.model.dto.institute.School school = new ca.bc.gov.educ.api.trax.model.dto.institute.School();
school.setSchoolId("1234567");
school.setDistrictId("9876543");
school.setMincode(mincode);

Mockito.when(schoolServiceV2.getSchoolByMincodeFromRedisCache(mincode)).thenReturn(school);
schoolControllerV2.getSchoolByMincode(mincode);
Mockito.verify(schoolServiceV2).getSchoolByMincodeFromRedisCache(mincode);
}

@Test
public void whenGetAllSchoolDetails_ReturnsListOfSchoolDetails() {
final List<SchoolDetail> schoolDetails = new ArrayList<>();
Expand All @@ -185,4 +198,17 @@ public void whenGetAllSchoolDetails_ReturnsListOfSchoolDetails() {
schoolControllerV2.getAllSchoolDetails();
Mockito.verify(schoolServiceV2).getSchoolDetailsFromRedisCache();
}

@Test
public void whenGetSchoolDetailsByMincode_ReturnsSchoolDetail() {
String mincode = "12345678";
SchoolDetail schoolDetail = new SchoolDetail();
schoolDetail.setSchoolId("1234567");
schoolDetail.setDistrictId("9876543");
schoolDetail.setMincode(mincode);

Mockito.when(schoolServiceV2.getSchoolDetailByMincodeFromRedisCache(mincode)).thenReturn(schoolDetail);
schoolControllerV2.getSchoolDetailsByMincode(mincode);
Mockito.verify(schoolServiceV2).getSchoolDetailByMincodeFromRedisCache(mincode);
}
}

0 comments on commit 81b0315

Please sign in to comment.