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

This commit is contained in:
vladp
2026-03-27 15:31:45 +07:00
parent 78b97b48c9
commit 547e70ecdd
3 changed files with 28 additions and 23 deletions
@@ -784,24 +784,32 @@ public class FileEntityHandler implements RequestHandler {
List<Map<String, Object>> filesWithInfo = files.getContent().stream()
.map(file -> {
FileModerationInfo info = moderationService.getFileModerationInfo(file.getId());
return Map.of(
"fileId", file.getId(),
"fileName", file.getOriginalFileName(),
"userId", file.getUserId(),
"status", file.getStatus().name(),
"createdAt", file.getCreatedAt(),
"fileSize", file.getFileSize(),
"formattedSize", fileEntityService.formatFileSize(file.getFileSize()),
"moderationInfo", Map.of(
"hasActiveAppeal", info.getHasActiveAppeal(),
"appealInfo", info.getActiveAppeal() != null ?
Map.of(
"appealId", info.getActiveAppeal().getAppealId(),
"status", info.getActiveAppeal().getStatus(),
"createdAt", info.getActiveAppeal().getCreatedAt()
) : null
)
);
Map<String, Object> fileMap = new HashMap<>();
fileMap.put("fileId", file.getId());
fileMap.put("fileName", file.getOriginalFileName());
fileMap.put("userId", file.getUserId());
fileMap.put("status", file.getStatus() != null ? file.getStatus().name() : null);
fileMap.put("createdAt", file.getCreatedAt());
fileMap.put("fileSize", file.getFileSize());
fileMap.put("formattedSize", fileEntityService.formatFileSize(file.getFileSize()));
Map<String, Object> moderationInfoMap = new HashMap<>();
moderationInfoMap.put("hasActiveAppeal", info != null && info.getHasActiveAppeal());
if (info != null && info.getActiveAppeal() != null) {
Map<String, Object> appealInfoMap = new HashMap<>();
appealInfoMap.put("appealId", info.getActiveAppeal().getAppealId());
appealInfoMap.put("status", info.getActiveAppeal().getStatus());
appealInfoMap.put("createdAt", info.getActiveAppeal().getCreatedAt());
moderationInfoMap.put("appealInfo", appealInfoMap);
} else {
moderationInfoMap.put("appealInfo", null);
}
fileMap.put("moderationInfo", moderationInfoMap);
return fileMap;
})
.collect(Collectors.toList());
@@ -42,7 +42,6 @@ public class ModerationReasonService {
throw new IllegalArgumentException("Reason text cannot be empty");
}
// Проверяем на дубликат
if (moderationReasonRepository.findByReasonText(reasonText.trim()).isPresent()) {
throw new IllegalArgumentException("Reason with this text already exists");
}
@@ -70,7 +69,6 @@ public class ModerationReasonService {
throw new IllegalArgumentException("Reason text cannot be empty");
}
// Проверяем на дубликат (исключая текущую запись)
moderationReasonRepository.findByReasonText(newReasonText.trim())
.ifPresent(existingReason -> {
if (!existingReason.getId().equals(reasonId)) {
@@ -99,14 +97,13 @@ public class ModerationReasonService {
ModerationReason reason = moderationReasonRepository.findById(reasonId)
.orElseThrow(() -> new ModerationReasonNotFoundException(reasonId));
// Проверяем, используется ли причина в активных блокировках
long usageCount = getReasonUsageCount(reasonId);
if (usageCount > 0) {
throw new ModerationReasonInUseException(reasonId, usageCount);
}
moderationReasonRepository.delete(reason);
moderationReasonRepository.deleteById(reasonId);
log.info("Deleted moderation reason: id={}, text={}", reasonId, reason.getReasonText());
}
@@ -72,7 +72,7 @@ public class ModerationService {
fileAppealRepository.findByFileIdAndStatus(file.getId(), AppealStatus.PENDING)
.ifPresent(appeal -> {
appeal.setStatus(AppealStatus.REJECTED);
appeal.setAdminComment("Апелляция отклонена в процессе модерации");
appeal.setAdminComment(request.getComment());
appeal.setResolvedAt(LocalDateTime.now());
fileAppealRepository.save(appeal);
});