Added column to communication table
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.gepafin.tendermanagement.dao;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
||||
@@ -9,6 +10,7 @@ import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse;
|
||||
import net.gepafin.tendermanagement.model.response.CommunicationResponseBean;
|
||||
import net.gepafin.tendermanagement.repositories.CommunicationRepository;
|
||||
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import org.slf4j.Logger;
|
||||
@@ -27,9 +29,12 @@ public class CommunicationDao {
|
||||
private CommunicationRepository communicationRepository;
|
||||
|
||||
@Autowired
|
||||
ApplicationAmendmentRequestService applicationAmendmentRequestService;
|
||||
private ApplicationAmendmentRequestService applicationAmendmentRequestService;
|
||||
|
||||
public CommunicationResponseBean addCommentToAmendmentRequest(CommunicationRequestBean communicationReq, Long amendmentId) {
|
||||
@Autowired
|
||||
private Validator validator;
|
||||
|
||||
public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationReq, Long amendmentId) {
|
||||
|
||||
log.info("Adding communication request...");
|
||||
CommunicationEntity communicationEntity = convertToCommunicationCommentEntity(communicationReq, amendmentId);
|
||||
@@ -85,18 +90,28 @@ public class CommunicationDao {
|
||||
response.setCreatedDate(entity.getCreatedDate());
|
||||
response.setUpdatedDate(entity.getUpdatedDate());
|
||||
response.setTitle(entity.getCommunicationTitle());
|
||||
response.setSenderUserId(entity.getSenderUserId());
|
||||
response.setReceiverUserId(entity.getReceiverUserId());
|
||||
return response;
|
||||
}
|
||||
|
||||
private CommunicationEntity convertToCommunicationCommentEntity(CommunicationRequestBean communicationReq, Long amendmentId) {
|
||||
|
||||
ApplicationAmendmentRequestEntity amendmentRequest = applicationAmendmentRequestService.validateApplicationAmendmentRequest(amendmentId);
|
||||
|
||||
CommunicationEntity communicationEntity = new CommunicationEntity();
|
||||
communicationEntity.setApplicationAmendmentRequest(amendmentRequest);
|
||||
communicationEntity.setCommunicationTitle(communicationReq.getTitle());
|
||||
communicationEntity.setCommunicationComment(communicationReq.getComment());
|
||||
communicationEntity.setIsDeleted(false);
|
||||
communicationEntity.setCommentedDate(LocalDateTime.now());
|
||||
if(validator.checkIsPreInstructor()){
|
||||
communicationEntity.setSenderUserId(amendmentRequest.getApplicationEvaluationEntity().getUserId());
|
||||
communicationEntity.setReceiverUserId(amendmentRequest.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||
} else if(validator.checkIsBeneficiary()) {
|
||||
communicationEntity.setSenderUserId(amendmentRequest.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||
communicationEntity.setReceiverUserId(amendmentRequest.getApplicationEvaluationEntity().getUserId());
|
||||
}
|
||||
return communicationEntity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,12 @@ public class CommunicationEntity extends BaseEntity {
|
||||
@Column(name = "COMMENTED_DATE")
|
||||
private LocalDateTime commentedDate;
|
||||
|
||||
@Column(name = "SENDER_USER_ID")
|
||||
private Long senderUserId;
|
||||
|
||||
@Column(name = "RECEIVER_USER_ID")
|
||||
private Long receiverUserId;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "AMENDMENT_ID", referencedColumnName = "id", nullable = false)
|
||||
private ApplicationAmendmentRequestEntity applicationAmendmentRequest;
|
||||
|
||||
@@ -16,6 +16,10 @@ public class CommunicationResponseBean {
|
||||
|
||||
private LocalDateTime updatedDate;
|
||||
|
||||
private Long senderUserId;
|
||||
|
||||
private Long receiverUserId;
|
||||
|
||||
private Long amendmentId;
|
||||
public CommunicationResponseBean(LocalDateTime commentedDate, String comment, String title, LocalDateTime createdDate, LocalDateTime updatedDate, Long amendmentId) {
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package net.gepafin.tendermanagement.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.model.request.CommunicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse;
|
||||
import net.gepafin.tendermanagement.model.response.CommunicationResponseBean;
|
||||
|
||||
public interface CommunicationService {
|
||||
CommunicationResponseBean addCommentToAmendmentRequest(CommunicationRequestBean communicationRequestBean, Long amendmentId);
|
||||
CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request ,CommunicationRequestBean communicationRequestBean, Long amendmentId);
|
||||
|
||||
String deleteComment(Long amendmentId, Long commentId);
|
||||
String deleteComment(HttpServletRequest request,Long amendmentId, Long commentId);
|
||||
|
||||
CommunicationResponseBean updateAmendmentComment(CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId);
|
||||
CommunicationResponseBean updateAmendmentComment(HttpServletRequest request,CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId);
|
||||
|
||||
ApplicationAmendmentResponse getAmendmentComments(Long id);
|
||||
ApplicationAmendmentResponse getAmendmentComments(HttpServletRequest request,Long id);
|
||||
}
|
||||
|
||||
@@ -1,43 +1,76 @@
|
||||
package net.gepafin.tendermanagement.service.impl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.dao.ApplicationAmendmentRequestDao;
|
||||
import net.gepafin.tendermanagement.dao.CommunicationDao;
|
||||
import net.gepafin.tendermanagement.entities.ApplicationAmendmentRequestEntity;
|
||||
import net.gepafin.tendermanagement.model.request.CommunicationRequestBean;
|
||||
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentResponse;
|
||||
import net.gepafin.tendermanagement.model.response.CommunicationResponseBean;
|
||||
import net.gepafin.tendermanagement.service.CommunicationService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
|
||||
@Service
|
||||
public class CommunicationServiceImpl implements CommunicationService {
|
||||
|
||||
@Autowired
|
||||
CommunicationDao communicationDao;
|
||||
|
||||
@Autowired
|
||||
ApplicationAmendmentRequestDao applicationAmendmentRequestDao;
|
||||
|
||||
@Autowired
|
||||
Validator validator;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CommunicationResponseBean addCommentToAmendmentRequest(CommunicationRequestBean communicationRequestBean, Long amendmentId) {
|
||||
|
||||
return communicationDao.addCommentToAmendmentRequest(communicationRequestBean, amendmentId);
|
||||
public CommunicationResponseBean addCommentToAmendmentRequest(HttpServletRequest request ,CommunicationRequestBean communicationRequestBean, Long amendmentId) {
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId);
|
||||
if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
|
||||
validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId());
|
||||
} else {
|
||||
validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||
}
|
||||
return communicationDao.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String deleteComment(Long amendmentId, Long commentId) {
|
||||
|
||||
public String deleteComment(HttpServletRequest request ,Long amendmentId, Long commentId) {
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId);
|
||||
if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
|
||||
validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId());
|
||||
} else {
|
||||
validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||
}
|
||||
return communicationDao.deleteComment(amendmentId, commentId);
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CommunicationResponseBean updateAmendmentComment(CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId) {
|
||||
|
||||
public CommunicationResponseBean updateAmendmentComment(HttpServletRequest request,CommunicationRequestBean communicationRequestBean, Long amendmentId, Long commentId) {
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(amendmentId);
|
||||
if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
|
||||
validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId());
|
||||
} else {
|
||||
validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||
}
|
||||
return communicationDao.updateAmendmentComment(communicationRequestBean, amendmentId, commentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public ApplicationAmendmentResponse getAmendmentComments(Long id) {
|
||||
|
||||
public ApplicationAmendmentResponse getAmendmentComments(HttpServletRequest request,Long id) {
|
||||
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = applicationAmendmentRequestDao.validateApplicationAmendmentRequest(id);
|
||||
if (Boolean.FALSE.equals(validator.checkIsBeneficiary())) {
|
||||
validator.validatePreInstructor(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getUserId());
|
||||
} else {
|
||||
validator.validateUserId(request, applicationAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication().getUserId());
|
||||
}
|
||||
return communicationDao.getAmendmentComments(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -32,6 +33,7 @@ public interface CommunicationApi {
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@PostMapping(value = "/{amendmentId}", produces = { "application/json" })
|
||||
@PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY')")
|
||||
ResponseEntity<Response<CommunicationResponseBean>> addCommentToAmendmentRequest(HttpServletRequest request,
|
||||
@RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId);
|
||||
|
||||
@@ -43,7 +45,7 @@ public interface CommunicationApi {
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value =
|
||||
ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) })
|
||||
@GetMapping(value = "/{amendmentId}", produces = "application/json")
|
||||
public ResponseEntity<Response<ApplicationAmendmentResponse>> getAmendmentComments(@PathVariable(value = "amendmentId") Long amendmentId);
|
||||
public ResponseEntity<Response<ApplicationAmendmentResponse>> getAmendmentComments(HttpServletRequest request,@PathVariable(value = "amendmentId") Long amendmentId);
|
||||
|
||||
@Operation(summary = "Api to update communication comments", responses = { @ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@@ -53,6 +55,7 @@ public interface CommunicationApi {
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) })
|
||||
@PutMapping(value = "/{amendmentId}/{commentId}", produces = { "application/json" })
|
||||
@PreAuthorize("hasRole('ROLE_PRE_INSTRUCTOR') || hasRole('ROLE_BENEFICIARY')")
|
||||
ResponseEntity<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request,
|
||||
@RequestBody @Parameter CommunicationRequestBean communicationResponseBean, @PathVariable(value = "amendmentId") Long amendmentId, @PathVariable(value = "commentId") Long commentId);
|
||||
|
||||
|
||||
@@ -27,28 +27,28 @@ public class CommunicationController implements CommunicationApi {
|
||||
public ResponseEntity<Response<CommunicationResponseBean>> addCommentToAmendmentRequest(HttpServletRequest request, CommunicationRequestBean communicationRequestBean,
|
||||
Long amendmentId) {
|
||||
|
||||
CommunicationResponseBean communicationResponseBean = communicationService.addCommentToAmendmentRequest(communicationRequestBean, amendmentId);
|
||||
CommunicationResponseBean communicationResponseBean = communicationService.addCommentToAmendmentRequest(request,communicationRequestBean, amendmentId);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMUNICATION_ADDED_TO_AMENDMENT_REQUEST_SUCCESS)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<ApplicationAmendmentResponse>> getAmendmentComments(Long amendmentId) {
|
||||
public ResponseEntity<Response<ApplicationAmendmentResponse>> getAmendmentComments(HttpServletRequest request,Long amendmentId) {
|
||||
|
||||
ApplicationAmendmentResponse response = communicationService.getAmendmentComments(amendmentId);
|
||||
ApplicationAmendmentResponse response = communicationService.getAmendmentComments(request,amendmentId);
|
||||
return ResponseEntity.ok(new Response<>(response, Status.SUCCESS, Translator.toLocale(GepafinConstant.AMENDMENT_FOUND_SUCCESS)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<CommunicationResponseBean>> updateCommunicationAmendment(HttpServletRequest request, CommunicationRequestBean communicationRequestBean,
|
||||
Long amendmentId, Long commentId) {
|
||||
|
||||
CommunicationResponseBean communicationResponseBean = communicationService.updateAmendmentComment(communicationRequestBean, amendmentId, commentId);
|
||||
CommunicationResponseBean communicationResponseBean = communicationService.updateAmendmentComment(request,communicationRequestBean, amendmentId, commentId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_UPDATED_SUCCESS_MSG)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<String>> deleteApplicationAmendmentComment(HttpServletRequest request, Long applicationAmendId, Long commentId) {
|
||||
|
||||
String communicationResponseBean = communicationService.deleteComment(applicationAmendId, commentId);
|
||||
String communicationResponseBean = communicationService.deleteComment(request,applicationAmendId, commentId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(communicationResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMMENT_DELETED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user