refactored code

This commit is contained in:
rajesh
2024-09-03 20:11:29 +05:30
parent 64f0d7ab85
commit 3752afdfd4
43 changed files with 310 additions and 349 deletions

View File

@@ -35,23 +35,24 @@ public class LookUpDataDao {
lookUpDataRepository.save(entity);
return entity;
}
public void validateLookUpDataEntity(LookUpDataEntity entity) {
if (entity.getValue() == null || entity.getValue().trim().isEmpty()) {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.VALUE_CANNOT_BE_EMPTY));
}
}
public LookUpDataResponseBean getLookUpDataById(Long id) {
return lookUpDataRepository.findById(id)
.map(this::convertLookUpDataEntityToResponseBean)
public LookUpDataEntity validateLookUpData(Long id) {
return lookUpDataRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.LOOKUP_DATA_NOT_FOUND)));
}
public LookUpDataResponseBean getLookUpDataById(Long id) {
return convertLookUpDataEntityToResponseBean(validateLookUpData(id));
}
public LookUpDataResponseBean updateLookUpData(Long id, LookUpDataRequest lookUpDataReq) {
LookUpDataEntity entity = lookUpDataRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.LOOKUP_DATA_NOT_FOUND)));
LookUpDataEntity entity = validateLookUpData(id);
entity.setTitle(lookUpDataReq.getTitle());
entity.setType(lookUpDataReq.getType().getValue());
entity.setValue(lookUpDataReq.getValue());
@@ -60,8 +61,7 @@ public class LookUpDataDao {
}
public void deleteLookUpData(Long id) {
LookUpDataEntity entity = lookUpDataRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.LOOKUP_DATA_NOT_FOUND)));
LookUpDataEntity entity = validateLookUpData(id);
lookUpDataRepository.deleteById(entity.getId());
}