-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#53): converted Report Service java to kotlin
- Loading branch information
1 parent
1244b2f
commit a9e0a42
Showing
2 changed files
with
33 additions
and
37 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
archive-application/src/main/java/site/archive/service/report/ReportService.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
archive-application/src/main/kotlin/site/archive/service/report/ReportService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |