@@ -2,6 +2,7 @@ package ru.soune.nocopy.dto;
|
|||||||
|
|
||||||
public enum MessageCode {
|
public enum MessageCode {
|
||||||
SUCCESS(0, "Operation successful"),
|
SUCCESS(0, "Operation successful"),
|
||||||
|
SUCCESS_MODERATION(0, "File moderated successfully"),
|
||||||
REG_EMAIL_EXISTS(1, "Email already registered"),
|
REG_EMAIL_EXISTS(1, "Email already registered"),
|
||||||
REG_EMAIL_OR_PHONE_EXISTS(1, "Email or phone already registered"),
|
REG_EMAIL_OR_PHONE_EXISTS(1, "Email or phone already registered"),
|
||||||
REFERRAL_LINK_IS_NOT_EXIST(1, "Refferal link is not exist"),
|
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"),
|
MONITORING_TYPE_NOT_FOUND(4, "Monitoring type not found"),
|
||||||
ERROR_TARIFF_INFO(2, "Erorr with tariff info"),
|
ERROR_TARIFF_INFO(2, "Erorr with tariff info"),
|
||||||
FILE_FOR_SEARCH_NOT_VALID(2, "File for search unsupported"),
|
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" +
|
NOT_VALID_FILE_TYPE_OR_COUNT_FILE(2, "Cost for file type not found, count is negative or files count" +
|
||||||
"more than max valid"),
|
"more than max valid"),
|
||||||
USER_NOT_ACTIVE(2, "User not active"),
|
USER_NOT_ACTIVE(2, "User not active"),
|
||||||
|
|||||||
@@ -219,19 +219,21 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
|
|
||||||
private BaseResponse handleChangeStatus(BaseRequest request, FileEntityRequest fileRequest) {
|
private BaseResponse handleChangeStatus(BaseRequest request, FileEntityRequest fileRequest) {
|
||||||
FileStatus newStatus = fileRequest.getFileStatus();
|
FileStatus newStatus = fileRequest.getFileStatus();
|
||||||
|
String fileId = fileRequest.getFileId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fileEntityService.changeFileStatus(newStatus ,fileRequest.getFileId());
|
fileEntityService.changeFileStatus(newStatus ,fileRequest.getFileId());
|
||||||
} catch (FileEntityNotFoundException e) {
|
} catch (FileEntityNotFoundException e) {
|
||||||
return new BaseResponse(request.getMsgId(),
|
return new BaseResponse(request.getMsgId(),
|
||||||
MessageCode.FILE_NOT_FOUND.getCode(),
|
MessageCode.FILE_NOT_FOUND.getCode(),
|
||||||
MessageCode.FILE_NOT_FOUND.getDescription(),
|
MessageCode.FILE_NOT_FOUND.getDescription(),
|
||||||
null);
|
FileEntityResponse.builder().id(fileId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BaseResponse(request.getMsgId(),
|
return new BaseResponse(request.getMsgId(),
|
||||||
MessageCode.SUCCESS.getCode(),
|
MessageCode.SUCCESS.getCode(),
|
||||||
MessageCode.SUCCESS.getDescription(),
|
MessageCode.SUCCESS.getDescription(),
|
||||||
Map.of("new_status", newStatus));
|
FileEntityResponse.builder().status(newStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
private BaseResponse handleSearchFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
private BaseResponse handleSearchFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
||||||
@@ -635,21 +637,27 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
moderationService.moderateFile(moderationRequest, 0L);
|
moderationService.moderateFile(moderationRequest, 0L);
|
||||||
|
|
||||||
return new BaseResponse(request.getMsgId(),
|
return new BaseResponse(request.getMsgId(),
|
||||||
MessageCode.SUCCESS.getCode(),
|
MessageCode.SUCCESS_MODERATION.getCode(),
|
||||||
"File moderated successfully",
|
MessageCode.SUCCESS_MODERATION.getDescription(),
|
||||||
null);
|
FileEntityResponse.builder().id(fileRequest.getFileId()));
|
||||||
|
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
return new BaseResponse(request.getMsgId(),
|
return new BaseResponse(request.getMsgId(),
|
||||||
MessageCode.ACCESS_DENIED.getCode(),
|
MessageCode.ACCESS_DENIED.getCode(),
|
||||||
e.getMessage(),
|
MessageCode.ACCESS_DENIED.getDescription(),
|
||||||
null);
|
FileEntityResponse.builder().id(fileRequest.getFileId()));
|
||||||
} catch (Exception e) {
|
} catch (FileEntityNotFoundException e) {
|
||||||
log.error("Error moderating file", e);
|
|
||||||
return new BaseResponse(request.getMsgId(),
|
return new BaseResponse(request.getMsgId(),
|
||||||
MessageCode.INVALID_FIELD.getCode(),
|
MessageCode.FILE_NOT_FOUND.getCode(),
|
||||||
"Failed to moderate file: " + e.getMessage(),
|
MessageCode.FILE_NOT_FOUND.getDescription(),
|
||||||
null);
|
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(),
|
MessageCode.SUCCESS.getCode(),
|
||||||
"Appeal submitted successfully",
|
"Appeal submitted successfully",
|
||||||
response);
|
response);
|
||||||
|
|
||||||
} catch (InvalidAppealException e) {
|
} catch (InvalidAppealException e) {
|
||||||
return new BaseResponse(request.getMsgId(),
|
return new BaseResponse(request.getMsgId(),
|
||||||
MessageCode.INVALID_FIELD.getCode(),
|
MessageCode.INVALID_FIELD.getCode(),
|
||||||
e.getMessage(),
|
e.getMessage(),
|
||||||
null);
|
null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error submitting appeal", e);
|
|
||||||
return new BaseResponse(request.getMsgId(),
|
return new BaseResponse(request.getMsgId(),
|
||||||
MessageCode.INVALID_FIELD.getCode(),
|
MessageCode.INVALID_FIELD.getCode(),
|
||||||
"Failed to submit appeal: " + e.getMessage(),
|
"Failed to submit appeal: " + e.getMessage(),
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class ModerationService {
|
|||||||
throw new SecurityException("User is not the owner of this file");
|
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());
|
throw new InvalidAppealException("Cannot appeal this file. Current status: " + file.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +150,7 @@ public class ModerationService {
|
|||||||
moderationLogRepository.save(log);
|
moderationLogRepository.save(log);
|
||||||
|
|
||||||
fileEntityRepository.save(file);
|
fileEntityRepository.save(file);
|
||||||
|
|
||||||
fileAppealRepository.save(appeal);
|
fileAppealRepository.save(appeal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user