Merge pull request #12 from Kitzanos/update-call-status

update-call-status (Endpoint to update call status)
This commit is contained in:
bagoraharish92
2024-08-28 16:40:46 +05:30
committed by GitHub
13 changed files with 133 additions and 39 deletions

View File

@@ -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";
}

View File

@@ -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,
@@ -486,7 +488,7 @@ public class CallDao {
}
private void updateFaq(CallEntity callEntity, List<FaqReq> faqReqList, UserEntity userEntity) {
if(faqReqList==null) {
if (faqReqList == null) {
return;
}
List<FaqEntity> existingFaqs = faqRepository.findByCallIdAndIsDeletedFalse(callEntity.getId());
@@ -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));
}
}
}

View File

@@ -67,11 +67,12 @@ public class LookUpDataDao {
return response;
}
public List<LookUpDataResponseBean> getLookUpDataByType(LookUpDataTypeEnum type) {
return lookUpDataRepository.findByType(type.getValue())
.stream()
public List<LookUpDataResponseBean> getLookUpDataByTypes(List<LookUpDataTypeEnum> types) {
return types.stream()
.flatMap(type -> lookUpDataRepository.findByType(type.getValue()).stream())
.map(this::convertLookUpDataEntityToResponseBean)
.collect(Collectors.toList());
}
}

View File

@@ -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);
}

View File

@@ -16,5 +16,5 @@ public interface LookUpDataService {
void deleteLookUpData(Long id);
List<LookUpDataResponseBean> getLookUpDataByType(LookUpDataTypeEnum type);
List<LookUpDataResponseBean> getLookUpDataByType(List<LookUpDataTypeEnum> type);
}

View File

@@ -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);
}
}

View File

@@ -36,7 +36,7 @@ public class LookUpDataServiceImpl implements LookUpDataService {
lookUpDataDao.deleteLookUpData(id);
}
@Override
public List<LookUpDataResponseBean> getLookUpDataByType(LookUpDataTypeEnum type) {
return lookUpDataDao.getLookUpDataByType(type);
public List<LookUpDataResponseBean> getLookUpDataByType( List<LookUpDataTypeEnum> type) {
return lookUpDataDao.getLookUpDataByTypes(type);
}
}

View File

@@ -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);
}
}

View File

@@ -77,5 +77,5 @@ public interface LookUpDataApi {
@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);
ResponseEntity<Response<List<LookUpDataResponseBean>>> getLookUpDataByType(HttpServletRequest request, @RequestParam List<LookUpDataTypeEnum> types);
}

View File

@@ -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)));
}
}

View File

@@ -63,7 +63,7 @@ public class LookUpDataApiController implements LookUpDataApi {
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.LOOKUP_DATA_DELETED_SUCCESSFULLY)));
}
@Override
public ResponseEntity<Response<List<LookUpDataResponseBean>>> getLookUpDataByType(HttpServletRequest request, LookUpDataTypeEnum type) {
public ResponseEntity<Response<List<LookUpDataResponseBean>>> getLookUpDataByType(HttpServletRequest request, List<LookUpDataTypeEnum> type) {
List<LookUpDataResponseBean> responseBean = lookUpDataService.getLookUpDataByType(type);
if (responseBean != null) {
return ResponseEntity.status(HttpStatus.OK)

View File

@@ -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.

View File

@@ -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.