From 3c965eabbcfe78a0966f34d935dc0c1eb1632de8 Mon Sep 17 00:00:00 2001 From: Ji-Ha Date: Sun, 24 Jul 2022 17:58:10 +0900 Subject: [PATCH] =?UTF-8?q?[#168]=20feature(=EB=B3=B4=EA=B4=80=ED=95=A8=20?= =?UTF-8?q?=EC=B4=88=EB=8C=80)=20-=20=EB=B3=B4=EA=B4=80=ED=95=A8=20?= =?UTF-8?q?=EC=B4=88=EB=8C=80=20API=20=EC=B6=94=EA=B0=80=20-=20folderIdLis?= =?UTF-8?q?t=EB=A1=9C=20=EB=B6=81=EB=A7=88=ED=81=AC=EB=A5=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=98=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20-=20folder=EB=A5=BC=20shared=EC=9D=B8=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80=20-=20folde?= =?UTF-8?q?r=EA=B0=80=20=EB=B3=B4=EA=B4=80=ED=95=A8=EC=9D=B8=EC=A7=80=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=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 --- .../web2/domain/bookmark/entity/Bookmark.kt | 6 ++++ .../bookmark/repository/BookmarkRepository.kt | 2 ++ .../folder/controller/FolderController.kt | 8 ++++- .../yapp/web2/domain/folder/entity/Folder.kt | 11 +++--- .../domain/folder/service/FolderService.kt | 36 +++++++++++++++++++ 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/yapp/web2/domain/bookmark/entity/Bookmark.kt b/src/main/kotlin/com/yapp/web2/domain/bookmark/entity/Bookmark.kt index 1f2c2270..e0918ad6 100644 --- a/src/main/kotlin/com/yapp/web2/domain/bookmark/entity/Bookmark.kt +++ b/src/main/kotlin/com/yapp/web2/domain/bookmark/entity/Bookmark.kt @@ -85,6 +85,8 @@ class Bookmark( var remindList = mutableListOf() + var shared: Boolean = false + fun restore(): Bookmark { this.deleted = false this.deleteTime = null @@ -96,6 +98,10 @@ class Bookmark( this.description = description } + fun changeSharedTrue() { + this.shared = true + } + fun deletedByFolder() { this.folderId = null this.folderEmoji = "" 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 6654319b..59f76ad5 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 @@ -14,6 +14,8 @@ interface BookmarkRepository : MongoRepository { fun findAllByFolderId(folderId: Long): List + fun findAllByFolderId(folderIdList: List): List + fun findAllByFolderIdAndDeleteTimeIsNullAndRemindTimeIsNotNull(folderId: Long, pageable: Pageable): Page fun findAllByFolderIdAndDeletedIsFalse(folderId: Long, pageable: Pageable): Page diff --git a/src/main/kotlin/com/yapp/web2/domain/folder/controller/FolderController.kt b/src/main/kotlin/com/yapp/web2/domain/folder/controller/FolderController.kt index d5180a53..eec76d4c 100644 --- a/src/main/kotlin/com/yapp/web2/domain/folder/controller/FolderController.kt +++ b/src/main/kotlin/com/yapp/web2/domain/folder/controller/FolderController.kt @@ -113,12 +113,18 @@ class FolderController( } // TODO: 2022/06/22 유저 정보 확인 - @ApiOperation(value = "암호화된 폴더 ID 조회 API") + @ApiOperation(value = "폴더 토큰 발급 API") @GetMapping("encrypt/{folderId}") fun getEncryptFolderId(@PathVariable folderId: Long): ResponseEntity { return ResponseEntity.status(HttpStatus.OK).body(folderService.encryptFolderId(folderId)) } + @ApiOperation(value = "초대를 위한 폴더 토큰 발급 API") + @GetMapping("invite/{folderId}") + fun getFolderInvitationToken(@PathVariable folderId: Long): ResponseEntity { + return ResponseEntity.status(HttpStatus.OK).body(folderService.createFolderInvitationToken(folderId)) + } + @ApiOperation(value = "보관함에 속한 유저 리스트 조회 API") @GetMapping("belong/{folderId}") fun getAccountList(@PathVariable @ApiParam(value = "폴더 ID", example = "2", required = true) folderId: Long): diff --git a/src/main/kotlin/com/yapp/web2/domain/folder/entity/Folder.kt b/src/main/kotlin/com/yapp/web2/domain/folder/entity/Folder.kt index 14d127f9..51576003 100644 --- a/src/main/kotlin/com/yapp/web2/domain/folder/entity/Folder.kt +++ b/src/main/kotlin/com/yapp/web2/domain/folder/entity/Folder.kt @@ -175,9 +175,12 @@ class Folder( this.bookmarkCount += count } - fun setRootFolder(folder: Folder) { - folder.rootFolderId?.let { - this.rootFolderId = it - } ?: let { this.rootFolderId = folder.id } + fun folderToShared(rootFolderId: Long) { + this.rootFolderId = rootFolderId + } + + fun isRootFolder(): Boolean { + if(parentFolder == null) return true + return false } } \ No newline at end of file diff --git a/src/main/kotlin/com/yapp/web2/domain/folder/service/FolderService.kt b/src/main/kotlin/com/yapp/web2/domain/folder/service/FolderService.kt index 8073c423..042e721a 100644 --- a/src/main/kotlin/com/yapp/web2/domain/folder/service/FolderService.kt +++ b/src/main/kotlin/com/yapp/web2/domain/folder/service/FolderService.kt @@ -324,6 +324,42 @@ class FolderService( return childList } + fun createFolderInvitationToken(rootFolderId: Long): FolderTokenDto { + //그냥 재귀를 돌면서 Folder 리스트들을 다 받고, 그 후에 폴더들에 rootFolder 추가, 북마크 shared 변경 하면 되지 않을까? 굳이 재귀? + val folder = folderRepository.findFolderById(rootFolderId) ?: throw FolderNotFoundException() + if(!folder.isRootFolder()) throw RuntimeException("보관함이 아닙니다! 공유를 할 수 없습니다.") + + // 하위 폴더들 모두 rootFolderId 추가해주기 + val sharedFolderIdList = folderToShared(folder, rootFolderId) + + // 하위 북마크들 모두 shared가 true인 상태로 변경해주기 + changeBookmarkToShared(sharedFolderIdList) + + // 토큰 발급 + return FolderTokenDto(jwtProvider.createFolderToken(rootFolderId)) + } + + private fun changeBookmarkToShared(sharedFolderIdList: List) { + val bookmarkList = bookmarkRepository.findAllByFolderId(sharedFolderIdList) + + for (bookmark in bookmarkList) + bookmark.changeSharedTrue() + } + + private fun folderToShared(folder: Folder, rootFolderId: Long): List { + val folderIdList = mutableListOf() + folder.folderToShared(rootFolderId) + folderIdList.add(folder.id) + + folder.children?.let { + for (child in it) { + folderIdList.addAll(folderToShared(child, rootFolderId)) + } + } + + return folderIdList + } + fun encryptFolderId(folderId: Long): FolderTokenDto { val folder = folderRepository.findFolderById(folderId) ?: throw FolderNotFoundException() return FolderTokenDto(jwtProvider.createFolderToken(folderId = folder.id!!))