Updated code

This commit is contained in:
rajesh
2024-11-23 20:02:47 +05:30
parent 972e205e94
commit 5581146888
3 changed files with 38 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ public class FaqDao {
CallEntity callEntity = callService.validateCall(callId); CallEntity callEntity = callService.validateCall(callId);
FaqEntity entity = createOrUpdateFaqEntity(faqRequest, callEntity, userEntity, FaqEntity entity = createOrUpdateFaqEntity(faqRequest, callEntity, userEntity,
LookUpDataTypeEnum.FAQ); LookUpDataTypeEnum.FAQ);
FaqEntity oldFaqEntity = Utils.getClonedEntityForData(entity);
if (validator.checkIsBeneficiary() && companyId == null) { if (validator.checkIsBeneficiary() && companyId == null) {
throw new CustomValidationException(Status.VALIDATION_ERROR, throw new CustomValidationException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.COMPANY_ID_MANDATORY)); Translator.toLocale(GepafinConstant.COMPANY_ID_MANDATORY));
@@ -68,6 +69,10 @@ public class FaqDao {
entity.setCompanyId(companyId); entity.setCompanyId(companyId);
} }
faqRepository.save(entity); faqRepository.save(entity);
if(entity.getCompanyId()!=null) {
/** This code is responsible for adding a version history log for the "Create FAQ" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldFaqEntity).newData(entity).build());
}
return convertToFaqResponseBean(entity); return convertToFaqResponseBean(entity);
} }
@@ -84,8 +89,11 @@ public class FaqDao {
public void deleteFaq(Long id) { public void deleteFaq(Long id) {
FaqEntity faqEntity = validateFaq(id); FaqEntity faqEntity = validateFaq(id);
FaqEntity oldFaqEntity = Utils.getClonedEntityForData(faqEntity);
faqEntity.setIsDeleted(Boolean.TRUE); faqEntity.setIsDeleted(Boolean.TRUE);
faqRepository.save(faqEntity); faqRepository.save(faqEntity);
/** This code is responsible for adding a version history log for the "soft delete faq" operation **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.SOFT_DELETE).oldData(oldFaqEntity).newData(faqEntity).build());
} }
public FaqEntity validateFaq(Long id) { public FaqEntity validateFaq(Long id) {

View File

@@ -22,7 +22,15 @@ public enum UserActionContextEnum {
DELETE_USER("DELETE_USER"), DELETE_USER("DELETE_USER"),
VALIDATE_NEW_USER_WITH_SPID_TOKEN("VALIDATE_NEW_USER_WITH_SPID_TOKEN"), VALIDATE_NEW_USER_WITH_SPID_TOKEN("VALIDATE_NEW_USER_WITH_SPID_TOKEN"),
VALIDATE_EXISTING_USER_WITH_SPID_TOKEN("VALIDATE_EXISTING_USER_WITH_SPID_TOKEN"), VALIDATE_EXISTING_USER_WITH_SPID_TOKEN("VALIDATE_EXISTING_USER_WITH_SPID_TOKEN"),
GET_VALID_USER_DETAILS("GET_VALID_USER_DETAILS"); GET_VALID_USER_DETAILS("GET_VALID_USER_DETAILS"),
/** FAQ action context **/
CREATE_FAQ("CREATE_FAQ"),
GET_FAQ("GET_FAQ"),
UPDATE_FAQ_DETAILS("UPDATE_FAQ_DETAILS"),
DELETE_FAQ("DELETE_FAQ")
;
private final String value; private final String value;

View File

@@ -2,10 +2,14 @@ package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.FaqReq; import net.gepafin.tendermanagement.model.request.FaqReq;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.response.FaqResponseBean; import net.gepafin.tendermanagement.model.response.FaqResponseBean;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.FaqService; import net.gepafin.tendermanagement.service.FaqService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.web.rest.api.FaqApi; import net.gepafin.tendermanagement.web.rest.api.FaqApi;
import net.gepafin.tendermanagement.web.rest.api.errors.Status; import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -20,9 +24,14 @@ public class FaqApiController implements FaqApi {
@Autowired @Autowired
private FaqService faqService; private FaqService faqService;
@Autowired
private LoggingUtil loggingUtil;
@Override @Override
public ResponseEntity<Response<FaqResponseBean>> createFaq(HttpServletRequest request, Long callId, Long companyId, FaqReq faqRequest) { public ResponseEntity<Response<FaqResponseBean>> createFaq(HttpServletRequest request, Long callId, Long companyId, FaqReq faqRequest) {
/** This code is responsible for creating user action logs for the "Create FAQ" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT)
.actionContext(UserActionContextEnum.CREATE_FAQ).build());
FaqResponseBean response = faqService.createFaq(request,callId, companyId, faqRequest); FaqResponseBean response = faqService.createFaq(request,callId, companyId, faqRequest);
return ResponseEntity.status(HttpStatus.CREATED) return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.FAQ_CREATED_SUCCESSFULLY))); .body(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.FAQ_CREATED_SUCCESSFULLY)));
@@ -30,6 +39,11 @@ public class FaqApiController implements FaqApi {
@Override @Override
public ResponseEntity<Response<FaqResponseBean>> getFaqById(HttpServletRequest request, Long id) { public ResponseEntity<Response<FaqResponseBean>> getFaqById(HttpServletRequest request, Long id) {
/** This code is responsible for creating user action logs for the "get FAQ by id" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW)
.actionContext(UserActionContextEnum.GET_FAQ).build());
FaqResponseBean response = faqService.getFaqById(request, id); FaqResponseBean response = faqService.getFaqById(request, id);
if (response != null) { if (response != null) {
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
@@ -42,6 +56,10 @@ public class FaqApiController implements FaqApi {
@Override @Override
public ResponseEntity<Response<FaqResponseBean>> updateFaq(HttpServletRequest request, Long id, FaqReq faqRequest) { public ResponseEntity<Response<FaqResponseBean>> updateFaq(HttpServletRequest request, Long id, FaqReq faqRequest) {
/** This code is responsible for "Updating FAQ details" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.UPDATE_FAQ_DETAILS).build());
FaqResponseBean response = faqService.updateFaq(request, id, faqRequest); FaqResponseBean response = faqService.updateFaq(request, id, faqRequest);
if (response != null) { if (response != null) {
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
@@ -54,6 +72,9 @@ public class FaqApiController implements FaqApi {
@Override @Override
public ResponseEntity<Response<Void>> deleteFaq(HttpServletRequest request, Long id) { public ResponseEntity<Response<Void>> deleteFaq(HttpServletRequest request, Long id) {
/** This code is responsible for creating user action logs for the "Delete FAQ" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.DELETE_FAQ).build());
faqService.deleteFaq(request, id); faqService.deleteFaq(request, id);
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.FAQ_DELETED_SUCCESSFULLY))); .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.FAQ_DELETED_SUCCESSFULLY)));