updated code

This commit is contained in:
rajesh
2024-08-27 13:58:57 +05:30
parent f561695db0
commit e7fa11f35e
3 changed files with 29 additions and 2 deletions

View File

@@ -239,10 +239,12 @@ public class CallDao {
Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG)); Translator.toLocale(GepafinConstant.AMOUNT_GREATER_THAN_ZERO_MSG));
} }
if (createCallRequest.getStartDate().toLocalDate().isBefore(LocalDate.now()) 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, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.INVALID_DATE_MSG)); Translator.toLocale(GepafinConstant.INVALID_DATE_MSG));
} }
} }
public CreateCallResponseBean convertToCallResponseBean(CallEntity callEntity) { public CreateCallResponseBean convertToCallResponseBean(CallEntity callEntity) {
@@ -382,7 +384,7 @@ public class CallDao {
private CallEntity getCallById(Long callId) { private CallEntity getCallById(Long callId) {
return callRepository.findById(callId).orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR, 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) { public CreateCallResponseBean createCallStep2(CreateCallRequestStep2 createCallRequest, Long userId) {
@@ -412,8 +414,31 @@ public class CallDao {
return createCallResponseBean; 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) { public CreateCallResponseBean updateCallStep1(Long callId, UpdateCallRequestStep1 updateCallRequest, Long userId) {
CallEntity callEntity = getCallById(callId); CallEntity callEntity = getCallById(callId);
isValidDateRange(updateCallRequest, callEntity);
setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName()); setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName());
setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort, setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort,
updateCallRequest.getDescriptionShort()); updateCallRequest.getDescriptionShort());

View File

@@ -46,6 +46,7 @@ document.id.not.found=Document ID not found.
call.created.successfully=Call created successfully. call.created.successfully=Call created successfully.
call.invalid.date=Invalid start or end date. call.invalid.date=Invalid start or end date.
call.update.successfully=Call updated successfully. call.update.successfully=Call updated successfully.
call.not.found=Call not found.
# Login-related messages # Login-related messages
login.successfully=Login successfully. login.successfully=Login successfully.

View File

@@ -45,6 +45,7 @@ document.not.found=Documento non trovato.
document.id.not.found=ID documento non trovato. document.id.not.found=ID documento non trovato.
call.invalid.date=Data di inizio o fine non valida. call.invalid.date=Data di inizio o fine non valida.
call.update.successfully=Chiamata aggiornata con successo. call.update.successfully=Chiamata aggiornata con successo.
call.not.found=Chiamata non trovata.
# Login-related messages # Login-related messages
login.successfully=Accesso effettuato con successo. login.successfully=Accesso effettuato con successo.