diff --git a/archive-application/src/main/java/site/archive/service/report/ReportService.java b/archive-application/src/main/java/site/archive/service/report/ReportService.java deleted file mode 100644 index f58c55e..0000000 --- a/archive-application/src/main/java/site/archive/service/report/ReportService.java +++ /dev/null @@ -1,37 +0,0 @@ -package site.archive.service.report; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import site.archive.domain.common.BaseTimeEntity; -import site.archive.domain.report.Report; -import site.archive.domain.report.ReportRepository; - -import jakarta.transaction.Transactional; - -@Service -@RequiredArgsConstructor -public class ReportService { - - private final ReportRepository reportRepository; - - public boolean isReportedBy(Long archiveId, Long userId) { - return reportRepository.findByArchiveIdAndUserId(archiveId, userId) - .filter(report -> !report.getIsDeleted()) - .isPresent(); - } - - @Transactional - public void reportArchive(Long archiveId, Long userId, String reason) { - var report = reportRepository.findByArchiveIdAndUserId(archiveId, userId) - .orElseGet(() -> Report.of(reason, archiveId, userId)); - report.softDeleteCancel(); - reportRepository.save(report); - } - - @Transactional - public void cancelReportArchive(Long archiveId, Long userId) { - reportRepository.findByArchiveIdAndUserId(archiveId, userId) - .ifPresent(BaseTimeEntity::softDelete); - } - -} diff --git a/archive-application/src/main/kotlin/site/archive/service/report/ReportService.kt b/archive-application/src/main/kotlin/site/archive/service/report/ReportService.kt new file mode 100644 index 0000000..40251d6 --- /dev/null +++ b/archive-application/src/main/kotlin/site/archive/service/report/ReportService.kt @@ -0,0 +1,33 @@ +package site.archive.service.report + +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import site.archive.domain.common.BaseTimeEntity +import site.archive.domain.report.Report +import site.archive.domain.report.ReportRepository + +@Service +@Transactional(readOnly = true) +class ReportService(private val reportRepository: ReportRepository) { + + fun isReportedBy(archiveId: Long, userId: Long): Boolean { + return reportRepository.findByArchiveIdAndUserId(archiveId, userId) + .filter { !it.isDeleted } + .isPresent + } + + @Transactional + fun reportArchive(archiveId: Long, userId: Long, reason: String) { + val report = reportRepository.findByArchiveIdAndUserId(archiveId, userId) + .orElseGet { Report.of(reason, archiveId, userId) } + report.softDeleteCancel() + reportRepository.save(report) + } + + @Transactional + fun cancelReportArchive(archiveId: Long, userId: Long) { + reportRepository.findByArchiveIdAndUserId(archiveId, userId) + .ifPresent(BaseTimeEntity::softDelete) + } + +} \ No newline at end of file