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

View File

@@ -0,0 +1,57 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import net.gepafin.tendermanagement.enums.CallTypeEnum;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class CallDetailsResponseBean {
private Long id;
private String name;
private String descriptionShort;
private String descriptionLong;
private List<LocalDateTime> dates;
private CallTypeEnum status;
private Long regionId;
private BigDecimal amount;
private BigDecimal amountMax;
private String contactInfo;
private String submissionMethod;
private Long threshold;
private String priorityArea;
private String documentationReqested;
private LocalDateTime createdDate;
private LocalDateTime updatedDate;
private List<LookUpDataResponse> aimedTo;
private List<EvaluationCriteriaResponseBean> criteria;
private List<DocumentResponseBean> docs;
private List<FaqResponseBean> faq;
private List<DocumentResponseBean> images;
private List<LookUpDataResponse> checkList;
private String currentStep;
}

View File

@@ -6,6 +6,7 @@ import net.gepafin.tendermanagement.entities.RoleEntity;
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.CreateCallResponseBean;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
@@ -19,8 +20,8 @@ public interface CallService {
CreateCallResponseBean updateCallStep1(HttpServletRequest request, Long callId, UpdateCallRequestStep1 updateCallRequest);
CallEntity getCallById (Long callId);
CreateCallResponseBean getCallById (Long callId);
List<CreateCallResponseBean> getAllCalls();
List<CallDetailsResponseBean> getAllCalls();
}

View File

@@ -14,7 +14,7 @@ public interface RegionService {
RegionResponseBean updateRegion(Long regionId, RegionReq regionReq);
RegionEntity getRegionById(Long regionId);
RegionResponseBean getRegionById(Long regionId);
void deleteRegion(Long regionId);

View File

@@ -11,7 +11,7 @@ public interface RoleService {
RoleResponseBean updateRole(Long roleId, RoleReq roleReq);
RoleEntity getRoleById(Long roleId);
RoleResponseBean getRoleById(Long roleId);
void deleteRole(Long roleId);

View File

@@ -8,6 +8,7 @@ import net.gepafin.tendermanagement.entities.RoleEntity;
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.CreateCallResponseBean;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.service.CallService;
@@ -47,10 +48,10 @@ public class CallServiceImpl implements CallService {
return callDao.updateCallStep1(callId, updateCallRequest, Long.parseLong(userInfo.get("userId").toString()));
}
@Override
public CallEntity getCallById(Long callId) {
public CreateCallResponseBean getCallById(Long callId) {
return callDao.getCallById(callId);
}
public List<CreateCallResponseBean> getAllCalls() {
public List<CallDetailsResponseBean> getAllCalls() {
return callDao.getAllCalls();
}

View File

@@ -32,7 +32,7 @@ public class RegionServiceImpl implements RegionService {
@Override
@Transactional(readOnly = true)
public RegionEntity getRegionById(Long regionId) {
public RegionResponseBean getRegionById(Long regionId) {
return regionDao.getRegionById(regionId);
}

View File

@@ -31,7 +31,7 @@ public class RoleServiceImpl implements RoleService {
@Override
@Transactional(readOnly = true)
public RoleEntity getRoleById(Long roleId) {
public RoleResponseBean getRoleById(Long roleId) {
return roleDao.getRoleById(roleId);
}

View File

@@ -12,6 +12,7 @@ import net.gepafin.tendermanagement.entities.RoleEntity;
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.CreateCallResponseBean;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
@@ -85,7 +86,7 @@ public interface CallApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/{callId}",
produces = { "application/json" })
ResponseEntity<Response<CallEntity>> getCallById(
ResponseEntity<Response<CreateCallResponseBean>> getCallById(
@Parameter(description = "The call ID", required = true) @PathVariable("callId") Long callId);
@Operation(summary = "Api to get all calls",
responses = {
@@ -98,6 +99,6 @@ public interface CallApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "",
produces = { "application/json" })
ResponseEntity<Response<List<CreateCallResponseBean>>> getAllCalls();
ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls();
}

View File

@@ -61,7 +61,7 @@ public interface RegionApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/{regionId}", produces = "application/json")
ResponseEntity<Response<RegionEntity>> getRegionById(
ResponseEntity<Response<RegionResponseBean>> getRegionById(
@Parameter(description = "The region id", required = true) @PathVariable("regionId") Long regionId);
@Operation(summary = "Api to get all regions",

View File

@@ -62,7 +62,7 @@ public interface RoleApi {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
@GetMapping(value = "/{roleId}",
produces = { "application/json" })
ResponseEntity<Response<RoleEntity>> getRoleById(
ResponseEntity<Response<RoleResponseBean>> getRoleById(
@Parameter(description = "The role ID", required = true) @PathVariable("roleId") Long roleId);
@Operation(summary = "Api to get all roles",

View File

@@ -8,6 +8,7 @@ import net.gepafin.tendermanagement.entities.RoleEntity;
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.CreateCallResponseBean;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
@@ -57,16 +58,16 @@ public class CallApiController implements CallApi {
}
@Override
@Transactional(readOnly = true)
public ResponseEntity<Response<CallEntity>> getCallById(Long callId) {
CallEntity callEntity = callService.getCallById(callId);
public ResponseEntity<Response<CreateCallResponseBean>> getCallById(Long callId) {
CreateCallResponseBean createCallResponseBean = callService.getCallById(callId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(callEntity, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG)));
.body(new Response<>(createCallResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG)));
}
@Override
@Transactional(readOnly = true)
public ResponseEntity<Response<List<CreateCallResponseBean>>> getAllCalls() {
List<CreateCallResponseBean> calls = callService.getAllCalls();
public ResponseEntity<Response<List<CallDetailsResponseBean>>> getAllCalls() {
List<CallDetailsResponseBean> calls = callService.getAllCalls();
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(calls, Status.SUCCESS, Translator.toLocale(GepafinConstant.CALL_FETCH_SUCCESS_MSG)));

View File

@@ -52,10 +52,10 @@ public class RegionApiController implements RegionApi {
}
@Override
public ResponseEntity<Response<RegionEntity>> getRegionById(
public ResponseEntity<Response<RegionResponseBean>> getRegionById(
@PathVariable("regionId") Long regionId) {
log.info("Get Region by ID - Region ID: {}", regionId);
RegionEntity region = regionService.getRegionById(regionId);
RegionResponseBean region = regionService.getRegionById(regionId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(region, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_REGION_SUCCESS_MSG)));
}

View File

@@ -57,11 +57,11 @@ public class RoleApiController implements RoleApi {
}
@Override
public ResponseEntity<Response<RoleEntity>> getRoleById(Long roleId) {
public ResponseEntity<Response<RoleResponseBean>> getRoleById(Long roleId) {
log.info("Get Role by ID - Role ID: {}", roleId);
RoleEntity roleEntity = roleService.getRoleById(roleId);
RoleResponseBean roleResponseBean = roleService.getRoleById(roleId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(roleEntity, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_FETCH_SUCCESS_MSG)));
.body(new Response<>(roleResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.ROLE_FETCH_SUCCESS_MSG)));
}
@Override