Created an api to get look up data by type

This commit is contained in:
harish
2024-08-28 12:33:45 +05:30
parent ffa07d779b
commit 1f87699356
6 changed files with 83 additions and 11 deletions

View File

@@ -4,48 +4,78 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum;
import net.gepafin.tendermanagement.model.request.LookUpDataRequest;
import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
public interface LookUpDataApi {
@Operation(summary = "API to create LookUp Data",
responses = {
@ApiResponse(responseCode = "201", description = "Created"),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Bad Request\" }"))),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Not Found\" }")))
})
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
@PostMapping(value = "", consumes = "application/json", produces = "application/json")
ResponseEntity<Response<LookUpDataResponseBean>> createLookUpData(HttpServletRequest request, @Valid @RequestBody LookUpDataRequest lookUpDataReq);
@Operation(summary = "API to get LookUp Data by id",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Not Found\" }")))
})
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
@GetMapping(value = "/{id}", produces = "application/json")
ResponseEntity<Response<LookUpDataResponseBean>> getLookUpDataById(HttpServletRequest request, @PathVariable Long id);
@Operation(summary = "API to update LookUp Data",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Bad Request\" }"))),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Not Found\" }")))
})
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
@PutMapping(value = "/{id}", consumes = "application/json", produces = "application/json")
ResponseEntity<Response<LookUpDataResponseBean>> updateLookUpData(HttpServletRequest request, @PathVariable Long id, @Valid @RequestBody LookUpDataRequest lookUpDataReq);
@Operation(summary = "API to delete LookUp Data",
responses = {
@ApiResponse(responseCode = "204", description = "No Content"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = "application/json", examples = @ExampleObject(value = "{ \"error\": \"Not Found\" }")))
})
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
@DeleteMapping(value = "/{id}")
ResponseEntity<Response<Void>> deleteLookUpData(HttpServletRequest request, @PathVariable Long id);
@Operation(summary = "API to get LookUp Data by type",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
@GetMapping(value = "/type", produces = "application/json")
ResponseEntity<Response<List<LookUpDataResponseBean>>> getLookUpDataByType(HttpServletRequest request, @RequestParam LookUpDataTypeEnum type);
}

View File

@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.LookUpDataEntity.LookUpDataTypeEnum;
import net.gepafin.tendermanagement.model.request.LookUpDataRequest;
import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
@@ -15,6 +16,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("${openapi.gepafin.base-path:/v1/lookupdata}")
public class LookUpDataApiController implements LookUpDataApi {
@@ -59,4 +62,15 @@ public class LookUpDataApiController implements LookUpDataApi {
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.LOOKUP_DATA_DELETED_SUCCESSFULLY)));
}
@Override
public ResponseEntity<Response<List<LookUpDataResponseBean>>> getLookUpDataByType(HttpServletRequest request, LookUpDataTypeEnum type) {
List<LookUpDataResponseBean> responseBean = lookUpDataService.getLookUpDataByType(type);
if (responseBean != null) {
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<List<LookUpDataResponseBean>>(responseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.LOOKUP_DATA_FETCHED_SUCCESSFULLY)));
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(new Response<List<LookUpDataResponseBean>>(responseBean, Status.NOT_FOUND, Translator.toLocale(GepafinConstant.LOOKUP_DATA_NOT_FOUND)));
}
}
}