-
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 #357 from bcgov/feature/GRAD2-2949
GRAD2-2949: initial commit for the new endpoints to get school clob data from institute RedisCache.
- Loading branch information
Showing
20 changed files
with
611 additions
and
135 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
82 changes: 82 additions & 0 deletions
82
api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/CommonController.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,82 @@ | ||
package ca.bc.gov.educ.api.trax.controller.v2; | ||
|
||
import ca.bc.gov.educ.api.trax.model.dto.School; | ||
import ca.bc.gov.educ.api.trax.service.institute.CommonService; | ||
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.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@CrossOrigin | ||
@RestController | ||
@Slf4j | ||
@OpenAPIDefinition(info = @Info(title = "API for School Clob for Graduation Algorithm Data.", description = "This Common API is for retrieving School Clob for Graduation Algorithm Data from Redis Cache.", version = "2"), | ||
security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_SCHOOL_DATA"})}) | ||
public class CommonController { | ||
CommonService commonService; | ||
GradValidation validation; | ||
ResponseHelper response; | ||
|
||
@Autowired | ||
public CommonController(CommonService commonService, GradValidation validation, ResponseHelper response) { | ||
this.commonService = commonService; | ||
this.validation = validation; | ||
this.response = response; | ||
} | ||
|
||
@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_CLOB_URL_MAPPING_V2) | ||
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) | ||
@Operation(summary = "Find All Schools Clob data for GRAD Algorithm Data from cache", description = "Get All Schools Clob data for GRAD Algorithm Data from cache", tags = { "Algorithm Data" }) | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) | ||
public ResponseEntity<List<School>> getAllSchoolsForClobData() { | ||
log.debug("getAllSchoolsClob : "); | ||
return response.GET(commonService.getSchoolsForClobDataFromRedisCache()); | ||
} | ||
|
||
@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_CLOB_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_BY_CODE_MAPPING) | ||
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) | ||
@Operation(summary = "Find a School Clob data by MinCode for GRAD Algorithm Data from cache", description = "Get a School Clob data by MinCode for GRAD Algorithm Data from cache", tags = { "Algorithm Data" }) | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), | ||
@ApiResponse(responseCode = "400", description = "BAD REQUEST"), | ||
@ApiResponse(responseCode = "422", description = "UNPROCESSABLE CONTENT"), | ||
@ApiResponse(responseCode = "204", description = "NO CONTENT")}) | ||
public ResponseEntity<School> getSchoolForClobDataByMinCode(@PathVariable String minCode) { | ||
log.debug("getSchoolClobData by minCode: {}", minCode); | ||
validation.requiredField(minCode, "minCode"); | ||
if (validation.hasErrors()) { | ||
validation.stopOnErrors(); | ||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
School schoolResponse = commonService.getSchoolForClobDataByMinCodeFromRedisCache(minCode); | ||
if (schoolResponse != null) { | ||
return response.GET(schoolResponse); | ||
} else { | ||
return response.NOT_FOUND(); | ||
} | ||
} | ||
|
||
@GetMapping(EducGradTraxApiConstants.GRAD_SCHOOLS_BY_DISTRICT_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_DISTRICT_BY_DISTNO_MAPPING) | ||
@PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) | ||
@Operation(summary = "Find Schools Clob data by District Number for GRAD Algorithm Data from cache", description = "Get Schools Clob data by District Number for GRAD Algorithm Data from cache", tags = { "Algorithm Data" }) | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) | ||
public ResponseEntity<List<School>> getSchoolsForClobDataByDistrictNumber(@PathVariable String distNo) { | ||
log.debug("getSchoolsClob by districtNumber: {}", distNo); | ||
return response.GET(commonService.getSchoolsByDistrictNumberFromRedisCache(distNo)); | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.