Add few APIs related to call and Update Responses for Call Controller

This commit is contained in:
harish
2024-08-27 16:55:50 +05:30
parent 157168a59e
commit 21fc9a4b91
17 changed files with 136 additions and 36 deletions

View File

@@ -379,10 +379,16 @@ public class CallDao {
return lookUpDataResponse;
}
public CallEntity getCallById(Long callId) {
public CallEntity validateCall(Long callId) {
return callRepository.findById(callId).orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
}
public CreateCallResponseBean getCallById(Long callId) {
CallEntity callEntity = callRepository.findById(callId)
.orElseThrow(() -> new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.CALL_NOT_FOUND)));
return convertToCallResponseBean(callEntity);
}
public CreateCallResponseBean createCallStep2(CreateCallRequestStep2 createCallRequest, Long userId) {
CreateCallResponseBean createCallResponseBean = null;
@@ -434,7 +440,7 @@ public class CallDao {
}
public CreateCallResponseBean updateCallStep1(Long callId, UpdateCallRequestStep1 updateCallRequest, Long userId) {
CallEntity callEntity = getCallById(callId);
CallEntity callEntity = validateCall(callId);
isValidDateRange(updateCallRequest, callEntity);
setIfUpdated(callEntity::getName, callEntity::setName, updateCallRequest.getName());
setIfUpdated(callEntity::getDescriptionShort, callEntity::setDescriptionShort,
@@ -454,6 +460,26 @@ public class CallDao {
return createCallResponseBean;
}
public CallDetailsResponseBean convertToCallDetailsResponseBean(CallEntity callEntity) {
CallDetailsResponseBean callDetailsResponseBean = new CallDetailsResponseBean();
callDetailsResponseBean.setId(callEntity.getId());
callDetailsResponseBean.setName(callEntity.getName());
callDetailsResponseBean.setDates(List.of(callEntity.getStartDate(), callEntity.getEndDate()));
callDetailsResponseBean.setDescriptionShort(callEntity.getDescriptionShort());
callDetailsResponseBean.setDescriptionLong(callEntity.getDescriptionLong());
callDetailsResponseBean.setStatus(CallTypeEnum.valueOf(callEntity.getStatus()));
callDetailsResponseBean.setRegionId(callEntity.getRegion().getId());
callDetailsResponseBean.setAmount(callEntity.getAmount());
callDetailsResponseBean.setAmountMax(callEntity.getAmountMax());
callDetailsResponseBean.setContactInfo(callEntity.getContactInfo());
callDetailsResponseBean.setSubmissionMethod(callEntity.getSubmissionMethod());
callDetailsResponseBean.setThreshold(callEntity.getThreshold());
callDetailsResponseBean.setDocumentationReqested(callEntity.getDocumentationRequested());
callDetailsResponseBean.setPriorityArea(callEntity.getPriorityArea());
callDetailsResponseBean.setCreatedDate(callEntity.getCreatedDate());
callDetailsResponseBean.setUpdatedDate(callEntity.getUpdatedDate());
return callDetailsResponseBean;
}
private CreateCallResponseBean getCallResponseBean(CallEntity callEntity) {
List<DocumentEntity> documentEntities = documentRepository.findByCallIdAndType(callEntity.getId(),
DocumentTypeEnum.DOCUMENT.getValue());
@@ -476,10 +502,10 @@ public class CallDao {
createCallResponseBean.setCheckList(checkList);
return createCallResponseBean;
}
public List<CreateCallResponseBean> getAllCalls() {
return callRepository.findAll()
public List<CallDetailsResponseBean> getAllCalls() {
return callRepository.findAll()
.stream()
.map(callEntity -> Utils.convertObject(callEntity, CreateCallResponseBean.class))
.map(this::convertToCallDetailsResponseBean)
.collect(Collectors.toList());
}
}

View File

@@ -76,7 +76,7 @@ public class RegionDao {
public RegionResponseBean updateRegion(Long id, RegionReq regionReq) {
log.info("Updating region with ID: {}", id);
RegionEntity existingRegion = getRegionById(id);
RegionEntity existingRegion = validateRegion(id);
log.info("Current region details: {}", existingRegion);
log.info("New region details: {}", regionReq);
String newStatus = regionReq.getStatus() != null ? regionReq.getStatus().getValue() : null;
@@ -102,14 +102,19 @@ public class RegionDao {
return Utils.convertObject(existingRegion, RegionResponseBean.class);
}
public RegionEntity getRegionById(Long id) {
public RegionEntity validateRegion(Long id) {
log.info("Fetching region with ID: {}", id);
RegionEntity regionEntity = regionRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
log.info("Region found: {}", regionEntity);
return regionEntity;
}
public RegionResponseBean getRegionById(Long id) {
log.info("Fetching region with ID: {}", id);
RegionEntity regionEntity = regionRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.REGION_NOT_FOUND_MSG)));
return convertRegionEntityToRegionResponse(regionEntity);
}
public void deleteById(Long id) {
log.info("Deleting region with ID: {}", id);
regionRepository.findById(id)

View File

@@ -2,6 +2,7 @@ package net.gepafin.tendermanagement.dao;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.RegionEntity;
import net.gepafin.tendermanagement.entities.RoleEntity;
import net.gepafin.tendermanagement.model.request.RoleReq;
import net.gepafin.tendermanagement.model.response.RegionResponseBean;
@@ -48,7 +49,8 @@ public class RoleDao {
roleEntity.setRoleType(roleReq.getRoleType());
roleEntity.setPermissions(roleReq.getPermissions());
roleEntity.setDescription(roleReq.getDescription());
roleEntity.setRegion(regionService.getRegionById(roleReq.getRegionId()));
RegionEntity regionEntity =regionDao.validateRegion(roleReq.getRegionId());
roleEntity.setRegion(regionEntity);
return roleEntity;
}
@@ -68,7 +70,7 @@ public class RoleDao {
public RoleResponseBean updateRole(Long id, RoleReq roleReq) {
log.info("Updating role with ID: {}", id);
RoleEntity existingRole = getRoleById(id);
RoleEntity existingRole = validateRole(id);
// Log changes before update
log.info("Current role details: {}", existingRole);
@@ -85,14 +87,20 @@ public class RoleDao {
return Utils.convertObject(existingRole, RoleResponseBean.class);
}
public RoleEntity getRoleById(Long id) {
public RoleEntity validateRole(Long id) {
log.info("Fetching role with ID: {}", id);
RoleEntity roleEntity = roleRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.ROLE_NOT_FOUND)));
log.info("Role found: {}", roleEntity);
return roleEntity;
}
public RoleResponseBean getRoleById(Long id) {
log.info("Fetching role with ID: {}", id);
RoleEntity roleEntity = roleRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.ROLE_NOT_FOUND)));
log.info("Role found: {}", roleEntity);
return convertRoleEntityToRoleResponse(roleEntity);
}
public void deleteById(Long id) {
log.info("Deleting role with ID: {}", id);
roleRepository.findById(id)

View File

@@ -81,7 +81,7 @@ public class UserDao {
setIfUpdated(userEntity::getAddress, userEntity::setAddress, userReq.getAddress());
setIfUpdated(userEntity::getPhoneNumber, userEntity::setPhoneNumber, userReq.getPhoneNumber());
if (userReq.getRoleId() != null) {
RoleEntity roleEntity = roleService.getRoleById(userReq.getRoleId());
RoleEntity roleEntity = roleDao.validateRole(userReq.getRoleId());
setIfUpdated(userEntity::getRoleEntity, userEntity::setRoleEntity, roleEntity);
}
userEntity = userRepository.save(userEntity);
@@ -99,7 +99,7 @@ public class UserDao {
userEntity.setOrganization(userReq.getOrganization());
userEntity.setAddress(userReq.getAddress());
userEntity.setPhoneNumber(userReq.getPhoneNumber());
userEntity.setRoleEntity(roleService.getRoleById(userReq.getRoleId()));
userEntity.setRoleEntity(roleDao.validateRole(userReq.getRoleId()));
return userEntity;
}