Skip to content

Commit

Permalink
feat(#53): converted Report Service java to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
KimDoubleB committed Jan 21, 2023
1 parent 1244b2f commit a9e0a42
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
}

}

0 comments on commit a9e0a42

Please sign in to comment.