From 5e36999ca3d16901c7c8a6b62b68dc52d467a33d Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Tue, 19 Nov 2024 02:37:39 +0530 Subject: [PATCH] Update DistrictController.java --- .../controller/v2/DistrictController.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/DistrictController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/DistrictController.java index 0116fa40..2b1f5003 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/DistrictController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/DistrictController.java @@ -14,6 +14,7 @@ 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.*; @@ -53,18 +54,30 @@ public ResponseEntity reloadDistrictsIntoCache() { return ResponseEntity.ok("Districts loaded into cache!"); } - @GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_DISTRICT_BY_DISTNO_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V2) @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 getDistrictDetailsByDistNo(@PathVariable String distNo) { + public ResponseEntity getDistrictDetailsByDistNo(@RequestParam(required = true) String distNo) { if(distNo.length() <=3) { District distResponse = districtService.getDistrictByDistNoFromRedisCache(distNo); if (distResponse != null) { return response.GET(distResponse); } } - return null; + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + @GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_DISTRICT_BY_ID_MAPPING) + @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) + @Operation(summary = "Find a District by ID V2", description = "Get District by ID V2", tags = { "District" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity getDistrictDetailsById(@PathVariable String districtId) { + District distResponse = districtService.getDistrictByIdFromRedisCache(districtId); + if (distResponse != null) { + return response.GET(distResponse); + } + return new ResponseEntity<>(HttpStatus.NOT_FOUND); } @GetMapping(EducGradTraxApiConstants.GRAD_DISTRICT_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_DISTRICTS_BY_SCHOOL_CATEGORY_MAPPING)