update call status
This commit is contained in:
@@ -78,6 +78,10 @@ public class GepafinConstant {
|
||||
public static final String UPDATE_USER_STATUS_SUCCESS_MSG = "update.user.status.success";
|
||||
public static final String FIELD_NOT_NULL = "field.not.null";
|
||||
public static final String FIELD_NOT_EMPTY = "field.not.empty";
|
||||
|
||||
public static final String UPDATE_CALL_STATUS_SUCCESS_MSG = "update_call_status_success_msg";
|
||||
public static final String STATUS_SAME_ERROR = "status.same.error";
|
||||
public static final String INVALID_STATUS_CHANGE_FROM_DRAFT = "invalid.status.change.from.draft";
|
||||
public static final String STATUS_CANNOT_BE_CHANGED = "status.cannot.be.changed";
|
||||
public static final String INVALID_STATUS_TRANSITION = "invalid.status.transition";
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -405,6 +406,7 @@ public class CallDao {
|
||||
return callRepository.findById(callId).orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
}
|
||||
|
||||
public CallResponse getCallById(Long callId) {
|
||||
CallEntity callEntity = callRepository.findById(callId)
|
||||
.orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
@@ -591,6 +593,7 @@ public class CallDao {
|
||||
callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
|
||||
return callDetailsResponseBean;
|
||||
}
|
||||
|
||||
private CallResponse getCallResponseBean(CallEntity callEntity) {
|
||||
List<DocumentEntity> documentEntities = documentRepository.findByCallIdAndTypeAndIsDeletedFalse(callEntity.getId(),
|
||||
DocumentTypeEnum.DOCUMENT.getValue());
|
||||
@@ -613,6 +616,7 @@ public class CallDao {
|
||||
createCallResponseBean.setCheckList(checkList);
|
||||
return createCallResponseBean;
|
||||
}
|
||||
|
||||
public List<CallDetailsResponseBean> getAllCalls() {
|
||||
return callRepository.findAll()
|
||||
.stream()
|
||||
@@ -628,4 +632,38 @@ public class CallDao {
|
||||
callResponseBean.setCurrentStep(GepafinConstant.VALIDATE_REQUEST);
|
||||
return callResponseBean;
|
||||
}
|
||||
|
||||
public CallResponse updateCallStatus(Long callId, CallStatusEnum statusReq) {
|
||||
CallEntity callEntity = callRepository.findById(callId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
|
||||
CallStatusEnum currentStatus = CallStatusEnum.valueOf(callEntity.getStatus());
|
||||
validateStatusChange(currentStatus, statusReq);
|
||||
callEntity.setStatus(statusReq.getValue());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
return convertToCallResponseBean(callEntity);
|
||||
}
|
||||
|
||||
private void validateStatusChange(CallStatusEnum currentStatus, CallStatusEnum newStatus) {
|
||||
if (currentStatus == newStatus) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.STATUS_SAME_ERROR));
|
||||
}
|
||||
|
||||
switch (currentStatus) {
|
||||
case DRAFT:
|
||||
if (newStatus == CallStatusEnum.READY_TO_PUBLISH || newStatus == CallStatusEnum.PUBLISH) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_STATUS_CHANGE_FROM_DRAFT));
|
||||
}
|
||||
break;
|
||||
case PUBLISH:
|
||||
case EXPIRE:
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.STATUS_CANNOT_BE_CHANGED));
|
||||
default:
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
Translator.toLocale(GepafinConstant.INVALID_STATUS_TRANSITION));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@ package net.gepafin.tendermanagement.service;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.CreateCallRequestStep1;
|
||||
import net.gepafin.tendermanagement.model.request.CreateCallRequestStep2;
|
||||
import net.gepafin.tendermanagement.model.request.UpdateCallRequestStep1;
|
||||
import net.gepafin.tendermanagement.model.response.CallDetailsResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.CallResponse;
|
||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||
|
||||
public interface CallService {
|
||||
|
||||
@@ -23,4 +26,6 @@ public interface CallService {
|
||||
|
||||
CallResponse validateCall(Long callId);
|
||||
|
||||
CallResponse updateCallStatus(Long callId, CallStatusEnum statusReq);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@ package net.gepafin.tendermanagement.service.impl;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||
import net.gepafin.tendermanagement.dao.CallDao;
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.request.CreateCallRequestStep1;
|
||||
import net.gepafin.tendermanagement.model.request.CreateCallRequestStep2;
|
||||
import net.gepafin.tendermanagement.model.request.UpdateCallRequestStep1;
|
||||
import net.gepafin.tendermanagement.model.response.CallDetailsResponseBean;
|
||||
import net.gepafin.tendermanagement.model.response.CallResponse;
|
||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||
import net.gepafin.tendermanagement.service.CallService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -65,4 +68,10 @@ public class CallServiceImpl implements CallService {
|
||||
public CallResponse validateCall(Long callId) {
|
||||
return callDao.validateCall(callDao.validateCall(callId));
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CallResponse updateCallStatus(Long callId, CallStatusEnum statusReq) {
|
||||
return callDao.updateCallStatus(callId, statusReq);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package net.gepafin.tendermanagement.web.rest.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
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.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -120,5 +120,23 @@ public interface CallApi {
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
public ResponseEntity<Response<CallResponse>> validateCall(HttpServletRequest request,
|
||||
@Parameter(description = "The call id", required = true) @PathVariable("callId") Long callId);
|
||||
|
||||
@Operation(summary = "Api to update call status",
|
||||
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 = "/{callId}/status",
|
||||
produces = {"application/json"},
|
||||
method = RequestMethod.PUT)
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
default ResponseEntity<Response<CallResponse>> updateCallStatus(
|
||||
@Parameter(description = "The call id", required = true) @PathVariable("callId") Long callId,
|
||||
@Parameter(description = "status", required = true)@RequestParam(value = "status", required = true) CallStatusEnum status) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,16 @@ package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.CallStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -78,4 +83,9 @@ public class CallApiController implements CallApi {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(call, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<CallResponse>> updateCallStatus(@PathVariable Long callId, @RequestParam CallStatusEnum status) {
|
||||
CallResponse updateCall = callService.updateCallStatus(callId, status);
|
||||
return ResponseEntity.ok(new Response<>(updateCall, Status.SUCCESS, Translator.toLocale(GepafinConstant.UPDATE_CALL_STATUS_SUCCESS_MSG)));
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,6 @@ call.created.successfully=Call created successfully.
|
||||
file.deleted.successfully=File deleted successfully.
|
||||
document.not.found=Document not found.
|
||||
document.id.not.found=Document ID not found.
|
||||
call.created.successfully=Call created successfully.
|
||||
call.invalid.date=Invalid start or end date.
|
||||
call.update.successfully=Call updated successfully.
|
||||
call.fetch.success=Call details fetched successfully.
|
||||
@@ -51,6 +50,11 @@ call.not.found=Call not found.
|
||||
score.not.null=Score cannot be null or cannot be zero.
|
||||
field.not.null={0} cannot be null.
|
||||
field.not.empty={0} cannot be empty.
|
||||
update_call_status_success_msg=The call status has been updated successfully.
|
||||
status.same.error=Status is already set.
|
||||
invalid.status.change.from.draft=Status cannot be changed to READY_TO_PUBLISH or PUBLISH from DRAFT.
|
||||
status.cannot.be.changed=Status cannot be changed.
|
||||
invalid.status.transition=Invalid status transition.
|
||||
|
||||
# Login-related messages
|
||||
login.successfully=Login successfully.
|
||||
|
||||
@@ -50,6 +50,11 @@ call.not.found=Chiamata non trovata.
|
||||
score.not.null=Il punteggio non pu� essere nullo o zero.
|
||||
field.not.null={0} non può essere nullo.
|
||||
field.not.empty=la {0} non può essere vuota.
|
||||
update_call_status_success_msg=Lo stato della chiamata è stato aggiornato con successo.
|
||||
status.same.error=Lo stato è già impostato.
|
||||
invalid.status.change.from.draft=Lo stato non può essere cambiato in READY_TO_PUBLISH o PUBLISH da DRAFT.
|
||||
status.cannot.be.changed=Lo stato non può essere cambiato.
|
||||
invalid.status.transition=Transizione di stato non valida.
|
||||
|
||||
# Login-related messages
|
||||
login.successfully=Accesso effettuato con successo.
|
||||
|
||||
Reference in New Issue
Block a user