dev add reason entity
Test Workflow / test (push) Successful in 3s

This commit is contained in:
vladp
2026-03-27 17:31:06 +07:00
parent 964910ec69
commit 9a8a4a72f4
3 changed files with 24 additions and 15 deletions
@@ -2,6 +2,7 @@ package ru.soune.nocopy.dto;
public enum MessageCode {
SUCCESS(0, "Operation successful"),
SUCCESS_MODERATION(0, "File moderated successfully"),
REG_EMAIL_EXISTS(1, "Email already registered"),
REG_EMAIL_OR_PHONE_EXISTS(1, "Email or phone already registered"),
REFERRAL_LINK_IS_NOT_EXIST(1, "Refferal link is not exist"),
@@ -52,6 +53,7 @@ public enum MessageCode {
MONITORING_TYPE_NOT_FOUND(4, "Monitoring type not found"),
ERROR_TARIFF_INFO(2, "Erorr with tariff info"),
FILE_FOR_SEARCH_NOT_VALID(2, "File for search unsupported"),
ILLEGAL_STATE(2, "File is not in moderation state"),
NOT_VALID_FILE_TYPE_OR_COUNT_FILE(2, "Cost for file type not found, count is negative or files count" +
"more than max valid"),
USER_NOT_ACTIVE(2, "User not active"),
@@ -219,19 +219,21 @@ public class FileEntityHandler implements RequestHandler {
private BaseResponse handleChangeStatus(BaseRequest request, FileEntityRequest fileRequest) {
FileStatus newStatus = fileRequest.getFileStatus();
String fileId = fileRequest.getFileId();
try {
fileEntityService.changeFileStatus(newStatus ,fileRequest.getFileId());
} catch (FileEntityNotFoundException e) {
return new BaseResponse(request.getMsgId(),
MessageCode.FILE_NOT_FOUND.getCode(),
MessageCode.FILE_NOT_FOUND.getDescription(),
null);
FileEntityResponse.builder().id(fileId));
}
return new BaseResponse(request.getMsgId(),
MessageCode.SUCCESS.getCode(),
MessageCode.SUCCESS.getDescription(),
Map.of("new_status", newStatus));
FileEntityResponse.builder().status(newStatus));
}
private BaseResponse handleSearchFiles(BaseRequest request, FileEntityRequest fileRequest) {
@@ -635,21 +637,27 @@ public class FileEntityHandler implements RequestHandler {
moderationService.moderateFile(moderationRequest, 0L);
return new BaseResponse(request.getMsgId(),
MessageCode.SUCCESS.getCode(),
"File moderated successfully",
null);
MessageCode.SUCCESS_MODERATION.getCode(),
MessageCode.SUCCESS_MODERATION.getDescription(),
FileEntityResponse.builder().id(fileRequest.getFileId()));
} catch (SecurityException e) {
return new BaseResponse(request.getMsgId(),
MessageCode.ACCESS_DENIED.getCode(),
e.getMessage(),
null);
} catch (Exception e) {
log.error("Error moderating file", e);
MessageCode.ACCESS_DENIED.getDescription(),
FileEntityResponse.builder().id(fileRequest.getFileId()));
} catch (FileEntityNotFoundException e) {
return new BaseResponse(request.getMsgId(),
MessageCode.INVALID_FIELD.getCode(),
"Failed to moderate file: " + e.getMessage(),
null);
MessageCode.FILE_NOT_FOUND.getCode(),
MessageCode.FILE_NOT_FOUND.getDescription(),
FileEntityResponse.builder()
.id(fileRequest.getFileId()));
} catch (IllegalStateException e) {
return new BaseResponse(request.getMsgId(),
MessageCode.ILLEGAL_STATE.getCode(),
MessageCode.ILLEGAL_STATE.getDescription(),
FileEntityResponse.builder()
.status(fileRequest.getFileStatus()));
}
}
@@ -669,14 +677,12 @@ public class FileEntityHandler implements RequestHandler {
MessageCode.SUCCESS.getCode(),
"Appeal submitted successfully",
response);
} catch (InvalidAppealException e) {
return new BaseResponse(request.getMsgId(),
MessageCode.INVALID_FIELD.getCode(),
e.getMessage(),
null);
} catch (Exception e) {
log.error("Error submitting appeal", e);
return new BaseResponse(request.getMsgId(),
MessageCode.INVALID_FIELD.getCode(),
"Failed to submit appeal: " + e.getMessage(),
@@ -92,7 +92,7 @@ public class ModerationService {
throw new SecurityException("User is not the owner of this file");
}
if (canAppeal(file)) {
if (!canAppeal(file)) {
throw new InvalidAppealException("Cannot appeal this file. Current status: " + file.getStatus());
}
@@ -150,6 +150,7 @@ public class ModerationService {
moderationLogRepository.save(log);
fileEntityRepository.save(file);
fileAppealRepository.save(appeal);
}