This commit is contained in:
@@ -22,6 +22,8 @@ public enum MessageCode {
|
||||
LAW_CASE_NOT_FOUND(4, "Law case not found"),
|
||||
PERMISSION_NOT_FOUND(2, "Permission not found"),
|
||||
USER_NOT_FOUND(2, "User not found"),
|
||||
LAW_CASE_ALREADY_EXIST(2, "Law case already exists"),
|
||||
COMPLAINT_ALREADY_EXIST(2, "Complaint already exists"),
|
||||
FILE_DOWNLOAD_ERROR_NOT_CORRECT_FIELD(2, "Not correct field"),
|
||||
TOKEN_IS_NULL(2, "Token field is null"),
|
||||
IMAGE_FOUND_ERROR(2, "Image found error"),
|
||||
|
||||
@@ -90,14 +90,20 @@ public class ComplaintEntityHandler implements RequestHandler {
|
||||
"violation_id is required");
|
||||
if (req.getComplaintText() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(),
|
||||
"text is required");
|
||||
Long violationId = req.getViolationId();
|
||||
|
||||
Violation violation = violationRepository.findById(req.getViolationId()).orElse(null);
|
||||
Violation violation = violationRepository.findById(violationId).orElse(null);
|
||||
|
||||
if (violation == null || !Objects.equals(violation.getFileEntity().getUserId(), userId)) {
|
||||
return errorResponse(msgId, MessageCode.USER_NOT_HAD_PERMISSION.getCode(),
|
||||
MessageCode.USER_NOT_HAD_PERMISSION.getDescription());
|
||||
}
|
||||
|
||||
if (violationRepository.existsViolation(violationId)) {
|
||||
return errorResponse(msgId, MessageCode.COMPLAINT_ALREADY_EXIST.getCode(),
|
||||
MessageCode.COMPLAINT_ALREADY_EXIST.getDescription());
|
||||
}
|
||||
|
||||
ComplaintResponse response = complaintService.createComplaint(req);
|
||||
|
||||
return successResponse(msgId, "Complaint created successfully", response);
|
||||
|
||||
@@ -162,6 +162,12 @@ public class LawCaseHandler implements RequestHandler {
|
||||
|
||||
private BaseResponse createLawCase(Long userId, LawCaseRequest lawCaseRequest, BaseRequest request) {
|
||||
validateRequiredParameters(lawCaseRequest, request, userId);
|
||||
Long violationId = lawCaseRequest.getViolationId();
|
||||
|
||||
if (lawCaseService.lawCaseExistByViolationId(violationId)) {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.LAW_CASE_ALREADY_EXIST.getCode(),
|
||||
MessageCode.LAW_CASE_ALREADY_EXIST.getDescription(), "Law case was already exists");
|
||||
}
|
||||
|
||||
try {
|
||||
tariffInfoService.writeOffTokens(userId, TariffConstants.LEGAL_COST, OperationType.CREATE_LEGAL_CASE);
|
||||
@@ -175,7 +181,6 @@ public class LawCaseHandler implements RequestHandler {
|
||||
}
|
||||
|
||||
User user = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("User not found"));
|
||||
Long violationId = lawCaseRequest.getViolationId();
|
||||
|
||||
LawCase lawCase = lawCaseService.addLawCase(
|
||||
lawCaseRequest.getAmount(),
|
||||
|
||||
@@ -55,4 +55,6 @@ public interface LawCaseRepository extends JpaRepository<LawCase, Long> {
|
||||
|
||||
|
||||
Optional<LawCase> getLawCaseByViolationIdAndType(Long violationId, LawCaseType type);
|
||||
|
||||
boolean existsByViolationId(Long violationId);
|
||||
}
|
||||
|
||||
@@ -95,4 +95,6 @@ public interface ViolationRepository extends JpaRepository<Violation, Long> {
|
||||
|
||||
@Query("SELECT COUNT(DISTINCT c.violation.id) FROM ComplaintEntity c WHERE c.violation IS NOT NULL")
|
||||
Long getViolationsWithComplaintCount();
|
||||
|
||||
boolean existsViolation(Long violationId);
|
||||
}
|
||||
@@ -51,6 +51,10 @@ public class LawCaseService {
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public boolean lawCaseExistByViolationId(Long violationId) {
|
||||
return lawCaseRepository.existsByViolationId(violationId);
|
||||
}
|
||||
|
||||
public LawCase changePriority(Long id, LawCasePriority priority) {
|
||||
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
||||
if (lawCase == null) {
|
||||
|
||||
Reference in New Issue
Block a user