Done ticket GEPAFINBE-3

This commit is contained in:
harish
2024-08-14 15:31:00 +05:30
parent 2773dfa034
commit e09f61f918
51 changed files with 2107 additions and 70 deletions

View File

@@ -0,0 +1,91 @@
package net.gepafin.tendermanagement.web.rest.api;
import net.gepafin.tendermanagement.entities.RegionEntity;
import net.gepafin.tendermanagement.model.request.RegionReq;
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
import net.gepafin.tendermanagement.model.request.UpdateRegionReq;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
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 io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Validated
@RequestMapping("/region")
public interface RegionApi {
@Operation(summary = "Api to create region",
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 = "",produces = "application/json")
ResponseEntity<Response<RegionResponseBean>> createRegion(
@Parameter(description = "Region request object", required = true) @Valid @RequestBody RegionReq regionReq);
@Operation(summary = "Api to update region",
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 = "/{regionId}", produces = "application/json")
ResponseEntity<Response<RegionResponseBean>> updateRegion(
@Parameter(description = "The region id", required = true) @PathVariable("regionId") Long regionId,
@Parameter(description = "Region request object", required = true) @Valid @RequestBody RegionReq regionReq);
@Operation(summary = "Api to get a region 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 = "/{regionId}", produces = "application/json")
ResponseEntity<Response<RegionEntity>> getRegionById(
@Parameter(description = "The region id", required = true) @PathVariable("regionId") Long regionId);
@Operation(summary = "Api to get all regions",
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 = "",
produces = { "application/json" })
ResponseEntity<Response<List<RegionResponseBean>>> getAllRegions();
@Operation(summary = "Api to delete region",
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) })) })
@DeleteMapping(value = "/{regionId}")
ResponseEntity<Response<Void>> deleteRegion(
@Parameter(description = "The region id", required = true) @PathVariable("regionId") Long regionId);
}

View File

@@ -0,0 +1,93 @@
package net.gepafin.tendermanagement.web.rest.api;
import net.gepafin.tendermanagement.entities.RoleEntity;
import net.gepafin.tendermanagement.model.request.RoleReq;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
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 io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Validated
public interface RoleApi {
@Operation(summary = "API to create role",
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 = "",
produces = { "application/json" })
ResponseEntity<Response<RoleResponseBean>> createRole(
@Parameter(description = " Role request object", required = true) @Valid @RequestBody RoleReq roleReq);
@Operation(summary = "API to update role",
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 = "/{roleId}",
produces = { "application/json" })
ResponseEntity<Response<RoleResponseBean>> updateRole(
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId,
@Parameter(description = "Role request object", required = true) @Valid @RequestBody RoleReq roleReq);
@Operation(summary = "API to get role 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 = "/{roleId}",
produces = { "application/json" })
ResponseEntity<Response<RoleEntity>> getRoleById(
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId);
@Operation(summary = "API to get all roles",
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 = "",
produces = { "application/json" })
ResponseEntity<Response<List<RoleResponseBean>>> getAllRoles();
@Operation(summary = "API to delete role",
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) })) })
@DeleteMapping(value = "/{roleId}")
ResponseEntity<Response<Void>> deleteRole(
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId);
}

View File

@@ -1,8 +1,94 @@
package net.gepafin.tendermanagement.web.rest.api;
import net.gepafin.tendermanagement.model.User;
import org.springframework.web.bind.annotation.GetMapping;
import io.swagger.v3.oas.annotations.Parameter;
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 jakarta.validation.Valid;
import net.gepafin.tendermanagement.model.request.UpdateUserReq;
import net.gepafin.tendermanagement.model.request.UserReq;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Validated
//@RequestMapping("/user")
public interface UserApi {
@GetMapping("")
User getUser();
@Operation(summary = "Api to create user",
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) })) })
@RequestMapping(value = "",
produces = { "application/json" },
method = RequestMethod.POST)
default ResponseEntity<Response<UserResponseBean>> createUser(
@Parameter(description = "User request object", required = true) @Valid @RequestBody UserReq userReq) {
return new ResponseEntity<Response<UserResponseBean>>(HttpStatus.NOT_IMPLEMENTED);
}
@Operation(summary = "Api to update user",
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) })) })
@RequestMapping(value = "/{userId}",
produces = { "application/json" },
method = RequestMethod.PUT)
default ResponseEntity<Response<UserResponseBean>> updateUser(
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId,
@Parameter(description = "User request object", required = true) @Valid @RequestBody UpdateUserReq userReq) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@Operation(summary = "Api to get user 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) })) })
@RequestMapping(value = "/{userId}",
produces = { "application/json" },
method = RequestMethod.GET)
default ResponseEntity<Response<UserResponseBean>> getUserById(
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@Operation(summary = "Api to delete user",
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) })) })
@RequestMapping(value = "/{userId}",
method = RequestMethod.DELETE)
default ResponseEntity<Response<Void>> deleteUser(
@Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
}

View File

@@ -0,0 +1,16 @@
package net.gepafin.tendermanagement.web.rest.api.errors;
public class CustomValidationException extends RuntimeException {
private final Status status;
private static final long serialVersionUID = 1L;
public Status getStatus() {
return status;
}
public CustomValidationException(Status status, String message) {
super(message);
this.status = status;
}
}

View File

@@ -0,0 +1,28 @@
package net.gepafin.tendermanagement.web.rest.api.errors;
import java.net.URI;
public final class ErrorConstants {
public static final String ERR_CONCURRENCY_FAILURE = "error.concurrencyFailure";
public static final String ERR_VALIDATION = "error.validation";
public static final String PROBLEM_BASE_URL = "https://www.jhipster.tech/problem";
public static final URI DEFAULT_TYPE = URI.create(PROBLEM_BASE_URL + "/problem-with-message");
public static final URI CONSTRAINT_VIOLATION_TYPE = URI.create(PROBLEM_BASE_URL + "/constraint-violation");
public static final URI INVALID_PASSWORD_TYPE = URI.create(PROBLEM_BASE_URL + "/invalid-password");
public static final URI EMAIL_ALREADY_USED_TYPE = URI.create(PROBLEM_BASE_URL + "/email-already-used");
public static final URI LOGIN_ALREADY_USED_TYPE = URI.create(PROBLEM_BASE_URL + "/login-already-used");
public static final String BADREQUEST_ERROR_EXAMPLE="{\"data\": null,"
+"\"status\": \"VALIDATION_ERROR\",\"message\": \"string\""
+ "}";
public static final String NOTFOUND_ERROR_EXAMPLE="{\"data\": null,"
+"\"status\": \"NOT_FOUND\",\"message\": \"string\""
+ "}";
public static final String UNAUTHORIZED_ERROR_EXAMPLE="{\"data\": null,"
+"\"status\": \"UNAUTHORIZED\",\"message\": \"string\""
+ "}";
private ErrorConstants() {
}
}

View File

@@ -0,0 +1,23 @@
package net.gepafin.tendermanagement.web.rest.api.errors;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;
private final Status status;
public ResourceNotFoundException(Status status, String message) {
super(message);
this.status = status;
}
public Status getStatus() {
return status;
}
}

View File

@@ -0,0 +1,16 @@
package net.gepafin.tendermanagement.web.rest.api.errors;
public enum Status {
SUCCESS("1"), VALIDATION_ERROR("2"), EXCEPTION_ERROR("3") , NOT_FOUND("4") , BAD_REQUEST("5") , UNAUTHORIZED("6") ,
FORBIDDEN("7"), VALIDATION_COMPLETED("8");
private String action;
public String getAction() {
return this.action;
}
private Status(String action) {
this.action = action;
}
}

View File

@@ -0,0 +1,79 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.RegionEntity;
import net.gepafin.tendermanagement.model.request.RegionReq;
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
import net.gepafin.tendermanagement.model.request.UpdateRegionReq;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.RegionService;
import net.gepafin.tendermanagement.web.rest.api.RegionApi;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
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;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
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/region}")
public class RegionApiController implements RegionApi {
private final Logger log = LoggerFactory.getLogger(RegionApiController.class);
@Autowired
private RegionService regionService;
@Override
public ResponseEntity<Response<RegionResponseBean>> createRegion(
@Valid @RequestBody RegionReq regionReq) {
log.info("Create Region - Request Body: {}", regionReq);
RegionResponseBean createdRegion = regionService.createRegion(regionReq);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(createdRegion, Status.SUCCESS, Translator.toLocale(GepafinConstant.REGION_CREATED_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<RegionResponseBean>> updateRegion(
@PathVariable("regionId") Long regionId,
@Valid @RequestBody RegionReq regionReq) {
log.info("Update Region - Region ID: {}, Request Body: {}", regionId, regionReq);
RegionResponseBean updatedRegion = regionService.updateRegion(regionId, regionReq);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(updatedRegion, Status.SUCCESS, Translator.toLocale(GepafinConstant.REGION_UPDATED_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<RegionEntity>> getRegionById(
@PathVariable("regionId") Long regionId) {
log.info("Get Region by ID - Region ID: {}", regionId);
RegionEntity region = regionService.getRegionById(regionId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(region, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_REGION_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<Void>> deleteRegion(
@PathVariable("regionId") Long regionId) {
log.info("Delete Region - Region ID: {}", regionId);
regionService.deleteRegion(regionId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELETE_REGION_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<List<RegionResponseBean>>> getAllRegions() {
List<RegionResponseBean> regions = regionService.getAllRegions();
log.info("Get All Region");
regionService.getAllRegions();
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(regions, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_REGION_SUCCESS_MSG)));
}
}

View File

@@ -0,0 +1,75 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import java.util.List;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.RoleEntity;
import net.gepafin.tendermanagement.model.request.RoleReq;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.RoleService;
import net.gepafin.tendermanagement.web.rest.api.RoleApi;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
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;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("${openapi.gepafin.base-path:/v1/role}")
public class RoleApiController implements RoleApi {
private static final Logger log = LoggerFactory.getLogger(RoleApiController.class);
@Autowired
private RoleService roleService;
@Override
public ResponseEntity<Response<RoleResponseBean>> createRole(RoleReq body) {
log.info("Create Role - Request Body: {}", body);
RoleResponseBean roleReq = roleService.createRole(body);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(roleReq, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_CREATED_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<RoleResponseBean>> updateRole(Long roleId, RoleReq body) {
log.info("Update Role - Role ID: {}, Request Body: {}", roleId, body);
RoleResponseBean updatedUserRole = roleService.updateRole(roleId, body);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(updatedUserRole, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_UPDATED_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<List<RoleResponseBean>>> getAllRoles() {
log.info("Get All Roles");
List<RoleResponseBean> roles = roleService.getAllRoles();
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(roles, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_FETCH_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<RoleEntity>> getRoleById(Long roleId) {
log.info("Get Role by ID - Role ID: {}", roleId);
RoleEntity roleEntity = roleService.getRoleById(roleId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(roleEntity, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_FETCH_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<Void>> deleteRole(Long roleId) {
log.info("Delete Role - Role ID: {}", roleId);
roleService.deleteRole(roleId);
return ResponseEntity.status(HttpStatus.NO_CONTENT)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_DELETED_SUCCESS_MSG)));
}
}

View File

@@ -1,18 +1,72 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import net.gepafin.tendermanagement.model.User;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.model.request.UpdateUserReq;
import net.gepafin.tendermanagement.model.request.UserReq;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.UserService;
import net.gepafin.tendermanagement.web.rest.api.UserApi;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
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;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/v1/user")
public class UserApiController implements UserApi
{
@RequestMapping("${openapi.gepafin.base-path:/v1/user}")
public class UserApiController implements UserApi {
private final Logger log = LoggerFactory.getLogger(UserApiController.class);
@Autowired
private UserService userService;
@Override
public User getUser() {
return new User(1L, "John Doe", "john.doe@test.test");
public ResponseEntity<Response<UserResponseBean>> createUser(
@Valid @RequestBody UserReq userReq) {
log.info("Create User with - Request Body: {}", userReq);
UserResponseBean createdUser = userService.createUser(userReq);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(createdUser, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_CREATED_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<UserResponseBean>> updateUser(
@PathVariable("userId") Long userId,
@Valid @RequestBody UpdateUserReq userReq) {
log.info("Update User - User ID: {}, Request Body: {}", userId, userReq);
UserResponseBean updatedUser = userService.updateUser(userId, userReq);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(updatedUser, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_UPDATED_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<UserResponseBean>> getUserById(
@PathVariable("userId") Long userId) {
log.info("Get User by ID - User ID: {}", userId);
UserResponseBean user = userService.getUserById(userId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(user, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USER_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<Void>> deleteUser(
@PathVariable("userId") Long userId) {
log.info("Delete User By- User ID: {}", userId);
userService.deleteUser(userId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.USER_DELETED_SUCCESS_MSG)));
}
}