dev check violation for lawcase,complaint
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-05-18 13:25:53 +07:00
parent 57a39d0cb0
commit 0e0fac02a8
6 changed files with 23 additions and 2 deletions
@@ -22,6 +22,8 @@ public enum MessageCode {
LAW_CASE_NOT_FOUND(4, "Law case not found"), LAW_CASE_NOT_FOUND(4, "Law case not found"),
PERMISSION_NOT_FOUND(2, "Permission not found"), PERMISSION_NOT_FOUND(2, "Permission not found"),
USER_NOT_FOUND(2, "User 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"), FILE_DOWNLOAD_ERROR_NOT_CORRECT_FIELD(2, "Not correct field"),
TOKEN_IS_NULL(2, "Token field is null"), TOKEN_IS_NULL(2, "Token field is null"),
IMAGE_FOUND_ERROR(2, "Image found error"), IMAGE_FOUND_ERROR(2, "Image found error"),
@@ -90,14 +90,20 @@ public class ComplaintEntityHandler implements RequestHandler {
"violation_id is required"); "violation_id is required");
if (req.getComplaintText() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(), if (req.getComplaintText() == null) return errorResponse(msgId, MessageCode.NOT_FOUND.getCode(),
"text is required"); "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)) { if (violation == null || !Objects.equals(violation.getFileEntity().getUserId(), userId)) {
return errorResponse(msgId, MessageCode.USER_NOT_HAD_PERMISSION.getCode(), return errorResponse(msgId, MessageCode.USER_NOT_HAD_PERMISSION.getCode(),
MessageCode.USER_NOT_HAD_PERMISSION.getDescription()); 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); ComplaintResponse response = complaintService.createComplaint(req);
return successResponse(msgId, "Complaint created successfully", response); 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) { private BaseResponse createLawCase(Long userId, LawCaseRequest lawCaseRequest, BaseRequest request) {
validateRequiredParameters(lawCaseRequest, request, userId); 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 { try {
tariffInfoService.writeOffTokens(userId, TariffConstants.LEGAL_COST, OperationType.CREATE_LEGAL_CASE); 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")); User user = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("User not found"));
Long violationId = lawCaseRequest.getViolationId();
LawCase lawCase = lawCaseService.addLawCase( LawCase lawCase = lawCaseService.addLawCase(
lawCaseRequest.getAmount(), lawCaseRequest.getAmount(),
@@ -55,4 +55,6 @@ public interface LawCaseRepository extends JpaRepository<LawCase, Long> {
Optional<LawCase> getLawCaseByViolationIdAndType(Long violationId, LawCaseType type); 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") @Query("SELECT COUNT(DISTINCT c.violation.id) FROM ComplaintEntity c WHERE c.violation IS NOT NULL")
Long getViolationsWithComplaintCount(); Long getViolationsWithComplaintCount();
boolean existsViolation(Long violationId);
} }
@@ -51,6 +51,10 @@ public class LawCaseService {
return lawCaseRepository.save(lawCase); return lawCaseRepository.save(lawCase);
} }
public boolean lawCaseExistByViolationId(Long violationId) {
return lawCaseRepository.existsByViolationId(violationId);
}
public LawCase changePriority(Long id, LawCasePriority priority) { public LawCase changePriority(Long id, LawCasePriority priority) {
LawCase lawCase = lawCaseRepository.findById(id).orElse(null); LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
if (lawCase == null) { if (lawCase == null) {