Skip to content

Commit

Permalink
[feat #31] 즐겨찾기 취소 API (#35)
Browse files Browse the repository at this point in the history
* feat : 북마크 삭제 쿼리 메소드

* feat : 북마크 삭제 유스케이스 구현

* feat : 북마크 삭제 API
  • Loading branch information
dlswns2480 authored Jul 23, 2024
1 parent 5ec9288 commit db85cd0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,15 @@ class ContentController(
val response = contentUseCase.bookmarkContent(user, contentId = contentId)
return ResponseEntity.ok(response)
}

@PutMapping("/{contentId}/bookmark")
@Operation(summary = "즐겨찾기 취소 API")
fun cancelBookmark(
@AuthenticationPrincipal principalUser: PrincipalUser,
@PathVariable("contentId") contentId: Long
): ResponseEntity<Unit> {
val user = principalUser.toDomain()
return contentUseCase.cancelBookmark(user, contentId)
.wrapUnit()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ class BookMarkAdapter(
val savedBookmark = bookMarkRepository.save(bookmarkEntity)
return savedBookmark.toDomain()
}

override fun delete(contentId: Long, userId: Long) {
bookMarkRepository.findByContentIdAndUserIdAndDeleted(
contentId,
userId,
false
)?.delete()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ package com.pokit.out.persistence.bookmark.persist
import org.springframework.data.jpa.repository.JpaRepository

interface BookMarkRepository : JpaRepository<BookmarkEntity, Long> {
fun findByContentIdAndUserIdAndDeleted(
contentId: Long,
userId: Long,
deleted: Boolean
): BookmarkEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ class BookmarkEntity(

@Column(name = "user_id")
val userId: Long,

@Column(name = "deleted")
var deleted: Boolean = true
) {
fun delete() {
this.deleted = true
}

companion object {
fun of(bookmark: Bookmark) =
BookmarkEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import com.pokit.bookmark.model.Bookmark

interface BookmarkPort {
fun persist(bookmark: Bookmark): Bookmark

fun delete(userId: Long, contentId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ interface ContentUseCase {
fun update(user: User, contentCommand: ContentCommand, contentId: Long): Content

fun delete(user: User, contentId: Long)
fun cancelBookmark(user: User, contentId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class ContentService(
contentPort.delete(content)
}

@Transactional
override fun cancelBookmark(user: User, contentId: Long) {
verifyContent(user.id, contentId)
bookMarkPort.delete(user.id, contentId)
}

private fun verifyContent(userId: Long, contentId: Long): Content {
return contentPort.loadByUserIdAndId(userId, contentId)
?: throw NotFoundCustomException(ContentErrorCode.NOT_FOUND_CONTENT)
Expand Down

0 comments on commit db85cd0

Please sign in to comment.