Skip to content

Commit

Permalink
[#132] refactor(bookmark)
Browse files Browse the repository at this point in the history
- 기존 북마크들과 새롭게 만들어진 personalBookmark 조회를 위한 로직 변경
- repository 메소드 수정
- bookmark -> bookmarkRequestDto 메소드 추가
- bookmarkInterface -> bookmarkRequestDto 메소드 추가
  • Loading branch information
Ji-Ha committed Jun 27, 2022
1 parent 2929d0f commit 73e7ab2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/main/kotlin/com/yapp/web2/domain/bookmark/BookmarkDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.yapp.web2.domain.bookmark.entity.SharedBookmark
import com.yapp.web2.domain.folder.entity.Folder
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
import java.time.LocalDateTime
import javax.validation.constraints.NotEmpty
import javax.validation.constraints.NotNull

Expand Down Expand Up @@ -120,4 +121,21 @@ class BookmarkDto {
val title: String,
val description: String
)

data class BookmarkRequestDto(
val id: String,
val userId: Long?,
val link: String,
val title: String?,
val description: String?,
val image: String?,
val folderId: Long?,
val folderEmoji: String?,
val folderName: String?,
val clickCount: Int,
val deleteTime: LocalDateTime?,
val deleted: Boolean,
val saveTime: LocalDateTime,
val parentBookmarkId: String?
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yapp.web2.domain.bookmark.controller

import com.yapp.web2.domain.bookmark.BookmarkDto
import com.yapp.web2.domain.bookmark.entity.Bookmark
import com.yapp.web2.domain.bookmark.service.BookmarkPageService
import com.yapp.web2.domain.bookmark.service.BookmarkSearchService
Expand Down Expand Up @@ -73,7 +74,7 @@ class BookmarkPageController(
fun getBookmarkPageByFolderToken(
@PathVariable folderToken: String,
pageable: Pageable
): ResponseEntity<Page<Bookmark>> {
): ResponseEntity<Page<BookmarkDto.BookmarkRequestDto>> {
return ResponseEntity.status(HttpStatus.OK)
.body(bookmarkPageService.getAllPageByEncryptFolderId(folderToken, pageable))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yapp.web2.domain.bookmark.repository

import com.yapp.web2.domain.bookmark.entity.BookmarkInterface
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.stereotype.Repository

Expand All @@ -10,7 +12,8 @@ interface BookmarkInterfaceRepository : MongoRepository<BookmarkInterface, Strin
fun deleteAllByParentBookmarkId(parentBookmarkIdList: List<String>)
fun deleteByParentBookmarkIdAndUserId(parentBookmarkId: String, userId: Long)
fun findAllByParentBookmarkId(bookmarkId: String): List<BookmarkInterface>
fun findAllByFolderId(folderId: Long): List<BookmarkInterface>?
fun findAllByFolderId(folderId: Long): List<BookmarkInterface>
fun findAllByFolderId(folderId: Long, pageable: Pageable): Page<BookmarkInterface>?

// page 조회
fun findAllByFolderIdAndDeleteTimeIsNull(folderId: Long): List<BookmarkInterface>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface BookmarkRepository : MongoRepository<Bookmark, String> {

fun findAllByFolderIdAndDeleteTimeIsNull(folderId: Long, pageable: Pageable): Page<Bookmark>

fun findAllByFolderIdAndDeleteTimeIsNull(folderId: Long): List<Bookmark>

fun findAllByUserIdAndRemindTimeIsNotNullAndDeleteTimeIsNull(userId: Long, pageable: Pageable): Page<Bookmark>

fun findAllByUserIdAndDeleteTimeIsNull(userId: Long, pageable: Pageable): Page<Bookmark>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.yapp.web2.domain.bookmark.service

import com.yapp.web2.domain.bookmark.BookmarkDto
import com.yapp.web2.domain.bookmark.entity.Bookmark
import com.yapp.web2.domain.bookmark.entity.BookmarkInterface
import com.yapp.web2.domain.bookmark.repository.BookmarkInterfaceRepository
import com.yapp.web2.domain.bookmark.repository.BookmarkRepository
import com.yapp.web2.security.jwt.JwtProvider
import com.yapp.web2.util.AES256Util
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageImpl
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -13,6 +18,7 @@ import java.time.LocalDate
@Service
class BookmarkPageService(
private val bookmarkRepository: BookmarkRepository,
private val bookmarkInterfaceRepository: BookmarkInterfaceRepository,
private val jwtProvider: JwtProvider,
private val aes256Util: AES256Util
) {
Expand Down Expand Up @@ -56,8 +62,60 @@ class BookmarkPageService(
)
}

fun getAllPageByEncryptFolderId(token: String, pageable: Pageable): Page<Bookmark> {
fun getAllPageByEncryptFolderId(token: String, pageable: Pageable): Page<BookmarkDto.BookmarkRequestDto> {
val folderIdByString = aes256Util.decrypt(token)
return bookmarkRepository.findAllByFolderIdAndDeleteTimeIsNull(folderIdByString.toLong(), pageable)
val bookmarkList =
bookmarkToBookmarkRequestDto(bookmarkRepository.findAllByFolderIdAndDeleteTimeIsNull(folderIdByString.toLong()))
val bookmarkInterfaceList = bookmarkInterfaceToBookmarkRequestDto(bookmarkInterfaceRepository.findAllByFolderId(folderIdByString.toLong()))

val list = bookmarkList + bookmarkInterfaceList

return PageImpl(list, pageable, list.size.toLong())
}

private fun bookmarkToBookmarkRequestDto(bookmarkList: List<Bookmark>): List<BookmarkDto.BookmarkRequestDto> {
val result = mutableListOf<BookmarkDto.BookmarkRequestDto>()
for (bookmark in bookmarkList) {
result.add(BookmarkDto.BookmarkRequestDto(
bookmark.id,
bookmark.userId,
bookmark.link,
bookmark.title,
bookmark.description,
bookmark.image,
bookmark.folderId,
bookmark.folderEmoji,
bookmark.folderName,
bookmark.clickCount,
bookmark.deleteTime,
bookmark.deleted,
bookmark.saveTime,
null
))
}
return result
}

private fun bookmarkInterfaceToBookmarkRequestDto(bookmarkList: List<BookmarkInterface>): List<BookmarkDto.BookmarkRequestDto> {
val result = mutableListOf<BookmarkDto.BookmarkRequestDto>()
for (bookmark in bookmarkList) {
result.add(BookmarkDto.BookmarkRequestDto(
bookmark.id,
bookmark.userId,
bookmark.link,
bookmark.title,
bookmark.description,
bookmark.image,
bookmark.folderId,
bookmark.folderEmoji,
bookmark.folderName,
bookmark.clickCount,
bookmark.deleteTime,
bookmark.deleted,
bookmark.saveTime,
null
))
}
return result
}
}

0 comments on commit 73e7ab2

Please sign in to comment.