diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index 2131519d..a1d7ebbd 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -239,10 +239,12 @@ public class CallDao { Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG)); } if (createCallRequest.getStartDate().toLocalDate().isBefore(LocalDate.now()) - || createCallRequest.getEndDate().toLocalDate().isBefore(LocalDate.now())) { + || createCallRequest.getEndDate().toLocalDate().isBefore(LocalDate.now()) || createCallRequest + .getStartDate().toLocalDate().isAfter(createCallRequest.getEndDate().toLocalDate())) { throw new CustomValidationException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.INVALID_DATE_MSG)); } + } public CreateCallResponseBean convertToCallResponseBean(CallEntity callEntity) { @@ -382,7 +384,7 @@ public class CallDao { private CallEntity getCallById(Long callId) { return callRepository.findById(callId).orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR, - Translator.toLocale(GepafinConstant.NAME_NOT_EMPTY_MSG))); + Translator.toLocale(GepafinConstant.CALL_NOT_FOUND))); } public CreateCallResponseBean createCallStep2(CreateCallRequestStep2 createCallRequest, Long userId) { @@ -412,8 +414,31 @@ public class CallDao { return createCallResponseBean; } + public void isValidDateRange(UpdateCallRequestStep1 updateCallRequest, CallEntity callEntity) { + LocalDate startDate = updateCallRequest.getStartDate() != null ? updateCallRequest.getStartDate().toLocalDate() + : null; + LocalDate endDate = updateCallRequest.getEndDate() != null ? updateCallRequest.getEndDate().toLocalDate() + : null; + Boolean isValid = true; + if (startDate != null && endDate != null && startDate.isAfter(endDate)) { + isValid = false; + } else if (startDate != null && callEntity.getEndDate() != null + && startDate.isAfter(callEntity.getEndDate().toLocalDate())) { + isValid = false; + } else if (endDate != null && callEntity.getStartDate() != null + && callEntity.getStartDate().toLocalDate().isAfter(endDate)) { + isValid = false; + } + + if (Boolean.FALSE.equals(isValid)) { + throw new CustomValidationException(Status.VALIDATION_ERROR, + Translator.toLocale(GepafinConstant.INVALID_DATE_MSG)); + } + } + public CreateCallResponseBean updateCallStep1(Long callId, UpdateCallRequestStep1 updateCallRequest, Long userId) { CallEntity callEntity = getCallById(callId); + isValidDateRange(updateCallRequest, callEntity); setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName()); setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort, updateCallRequest.getDescriptionShort()); diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index 345ff54e..447e637b 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -46,6 +46,7 @@ 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.not.found=Call not found. # Login-related messages login.successfully=Login successfully. diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index 6ad0869e..c403ea60 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -45,6 +45,7 @@ document.not.found=Documento non trovato. document.id.not.found=ID documento non trovato. call.invalid.date=Data di inizio o fine non valida. call.update.successfully=Chiamata aggiornata con successo. +call.not.found=Chiamata non trovata. # Login-related messages login.successfully=Accesso effettuato con successo.