Done ticket GEPAFINBE-6143
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package net.gepafin.tendermanagement.web.rest.api;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
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 jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentSpecialRequest;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationContractRequest;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationEvaluationRequest;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationContractResponse;
|
||||
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.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Validated
|
||||
public interface ApplicationContractApi {
|
||||
|
||||
@Operation(summary = "Api to create application contract",
|
||||
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) })) })
|
||||
@PostMapping(value = "/application/{applicationId}", produces = "application/json", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_INSTRUCTOR_MANAGER')|| hasRole('ROLE_PRE_INSTRUCTOR')")
|
||||
ResponseEntity<Response<ApplicationContractResponse>> createApplicationContract(HttpServletRequest request,
|
||||
@Parameter(description = "Application ID", required = true) @PathVariable("applicationId") Long applicationId, @Parameter(description = "List of files to upload", required = true)
|
||||
@RequestPart(required = true) List<MultipartFile> contractDocuments,
|
||||
@Parameter(description = "Application Contract Request Body", required = true) @RequestPart ApplicationContractRequest applicationContractRequest);
|
||||
|
||||
@Operation(summary = "Api to update application contract from beneficiary side",
|
||||
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) })) })
|
||||
@PutMapping(value = "{applicationContractId}", produces = "application/json", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@PreAuthorize( "hasRole('ROLE_SUPER_ADMIN') || hasRole('ROLE_BENEFICIARY') || hasRole('ROLE_CONFIDI')")
|
||||
ResponseEntity<Response<ApplicationContractResponse>> updateApplicationContract(HttpServletRequest request,
|
||||
@Parameter(description = "Application Contract ID", required = true) @PathVariable("applicationContractId") Long applicationContractId, @Parameter(description = "List of files to upload", required = true)
|
||||
@RequestPart(required = true) List<MultipartFile> beneficiaryContractDocuments);
|
||||
|
||||
@Operation(summary = "Api to get an application contract by id",
|
||||
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 = "{applicationContractId}", produces = "application/json")
|
||||
ResponseEntity<Response<ApplicationContractResponse>> getApplicationContractById(HttpServletRequest request,@Parameter(description = "The application contract id", required = true) @RequestParam(value = "id", required = true) Long id);
|
||||
|
||||
@Operation(summary = "Api to get an application contract by application id",
|
||||
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 = "/application/{applicationId}", produces = "application/json")
|
||||
ResponseEntity<Response<ApplicationContractResponse>> getApplicationContractByApplicationId(HttpServletRequest request,@Parameter(description = "The application id", required = true) @RequestParam(value = "applicationId", required = true) Long applicationId);
|
||||
|
||||
@Operation(summary = "Api to get an application contract by beneficiary user id",
|
||||
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 = "/user/{userId}", produces = "application/json")
|
||||
ResponseEntity<Response< List<ApplicationContractResponse>>> getApplicationContractByBeneficiaryUserId(HttpServletRequest request,@Parameter(description = "The user id", required = true) @RequestParam(value = "userId", required = true) Long userId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
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.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||
import net.gepafin.tendermanagement.model.request.ApplicationContractRequest;
|
||||
import net.gepafin.tendermanagement.model.request.UserActionRequest;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationContractResponse;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.service.ApplicationContractService;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import net.gepafin.tendermanagement.web.rest.api.ApplicationContractApi;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("${openapi.gepafin.base-path:/v1/applicationContract}")
|
||||
public class ApplicationContractApiController implements ApplicationContractApi {
|
||||
|
||||
@Autowired
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContractService applicationContractService;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<ApplicationContractResponse>> createApplicationContract(HttpServletRequest request, Long applicationId, List<MultipartFile> contractDocuments, ApplicationContractRequest applicationContractRequest) {
|
||||
loggingUtil.logUserAction(
|
||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT).actionContext(UserActionContextEnum.CREATE_CONTRACT_FOR_APPLICATION).build());
|
||||
ApplicationContractResponse applicationContractResponse=applicationContractService.createApplicationContract(request,applicationId,contractDocuments,applicationContractRequest);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(applicationContractResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.CREATE_APPLICATION_CONTRACT)));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<ApplicationContractResponse>> updateApplicationContract(HttpServletRequest request, Long applicationId, List<MultipartFile> beneficiaryContractDocuments) {
|
||||
loggingUtil.logUserAction(
|
||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPDATE).actionContext(UserActionContextEnum.UPDATE_APPLICATION_CONTRACT).build());
|
||||
ApplicationContractResponse applicationContractResponse=applicationContractService.updateApplicationContract(request,applicationId,beneficiaryContractDocuments);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(applicationContractResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CONTRACT_UPDATED)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<ApplicationContractResponse>> getApplicationContractById(HttpServletRequest request, Long id) {
|
||||
loggingUtil.logUserAction(
|
||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.FETCH_APPLICATION_CONTRACT).build());
|
||||
ApplicationContractResponse applicationContractResponse=applicationContractService.getContractById(id);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(applicationContractResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CONTRACT_FETCHED)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<ApplicationContractResponse>> getApplicationContractByApplicationId(HttpServletRequest request, Long applicationId) {
|
||||
loggingUtil.logUserAction(
|
||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.FETCH_APPLICATION_CONTRACT_BY_APPLICATION_ID).build());
|
||||
ApplicationContractResponse applicationContractResponse=applicationContractService.getContractByApplicationId(applicationId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(applicationContractResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CONTRACT_FETCHED)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<ApplicationContractResponse>>> getApplicationContractByBeneficiaryUserId(HttpServletRequest request, Long beneficiaryUserId) {
|
||||
loggingUtil.logUserAction(
|
||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.FETCH_APPLICATION_CONTRACT_BY_BENEFICIARY_USER_ID).build());
|
||||
List<ApplicationContractResponse> applicationContractResponse=applicationContractService.getContractByBeneficiaryUserId(beneficiaryUserId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(applicationContractResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_CONTRACT_FETCHED)));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user