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