updated code for faq update api

This commit is contained in:
rajesh
2024-08-29 20:57:52 +05:30
parent 6318153300
commit 4ac0d31e43
2 changed files with 17 additions and 11 deletions

View File

@@ -148,7 +148,7 @@ public class CallDao {
CallEntity callEntity, LookUpDataTypeEnum type) { CallEntity callEntity, LookUpDataTypeEnum type) {
EvaluationCriteriaEntity criteriaEntity = null; EvaluationCriteriaEntity criteriaEntity = null;
LookUpDataEntity lookupDataEntity = convertLookUpDataRequestIntoLookUpDataEntity(criteriaReq, type); LookUpDataEntity lookupDataEntity = convertLookUpDataRequestIntoLookUpDataEntity(criteriaReq, type);
if (criteriaReq.getId() == null && criteriaReq.getId().equals(0l)) { if (criteriaReq.getId() != null && criteriaReq.getId() > 0) {
criteriaEntity = evaluationCriteriaRepository.findById(criteriaReq.getId()) criteriaEntity = evaluationCriteriaRepository.findById(criteriaReq.getId())
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR, .orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.EVALUATION_CRITERIA_NOT_FOUND))); Translator.toLocale(GepafinConstant.EVALUATION_CRITERIA_NOT_FOUND)));
@@ -224,7 +224,7 @@ public class CallDao {
LookUpDataEntity lookupDataEntity = convertLookUpDataRequestIntoLookUpDataEntity(faqReq, type); LookUpDataEntity lookupDataEntity = convertLookUpDataRequestIntoLookUpDataEntity(faqReq, type);
validateFaqEntity(faqReq.getQuestion()); validateFaqEntity(faqReq.getQuestion());
faqEntity.setUser(userEntity); faqEntity.setUser(userEntity);
faqEntity.setIsVisible(true); faqEntity.setIsVisible(false);
faqEntity.setLookupData(lookupDataEntity); faqEntity.setLookupData(lookupDataEntity);
if (faqReq.getIsVisible() != null) { if (faqReq.getIsVisible() != null) {
faqEntity.setIsVisible(faqReq.getIsVisible()); faqEntity.setIsVisible(faqReq.getIsVisible());
@@ -249,7 +249,7 @@ public class CallDao {
} }
public void validateDocumentEntity(Long documentId) { public void validateDocumentEntity(Long documentId) {
if (documentId == null) { if (documentId == null || documentId < 1) {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.DOCUMENT_ID_NOT_FOUND)); Translator.toLocale(GepafinConstant.DOCUMENT_ID_NOT_FOUND));
} }
@@ -528,13 +528,13 @@ public class CallDao {
updateCallRequest.getDocumentationRequested()); updateCallRequest.getDocumentationRequested());
setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi()); setIfUpdated(callEntity::getConfidi, callEntity::setConfidi, updateCallRequest.getConfidi());
updateLookUpData(callEntity, updateCallRequest.getAimedTo(), LookUpDataTypeEnum.AIMED_TO); updateLookUpData(callEntity, updateCallRequest.getAimedTo(), LookUpDataTypeEnum.AIMED_TO);
updateFaq(callEntity, updateCallRequest.getFaq(), userEntity); updateFaq(callEntity, updateCallRequest.getFaq(), userEntity, LookUpDataTypeEnum.FAQ);
CallResponse createCallResponseBean = getCallResponseBean(callEntity); CallResponse createCallResponseBean = getCallResponseBean(callEntity);
createCallResponseBean.setCurrentStep(GepafinConstant.STEP_1); createCallResponseBean.setCurrentStep(GepafinConstant.STEP_1);
return createCallResponseBean; return createCallResponseBean;
} }
private void updateFaq(CallEntity callEntity, List<FaqReq> faqReqList, UserEntity userEntity) { private void updateFaq(CallEntity callEntity, List<FaqReq> faqReqList, UserEntity userEntity, LookUpDataTypeEnum type) {
if (faqReqList == null) { if (faqReqList == null) {
return; return;
} }
@@ -542,7 +542,7 @@ public class CallDao {
List<Long> incomingIds = faqReqList.stream().map(FaqReq::getId).filter(Objects::nonNull).filter(id -> id > 0) List<Long> incomingIds = faqReqList.stream().map(FaqReq::getId).filter(Objects::nonNull).filter(id -> id > 0)
.collect(Collectors.toList()); .collect(Collectors.toList());
existingFaqs.stream().filter(faq -> !incomingIds.contains(faq.getId())).forEach(this::softDeleteFaq); existingFaqs.stream().filter(faq -> !incomingIds.contains(faq.getId())).forEach(this::softDeleteFaq);
faqReqList.forEach(faqReq -> createOrUpdateFaq(faqReq, callEntity, userEntity)); faqReqList.forEach(faqReq -> createOrUpdateFaq(faqReq, callEntity, userEntity, type));
} }
@@ -551,8 +551,10 @@ public class CallDao {
faqRepository.save(faqEntity); faqRepository.save(faqEntity);
} }
private void createOrUpdateFaq(FaqReq faqReq, CallEntity callEntity, UserEntity userEntity) { private void createOrUpdateFaq(FaqReq faqReq, CallEntity callEntity, UserEntity userEntity, LookUpDataTypeEnum type) {
FaqEntity faqEntity = null; FaqEntity faqEntity = null;
LookUpDataEntity lookupDataEntity = convertLookUpDataRequestIntoLookUpDataEntity(faqReq, type);
if (isExistingFaq(faqReq)) { if (isExistingFaq(faqReq)) {
faqEntity = faqRepository.findById(faqReq.getId()) faqEntity = faqRepository.findById(faqReq.getId())
@@ -562,10 +564,14 @@ public class CallDao {
faqEntity = new FaqEntity(); faqEntity = new FaqEntity();
faqEntity.setCall(callEntity); faqEntity.setCall(callEntity);
faqEntity.setUser(userEntity); faqEntity.setUser(userEntity);
faqEntity.setLookupData(lookupDataEntity);
faqEntity.setIsVisible(false); faqEntity.setIsVisible(false);
faqEntity.setIsDeleted(false); faqEntity.setIsDeleted(false);
} }
if (Boolean.FALSE.equals(faqEntity.getLookupData().getId().equals(lookupDataEntity.getId()))) {
faqEntity.setLookupData(lookupDataEntity);
}
setIfUpdated(faqEntity::getQuestionShort, faqEntity::setQuestionShort, faqReq.getQuestionShort()); setIfUpdated(faqEntity::getQuestionShort, faqEntity::setQuestionShort, faqReq.getQuestionShort());
setIfUpdated(faqEntity::getQuestion, faqEntity::setQuestion, faqReq.getQuestion()); setIfUpdated(faqEntity::getQuestion, faqEntity::setQuestion, faqReq.getQuestion());
setIfUpdated(faqEntity::getResponseShort, faqEntity::setResponseShort, faqReq.getResponseShort()); setIfUpdated(faqEntity::getResponseShort, faqEntity::setResponseShort, faqReq.getResponseShort());

View File

@@ -30,7 +30,7 @@ public interface DocumentApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))}) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))})
@PostMapping(value = "/uploadFile/call/{callId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/uploadFile/call/{callId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
default ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, @Parameter(description = "call id", required = true) @PathVariable Long callId, @RequestParam("file") List<MultipartFile> files, @RequestParam("documentType") DocumentTypeEnum documentTypeEnum) { default ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, @Parameter(description = "call id", required = true) @PathVariable("callId") Long callId, @RequestParam("file") List<MultipartFile> files, @RequestParam("documentType") DocumentTypeEnum documentTypeEnum) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} }
@@ -59,7 +59,7 @@ public interface DocumentApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))}) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))})
@PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
default ResponseEntity<Response<DocumentResponseBean>> updateDocument(HttpServletRequest httpServletRequest, @Parameter(description = "document id", required = true) @PathVariable Long documentId, @RequestParam("file") MultipartFile file, @RequestParam("documentType") DocumentTypeEnum documentTypeEnum) { default ResponseEntity<Response<DocumentResponseBean>> updateDocument(HttpServletRequest httpServletRequest, @Parameter(description = "document id", required = true) @PathVariable("id") Long documentId, @RequestParam("file") MultipartFile file, @RequestParam("documentType") DocumentTypeEnum documentTypeEnum) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} }
@Operation(summary = "API to get document by id", @Operation(summary = "API to get document by id",
@@ -73,6 +73,6 @@ public interface DocumentApi {
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Response<DocumentResponseBean>> getDocumentById(HttpServletRequest request, ResponseEntity<Response<DocumentResponseBean>> getDocumentById(HttpServletRequest request,
@Parameter(description = "document id", required = true) @Parameter(description = "document id", required = true)
@PathVariable Long id); @PathVariable("id") Long id);
} }