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