Merge branch 'develop' of https://github.com/Kitzanos/GEPAFIN-BE into feature/GEPAFINBE-55

This commit is contained in:
Anisha Gokhru
2024-10-21 18:52:36 +05:30
65 changed files with 1603 additions and 297 deletions

View File

@@ -85,7 +85,7 @@ public interface CallApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/{callId}",
produces = { "application/json" })
ResponseEntity<Response<CallResponse>> getCallById(
ResponseEntity<Response<CallResponse>> getCallById(HttpServletRequest request,
@Parameter(description = "The call ID", required = true) @PathVariable("callId") Long callId);

View File

@@ -72,7 +72,7 @@ public interface EvaluationCriteriaApi {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) }))
})
@DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Void> deleteEvaluationCriteria(HttpServletRequest request,
ResponseEntity<Response<Void>> deleteEvaluationCriteria(HttpServletRequest request,
@Parameter(description = "evaluation criteria id", required = true)
@PathVariable("id") Long id);
}

View File

@@ -0,0 +1,113 @@
package net.gepafin.tendermanagement.web.rest.api;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.model.request.HubReq;
import net.gepafin.tendermanagement.model.response.HubResponseBean;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Validated
@RequestMapping("/hub")
public interface HubApi {
@Operation(summary = "API to create a hub", 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) }))
})
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
@PostMapping(value = "", produces = "application/json")
ResponseEntity<Response<HubResponseBean>> createHub(HttpServletRequest request,
@Parameter(description = "Hub request object", required = true)
@Valid @RequestBody HubReq hubReq);
@Operation(summary = "API to update a hub", 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) }))
})
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
@PutMapping(value = "/{hubId}", produces = "application/json")
ResponseEntity<Response<HubResponseBean>> updateHub(HttpServletRequest request,
@Parameter(description = "The hub id", required = true)
@PathVariable("hubId") Long hubId,
@Parameter(description = "Hub request object", required = true)
@Valid @RequestBody HubReq hubReq);
@Operation(summary = "API to get a hub 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 = "/{hubId}", produces = "application/json")
ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request,
@Parameter(description = "The hub id", required = true)
@PathVariable("hubId") Long hubId);
@Operation(summary = "API to get all hubs", 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) }))
})
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
@GetMapping(value = "", produces = "application/json")
ResponseEntity<Response<List<HubResponseBean>>> getAllHubs(HttpServletRequest request);
@Operation(summary = "API to delete a hub", 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) }))
})
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
@DeleteMapping(value = "/{hubId}")
ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request,
@Parameter(description = "The hub id", required = true)
@PathVariable("hubId") Long hubId);
@Operation(summary = "API to get a hub 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 = "/uuid/{uuid}", produces = "application/json")
ResponseEntity<Response<HubResponseBean>> getHubByUuid(HttpServletRequest request,
@Parameter(description = "The hub id", required = true)
@PathVariable("uuid") String uuid);
}

View File

@@ -144,8 +144,10 @@ public interface UserApi {
@RequestMapping(value = "/change-password",
produces = {"application/json"},
method = RequestMethod.POST)
ResponseEntity<Response<Boolean>> changePassword(
@Parameter(description = "Change password request object", required = true) @Valid @RequestBody ChangePasswordRequest changePasswordRequest); @Operation(summary = "Api to logout user",
ResponseEntity<Response<Boolean>> changePassword(HttpServletRequest request,
@Parameter(description = "Change password request object", required = true) @Valid @RequestBody ChangePasswordRequest changePasswordRequest);
@Operation(summary = "Api to logout user",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@@ -192,6 +194,7 @@ public interface UserApi {
produces = { "application/json" })
ResponseEntity<Response<UserResponseBean>> getValidUser(HttpServletRequest request);
@Operation(summary = "Api to validate existing user from saml token",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@@ -232,7 +235,7 @@ public interface UserApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
@RequestMapping(value = "", produces = {"application/json"}, method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(
ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(HttpServletRequest request,
@Parameter( required = false)@RequestParam(value ="roleId", required = false) Long roleId);

View File

@@ -59,8 +59,8 @@ public class CallApiController implements CallApi {
}
@Override
@Transactional(readOnly = true)
public ResponseEntity<Response<CallResponse>> getCallById(Long callId) {
CallResponse createCallResponseBean = callService.getCallById(callId);
public ResponseEntity<Response<CallResponse>> getCallById(HttpServletRequest request, Long callId) {
CallResponse createCallResponseBean = callService.getCallById(request, callId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(createCallResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG)));
}
@@ -76,7 +76,7 @@ public class CallApiController implements CallApi {
}
@Override
public ResponseEntity<Response<CallResponse>> validateCallData(HttpServletRequest request, Long callId) {
CallResponse call = callService.validateCallData(callId);
CallResponse call = callService.validateCallData(request, callId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(call, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG)));

View File

@@ -29,10 +29,13 @@ public class CustomUserDetailsService implements UserDetailsService {
@Override
@Transactional
public UserDetails loadUserByUsername(final String email) throws UsernameNotFoundException {
log.debug("Authenticating {}", email);
public UserDetails loadUserByUsername(final String emailWithHudId) throws UsernameNotFoundException {
log.debug("Authenticating {}", emailWithHudId);
String[] loginParts = emailWithHudId.split(":");
String email = loginParts[0];
String hubId = loginParts[1];
UserEntity user = userRepository.findByEmailIgnoreCase(email)
UserEntity user = userRepository.findByEmailIgnoreCaseAndHubUniqueUuid(email, hubId)
.orElseThrow(
() -> new UsernameNotFoundException("User " + email + " was not found in the database"));
return createSpringSecurityUser(user);

View File

@@ -57,10 +57,10 @@ public class EvaluationCriteriaApiController implements EvaluationCriteriaApi {
}
@Override
public ResponseEntity<Void> deleteEvaluationCriteria(HttpServletRequest request, Long id) {
public ResponseEntity<Response<Void>> deleteEvaluationCriteria(HttpServletRequest request, Long id) {
service.deleteEvaluationCriteria(request,id);
return ResponseEntity.status(HttpStatus.OK)
.header("Message", Translator.toLocale(GepafinConstant.EVALUATION_CRITERIA_DELETED_SUCCESSFULLY))
.build();
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.EVALUATION_CRITERIA_DELETED_SUCCESSFULLY)));
}
}

View File

@@ -0,0 +1,73 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.model.request.HubReq;
import net.gepafin.tendermanagement.model.response.HubResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.HubService;
import net.gepafin.tendermanagement.web.rest.api.HubApi;
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.RestController;
import java.util.List;
@RestController
public class HubApiController implements HubApi {
@Autowired
private HubService hubService;
@Override
public ResponseEntity<Response<HubResponseBean>> createHub(HttpServletRequest request, @Valid HubReq hubReq) {
HubResponseBean hubResponse = hubService.createHub(hubReq);
return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_CREATE_SUCCESS)));
}
@Override
public ResponseEntity<Response<HubResponseBean>> updateHub(HttpServletRequest request, Long hubId, @Valid HubReq hubReq) {
HubResponseBean hubResponse = hubService.updateHub(hubId, hubReq);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_UPDATE_SUCCESS)));
}
@Override
public ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request, Long hubId) {
HubResponseBean hubResponse = hubService.getHubById(hubId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_SUCCESS)));
}
@Override
public ResponseEntity<Response<List<HubResponseBean>>> getAllHubs(HttpServletRequest request) {
List<HubResponseBean> hubs = hubService.getAllHubs();
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(hubs, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_ALL_SUCCESS)));
}
@Override
public ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request, Long hubId) {
hubService.deleteHub(hubId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_DELETE_SUCCESS)));
}
@Override
public ResponseEntity<Response<HubResponseBean>> getHubByUuid(HttpServletRequest request, String uuid) {
HubResponseBean hubResponse = hubService.getHubByHubUuid(uuid);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_SUCCESS)));
}
}

View File

@@ -79,9 +79,9 @@ public class UserApiController implements UserApi {
return ResponseEntity.ok(new Response<>(jwtToken, Status.SUCCESS, Translator.toLocale(GepafinConstant.LOGIN_SUCCESS_MSG)));
}
@Override
public ResponseEntity<Response<Boolean>> changePassword(@Valid @RequestBody ChangePasswordRequest request) {
public ResponseEntity<Response<Boolean>> changePassword(HttpServletRequest httpServletRequest, @Valid @RequestBody ChangePasswordRequest request) {
log.info("Change Password attempt for email: {}", request.getEmail());
userService.changePassword(request);
userService.changePassword(httpServletRequest, request);
return ResponseEntity.ok(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.SUCCESS_PASSWORD_CHANGED)));
}
@Override
@@ -142,10 +142,10 @@ public class UserApiController implements UserApi {
return ResponseEntity.ok(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.TOKEN_VALIDATE_SUCCESS_MSE)));
}
@Override
public ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(
public ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(HttpServletRequest request,
Long roleId) {
log.info("Get all Users by Role ID - Role ID: {}", roleId);
List<UserResponseBean> users = userService.getAllUsers(roleId);
List<UserResponseBean> users = userService.getAllUsers(request, roleId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(users, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USERS_SUCCESS_MSG)));
}