Skip to content

Commit

Permalink
[#168] feature(보관함 초대)
Browse files Browse the repository at this point in the history
- 보관함 초대 API 추가
- folderIdList로 북마크를 조회하는 메소드 추가
- folder를 shared인 상태로 변경하는 로직 추가
- folder가 보관함인지 확인하는 로직 추가
  • Loading branch information
Ji-Ha committed Jul 24, 2022
1 parent 4e223a5 commit 3c965ea
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class Bookmark(

var remindList = mutableListOf<Remind>()

var shared: Boolean = false

fun restore(): Bookmark {
this.deleted = false
this.deleteTime = null
Expand All @@ -96,6 +98,10 @@ class Bookmark(
this.description = description
}

fun changeSharedTrue() {
this.shared = true
}

fun deletedByFolder() {
this.folderId = null
this.folderEmoji = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ interface BookmarkRepository : MongoRepository<Bookmark, String> {

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

fun findAllByFolderId(folderIdList: List<Long?>): List<Bookmark>

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

fun findAllByFolderIdAndDeletedIsFalse(folderId: Long, pageable: Pageable): Page<Bookmark>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FolderTokenDto> {
return ResponseEntity.status(HttpStatus.OK).body(folderService.encryptFolderId(folderId))
}

@ApiOperation(value = "초대를 위한 폴더 토큰 발급 API")
@GetMapping("invite/{folderId}")
fun getFolderInvitationToken(@PathVariable folderId: Long): ResponseEntity<FolderTokenDto> {
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):
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/com/yapp/web2/domain/folder/entity/Folder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long?>) {
val bookmarkList = bookmarkRepository.findAllByFolderId(sharedFolderIdList)

for (bookmark in bookmarkList)
bookmark.changeSharedTrue()
}

private fun folderToShared(folder: Folder, rootFolderId: Long): List<Long?> {
val folderIdList = mutableListOf<Long?>()
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!!))
Expand Down

0 comments on commit 3c965ea

Please sign in to comment.