-
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 Like Service java to kotlin
- Loading branch information
1 parent
388314f
commit 1244b2f
Showing
2 changed files
with
49 additions
and
57 deletions.
There are no files selected for viewing
57 changes: 0 additions & 57 deletions
57
archive-application/src/main/java/site/archive/service/like/LikeService.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
archive-application/src/main/kotlin/site/archive/service/like/LikeService.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,49 @@ | ||
package site.archive.service.like | ||
|
||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import site.archive.common.exception.common.ResourceNotFoundException | ||
import site.archive.domain.common.BaseTimeEntity | ||
import site.archive.domain.like.Like | ||
import site.archive.domain.like.LikeRepository | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class LikeService(private val likeRepository: LikeRepository) { | ||
|
||
@Transactional | ||
fun save(userId: Long, archiveId: Long) { | ||
likeRepository.findByUserIdAndArchiveId(userId, archiveId) | ||
.ifPresentOrElse(BaseTimeEntity::softDeleteCancel) { likeRepository.save(Like.of(userId, archiveId)) } | ||
} | ||
|
||
@Transactional | ||
fun save(userId: Long, archiveIds: List<Long>) { | ||
archiveIds.forEach { | ||
likeRepository.findByUserIdAndArchiveId(userId, it) | ||
.ifPresentOrElse(BaseTimeEntity::softDeleteCancel) { likeRepository.save(Like.of(userId, it)) } | ||
} | ||
} | ||
|
||
@Transactional | ||
fun delete(userId: Long, archiveId: Long) { | ||
likeRepository.findByUserIdAndArchiveId(userId, archiveId) | ||
.ifPresentOrElse(likeRepository::delete) { throw ResourceNotFoundException("조건에 맞는 Like 데이터가 없습니다") } | ||
} | ||
|
||
@Transactional | ||
fun delete(userId: Long, archiveIds: List<Long>) { | ||
archiveIds.forEach { | ||
likeRepository.findByUserIdAndArchiveId(userId, it) | ||
.ifPresentOrElse(likeRepository::delete) { throw ResourceNotFoundException("조건에 맞는 Like 데이터가 없습니다") } | ||
} | ||
} | ||
|
||
fun likeArchiveIds(userId: Long): List<Long> { | ||
return likeRepository.findAllByUserId(userId) | ||
.filter { !it.isDeleted } | ||
.map { it.archive.id } | ||
.toList() | ||
} | ||
|
||
} |