From 73e7ab26e3245621aa6c8d0412a138fd788b2d44 Mon Sep 17 00:00:00 2001 From: Ji-Ha Date: Mon, 27 Jun 2022 14:33:22 +0900 Subject: [PATCH] =?UTF-8?q?[#132]=20refactor(bookmark)=20-=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20=EB=B6=81=EB=A7=88=ED=81=AC=EB=93=A4=EA=B3=BC=20?= =?UTF-8?q?=EC=83=88=EB=A1=AD=EA=B2=8C=20=EB=A7=8C=EB=93=A4=EC=96=B4?= =?UTF-8?q?=EC=A7=84=20personalBookmark=20=EC=A1=B0=ED=9A=8C=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?-=20repository=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20-=20bookmark=20->=20bookmarkRequestDto=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80=20-=20bookmarkInterface?= =?UTF-8?q?=20->=20bookmarkRequestDto=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yapp/web2/domain/bookmark/BookmarkDto.kt | 18 ++++++ .../controller/BookmarkPageController.kt | 3 +- .../repository/BookmarkInterfaceRepository.kt | 5 +- .../bookmark/repository/BookmarkRepository.kt | 2 + .../bookmark/service/BookmarkPageService.kt | 62 ++++++++++++++++++- 5 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/yapp/web2/domain/bookmark/BookmarkDto.kt b/src/main/kotlin/com/yapp/web2/domain/bookmark/BookmarkDto.kt index 1d8f0202..6d65cf84 100644 --- a/src/main/kotlin/com/yapp/web2/domain/bookmark/BookmarkDto.kt +++ b/src/main/kotlin/com/yapp/web2/domain/bookmark/BookmarkDto.kt @@ -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 @@ -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? + ) } \ No newline at end of file diff --git a/src/main/kotlin/com/yapp/web2/domain/bookmark/controller/BookmarkPageController.kt b/src/main/kotlin/com/yapp/web2/domain/bookmark/controller/BookmarkPageController.kt index 26b66db1..17d60fdd 100644 --- a/src/main/kotlin/com/yapp/web2/domain/bookmark/controller/BookmarkPageController.kt +++ b/src/main/kotlin/com/yapp/web2/domain/bookmark/controller/BookmarkPageController.kt @@ -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 @@ -73,7 +74,7 @@ class BookmarkPageController( fun getBookmarkPageByFolderToken( @PathVariable folderToken: String, pageable: Pageable - ): ResponseEntity> { + ): ResponseEntity> { return ResponseEntity.status(HttpStatus.OK) .body(bookmarkPageService.getAllPageByEncryptFolderId(folderToken, pageable)) } diff --git a/src/main/kotlin/com/yapp/web2/domain/bookmark/repository/BookmarkInterfaceRepository.kt b/src/main/kotlin/com/yapp/web2/domain/bookmark/repository/BookmarkInterfaceRepository.kt index 1124e980..77a24faf 100644 --- a/src/main/kotlin/com/yapp/web2/domain/bookmark/repository/BookmarkInterfaceRepository.kt +++ b/src/main/kotlin/com/yapp/web2/domain/bookmark/repository/BookmarkInterfaceRepository.kt @@ -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 @@ -10,7 +12,8 @@ interface BookmarkInterfaceRepository : MongoRepository) fun deleteByParentBookmarkIdAndUserId(parentBookmarkId: String, userId: Long) fun findAllByParentBookmarkId(bookmarkId: String): List - fun findAllByFolderId(folderId: Long): List? + fun findAllByFolderId(folderId: Long): List + fun findAllByFolderId(folderId: Long, pageable: Pageable): Page? // page 조회 fun findAllByFolderIdAndDeleteTimeIsNull(folderId: Long): List diff --git a/src/main/kotlin/com/yapp/web2/domain/bookmark/repository/BookmarkRepository.kt b/src/main/kotlin/com/yapp/web2/domain/bookmark/repository/BookmarkRepository.kt index 2fc8fecc..9b154dfa 100644 --- a/src/main/kotlin/com/yapp/web2/domain/bookmark/repository/BookmarkRepository.kt +++ b/src/main/kotlin/com/yapp/web2/domain/bookmark/repository/BookmarkRepository.kt @@ -18,6 +18,8 @@ interface BookmarkRepository : MongoRepository { fun findAllByFolderIdAndDeleteTimeIsNull(folderId: Long, pageable: Pageable): Page + fun findAllByFolderIdAndDeleteTimeIsNull(folderId: Long): List + fun findAllByUserIdAndRemindTimeIsNotNullAndDeleteTimeIsNull(userId: Long, pageable: Pageable): Page fun findAllByUserIdAndDeleteTimeIsNull(userId: Long, pageable: Pageable): Page diff --git a/src/main/kotlin/com/yapp/web2/domain/bookmark/service/BookmarkPageService.kt b/src/main/kotlin/com/yapp/web2/domain/bookmark/service/BookmarkPageService.kt index 85f3297a..353a5094 100644 --- a/src/main/kotlin/com/yapp/web2/domain/bookmark/service/BookmarkPageService.kt +++ b/src/main/kotlin/com/yapp/web2/domain/bookmark/service/BookmarkPageService.kt @@ -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 @@ -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 ) { @@ -56,8 +62,60 @@ class BookmarkPageService( ) } - fun getAllPageByEncryptFolderId(token: String, pageable: Pageable): Page { + fun getAllPageByEncryptFolderId(token: String, pageable: Pageable): Page { 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): List { + val result = mutableListOf() + 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): List { + val result = mutableListOf() + 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 } } \ No newline at end of file