Skip to content

Commit

Permalink
Merge branch 'refs/heads/grad-release' into GRAD2-2768
Browse files Browse the repository at this point in the history
  • Loading branch information
chris.ditcher authored and chris.ditcher committed Aug 29, 2024
2 parents f3d3ab5 + 7caa579 commit 2b185fe
Show file tree
Hide file tree
Showing 30 changed files with 913 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ca.bc.gov.educ.api.trax.model.dto.GradProvince;
import ca.bc.gov.educ.api.trax.service.CodeService;
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants;
import ca.bc.gov.educ.api.trax.util.GradValidation;
import ca.bc.gov.educ.api.trax.util.PermissionsConstants;
import ca.bc.gov.educ.api.trax.util.ResponseHelper;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ca.bc.gov.educ.api.trax.model.dto.District;
import ca.bc.gov.educ.api.trax.service.DistrictService;
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants;
import ca.bc.gov.educ.api.trax.util.GradValidation;
import ca.bc.gov.educ.api.trax.util.PermissionsConstants;
import ca.bc.gov.educ.api.trax.util.ResponseHelper;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
Expand Down Expand Up @@ -48,7 +47,7 @@ public ResponseEntity<District> getDistrictDetails(@PathVariable String distCode

@GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_DISTRICTS_BY_SCHOOL_CATEGORY_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Check school existence by Mincode", description = "Check school existence by Mincode", tags = { "School" })
@Operation(summary = "Get Districts by SchoolCategory", description = "Get Districts by SchoolCategory", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<List<District>> getDistrictBySchoolCategory(@RequestParam(required = false) String schoolCategory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ResponseEntity<List<CommonSchool>> getAllCommonSchool() {

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_COMMON_SCHOOL_BY_CODE_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Find a Common School by Mincode", description = "Get a Common School by Mincode", tags = { "School" })
@Operation(summary = "Find a Common School by Mincode", description = "Find a Common School by Mincode", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "NOT FOUND")})
public ResponseEntity<CommonSchool> getCommonSchool(@PathVariable String minCode) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public ResponseEntity<Boolean> checkSchoolExists(@PathVariable String minCode) {

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V1 + EducGradTraxApiConstants.GET_SCHOOLS_BY_SCHOOL_CATEGORY_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Check school existence by Mincode", description = "Check school existence by Mincode", tags = { "School" })
@Operation(summary = "Get schools by SchoolCategory", description = "Get schools by SchoolCategory", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<List<School>> getSchoolsBySchoolCategory(@RequestParam(required = false) String schoolCategory, @RequestHeader(name="Authorization") String accessToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package ca.bc.gov.educ.api.trax.controller.v2;

import ca.bc.gov.educ.api.trax.model.dto.institute.District;
import ca.bc.gov.educ.api.trax.service.institute.DistrictService;
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants;
import ca.bc.gov.educ.api.trax.util.GradValidation;
import ca.bc.gov.educ.api.trax.util.PermissionsConstants;
import ca.bc.gov.educ.api.trax.util.ResponseHelper;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController("districtControllerV2")
@Slf4j
@OpenAPIDefinition(info = @Info(title = "API for School Data.", description = "This Read API is for Reading school data.", version = "2"),
security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_SCHOOL_DATA"})})
public class DistrictController {

DistrictService districtService;
GradValidation validation;
ResponseHelper response;

@Autowired
public DistrictController(DistrictService districtService, GradValidation validation, ResponseHelper response) {
this.districtService = districtService;
this.validation = validation;
this.response = response;
}

@GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_DISTRICT_BY_DISTNO_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Find a District by District Number V2", description = "Get District by District Number V2", tags = { "District" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<District> getDistrictDetailsByDistNo(@PathVariable String distNo) {
if(distNo.length() <=3) {
District distResponse = districtService.getDistrictByDistNoFromRedisCache(distNo);
if (distResponse != null) {
return response.GET(distResponse);
}
}
return null;
}

@GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_DISTRICTS_BY_SCHOOL_CATEGORY_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Get District by school category code V2", description = "Get District by school category code V2", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<List<District>> getDistrictsBySchoolCategoryCode(@RequestParam(required = false) String schoolCategoryCode) {
return response.GET(districtService.getDistrictsBySchoolCategoryCode(schoolCategoryCode));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController("SchoolControllerV2")
@RestController("schoolControllerV2")
@Slf4j
@OpenAPIDefinition(info = @Info(title = "API for School Data.", description = "This Read API is for Reading school data from Redis Cache.", version = "2"),
security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_SCHOOL_DATA"})})
Expand All @@ -47,6 +48,21 @@ public List<School> getAllSchools() {
return schoolService.getSchoolsFromRedisCache();
}

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_BY_CODE_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Find a School by Mincode from cache", description = "Get a School by Mincode from cache", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<School> getSchoolByMincode(@PathVariable String minCode) {
log.debug("getSchoolByMincode : ");
School schoolResponse = schoolService.getSchoolByMincodeFromRedisCache(minCode);
if(schoolResponse != null) {
return response.GET(schoolResponse);
}else {
return response.NOT_FOUND();
}
}

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_DETAIL_URL_MAPPING_V2)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Find All School details from Cache", description = "Get All School details from Cache", tags = { "School" })
Expand All @@ -56,5 +72,38 @@ public List<SchoolDetail> getAllSchoolDetails() {
return schoolService.getSchoolDetailsFromRedisCache();
}

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V2 + EducGradTraxApiConstants.CHECK_SCHOOL_BY_CODE_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Check school existence by Mincode V2", description = "Check school existence by Mincode V2", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public Boolean checkIfSchoolExists(@PathVariable String minCode) {
return schoolService.checkIfSchoolExists(minCode);
}

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOLS_BY_SCHOOL_CATEGORY_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Get Schools by School Category Code V2", description = "Get Schools by School Category Code V2", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<List<SchoolDetail>> getSchoolsBySchoolCategory(@RequestParam(required = false) String schoolCategoryCode) {
return response.GET(schoolService.getSchoolDetailsBySchoolCategoryCode(schoolCategoryCode));
}

@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_DETAIL_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_BY_CODE_MAPPING)
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA)
@Operation(summary = "Find School Details by Mincode from cache", description = "Get School Details by Mincode from cache", tags = { "School" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "NO CONTENT")})
public ResponseEntity<SchoolDetail> getSchoolDetailsByMincode(@PathVariable String minCode) {
log.debug("getSchoolDetails : ");
SchoolDetail schoolDetailResponse = schoolService.getSchoolDetailByMincodeFromRedisCache(minCode);
if(schoolDetailResponse != null) {
return response.GET(schoolDetailResponse);
}else {
return response.NOT_FOUND();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Component("InstituteDistrict")
@Component("instituteDistrict")
@NoArgsConstructor
@AllArgsConstructor
public class District extends BaseModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Component("DistrictAddress")
@Component("districtAddress")
public class DistrictAddress extends BaseModel {

private String districtAddressId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Component("DistrictContact")
@Component("districtContact")
public class DistrictContact extends BaseModel {

private String districtId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Component("Grade")
@Component("grade")
public class Grade extends BaseModel {

private String schoolGradeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Component("NeighborhoodLearning")
@Component("neighborhoodLearning")
public class NeighborhoodLearning extends BaseModel {

private String neighborhoodLearningId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Component("Note")
@Component("note")
public class Note extends BaseModel {

private String noteId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Component("InstituteSchool")
@Component("instituteSchool")
@JsonIgnoreProperties(ignoreUnknown = true)
public class School extends BaseModel {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
@Component("SchoolAddress")
@Component("schoolAddress")
public class SchoolAddress extends BaseModel {

private String SchoolAddressId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ca.bc.gov.educ.api.trax.model.dto.institute.District;
import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictEntity;
import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolDetailEntity;
import org.modelmapper.ModelMapper;
import org.modelmapper.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
@Repository
public interface DistrictRedisRepository extends CrudRepository<DistrictEntity, String> {
String HASH_KEY = "District";

DistrictEntity findByDistrictNumber(String districtNumber);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package ca.bc.gov.educ.api.trax.repository.redis;

import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolDetailEntity;
import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolEntity;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SchoolDetailRedisRepository extends CrudRepository<SchoolDetailEntity, String> {
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 @@ -7,4 +7,6 @@
@Repository
public interface SchoolRedisRepository extends CrudRepository<SchoolEntity, String> {
String HASH_KEY = "School";

SchoolEntity findByMincode(String mincode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ca.bc.gov.educ.api.trax.constant.CacheKey;
import ca.bc.gov.educ.api.trax.exception.ServiceException;
import ca.bc.gov.educ.api.trax.model.dto.institute.District;
import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolDetail;
import ca.bc.gov.educ.api.trax.model.entity.institute.DistrictEntity;
import ca.bc.gov.educ.api.trax.model.transformer.institute.DistrictTransformer;
import ca.bc.gov.educ.api.trax.repository.redis.DistrictRedisRepository;
Expand All @@ -15,6 +16,7 @@
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;

import java.util.ArrayList;
import java.util.List;

@Slf4j
Expand All @@ -33,6 +35,8 @@ public class DistrictService {
@Autowired
ServiceHelper<DistrictService> serviceHelper;
@Autowired
SchoolService schoolService;
@Autowired
RESTService restService;

public List<District> getDistrictsFromInstituteApi() {
Expand Down Expand Up @@ -64,6 +68,31 @@ public void initializeDistrictCache(boolean force) {
serviceHelper.initializeCache(force, CacheKey.DISTRICT_CACHE, this);
}

public District getDistrictByDistNoFromRedisCache(String districtNumber) {
log.debug("**** Getting district by district no. from Redis Cache.");
return districtTransformer.transformToDTO(districtRedisRepository.findByDistrictNumber(districtNumber));
}

public District getDistrictByIdFromRedisCache(String districtId) {
log.debug("**** Getting district by ID from Redis Cache.");
return districtTransformer.transformToDTO(districtRedisRepository.findById(districtId));
}

public List<District> getDistrictsBySchoolCategoryCode(String schoolCategoryCode) {
List<SchoolDetail> schoolDetails;

if (schoolCategoryCode.isBlank() || schoolCategoryCode.isEmpty())
schoolDetails = schoolService.getSchoolDetailsFromRedisCache();
else
schoolDetails = schoolService.getSchoolDetailsBySchoolCategoryCode(schoolCategoryCode);

List<District> districts = new ArrayList<>();
for (SchoolDetail schoolDetail : schoolDetails) {
districts.add(getDistrictByIdFromRedisCache(schoolDetail.getDistrictId()));
}
return districts;
}

/**
* Updates the district details in the cache
* based on schoolId
Expand Down
Loading

0 comments on commit 2b185fe

Please sign in to comment.