From e508844743115460ae4cbe9fa2e4c6a5d0acc70e Mon Sep 17 00:00:00 2001 From: Ji-Ha Date: Tue, 16 Aug 2022 12:41:19 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[#176]=20init(SharedType)=20:=20=EB=B3=B4?= =?UTF-8?q?=EA=B4=80=ED=95=A8=20=EC=83=81=ED=83=9C=20=EC=BB=AC=EB=9F=BC=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 --- .../kotlin/com/yapp/web2/domain/folder/entity/Folder.kt | 6 ++++-- .../kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt 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 3ae011a..4153cf8 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 @@ -38,8 +38,10 @@ class Folder( @OneToMany(mappedBy = "folder", cascade = [CascadeType.ALL]) var folders: MutableList? = mutableListOf() - // TODO: 2022/05/06 공유 북마크인지 확인하기 위해서 추가한 컬럼 - var share: Boolean? = false + // 공유 상태 저장 + var sharedType: SharedType = SharedType.CLOSED + + var beforeSharedType: SharedType? = null var rootFolderId: Long? = null diff --git a/src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt b/src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt new file mode 100644 index 0000000..51818e0 --- /dev/null +++ b/src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt @@ -0,0 +1,5 @@ +package com.yapp.web2.domain.folder.entity + +enum class SharedType { + INVITE, OPEN, CLOSED +} \ No newline at end of file From ff317ac6673674d29781d97998f2c1ca5daf82b1 Mon Sep 17 00:00:00 2001 From: Ji-Ha Date: Tue, 16 Aug 2022 15:34:48 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[#176]=20feature(=EB=B3=B4=EA=B4=80?= =?UTF-8?q?=ED=95=A8=20=EC=9E=A0=EA=B8=88/=ED=95=B4=EC=A0=9C)=20-=20Shared?= =?UTF-8?q?Type=EC=97=90=EC=84=9C=20=EC=9E=A0=EA=B8=88=ED=95=B4=EC=A0=9C?= =?UTF-8?q?=20=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20-=20=ED=8F=B4=EB=8D=94=EB=A5=BC=20OPEN/INVITE/INVITE=5FAND?= =?UTF-8?q?=5FOPEN=20=EC=83=81=ED=83=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=ED=95=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80=20-=20ENUM=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9D=84=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=EC=97=90=20=EC=A0=80=EC=9E=A5=ED=95=A0=20=EB=95=8C=20?= =?UTF-8?q?String=20=EC=9C=BC=EB=A1=9C=20=EC=A0=80=EC=9E=A5=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?-=20=EC=B4=88=EB=8C=80=EB=A5=BC=20=EC=88=98=EB=9D=BD=ED=95=A0?= =?UTF-8?q?=20=EB=95=8C,=20=EB=B3=B4=EA=B4=80=ED=95=A8=EC=9D=98=20?= =?UTF-8?q?=EA=B3=B5=EC=9C=A0=20=EC=83=81=ED=83=9C=ED=99=95=EC=9D=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80=20-=20=EB=B9=84?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=EC=9D=B4=20=EB=B3=B4=EA=B4=80=ED=95=A8?= =?UTF-8?q?=EC=9D=84=20=EC=A1=B0=ED=9A=8C=ED=95=A0=20=EB=95=8C,=20?= =?UTF-8?q?=EB=B3=B4=EA=B4=80=ED=95=A8=EC=9D=98=20=EA=B3=B5=EC=9C=A0=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=ED=99=95=EC=9D=B8=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 --- .../domain/account/service/AccountService.kt | 1 + .../bookmark/service/BookmarkPageService.kt | 4 +++ .../folder/controller/FolderController.kt | 7 ++++ .../domain/folder/entity/AccountFolder.kt | 9 ++--- .../yapp/web2/domain/folder/entity/Folder.kt | 29 ++++++++++++++-- .../web2/domain/folder/entity/SharedType.kt | 33 ++++++++++++++++++- .../domain/folder/service/FolderService.kt | 9 +++++ 7 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/yapp/web2/domain/account/service/AccountService.kt b/src/main/kotlin/com/yapp/web2/domain/account/service/AccountService.kt index f90cc08..cc6b472 100644 --- a/src/main/kotlin/com/yapp/web2/domain/account/service/AccountService.kt +++ b/src/main/kotlin/com/yapp/web2/domain/account/service/AccountService.kt @@ -196,6 +196,7 @@ class AccountService( val rootFolder = folderService.findByFolderId(folderId) if (rootFolder.rootFolderId != folderId) throw FolderNotRootException() + if(!rootFolder.isInviteState()) throw RuntimeException("보관함이 초대잠금상태입니다. 가입할 수 없습니다.") val accountFolder = AccountFolder(account, rootFolder) accountFolder.changeAuthority(Authority.INVITEE) 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 379c00d..69298f9 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 @@ -4,6 +4,7 @@ import com.yapp.web2.domain.bookmark.BookmarkDto import com.yapp.web2.domain.bookmark.entity.Bookmark import com.yapp.web2.domain.bookmark.repository.BookmarkRepository import com.yapp.web2.domain.folder.entity.Folder +import com.yapp.web2.domain.folder.service.FolderService import com.yapp.web2.security.jwt.JwtProvider import org.springframework.data.domain.Page import org.springframework.data.domain.PageImpl @@ -16,6 +17,7 @@ import java.time.LocalDate @Transactional(readOnly = true) class BookmarkPageService( private val bookmarkRepository: BookmarkRepository, + private val folderService: FolderService, private val jwtProvider: JwtProvider ) { @@ -39,6 +41,8 @@ class BookmarkPageService( fun getAllPageByEncryptFolderId(token: String, pageable: Pageable): Page { val folderId = jwtProvider.getIdFromToken(token) + val folder = folderService.findByFolderId(folderId) + if(!folder.isOpenState()) throw RuntimeException("보관함이 조회잠금상태입니다. 조회할 수 없습니다!") return bookmarkRepository.findAllByFolderIdAndDeletedIsFalse(folderId, pageable) } 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 eec76d4..f35bc37 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 @@ -125,6 +125,13 @@ class FolderController( return ResponseEntity.status(HttpStatus.OK).body(folderService.createFolderInvitationToken(folderId)) } + @ApiOperation(value = "보관함 잠금/해제 API") + @GetMapping("state/{folderId}") + fun inverseFolderShare(@PathVariable folderId: Long): ResponseEntity { + folderService.inverseSharedType(folderId) + return ResponseEntity.status(HttpStatus.OK).body(Message.SUCCESS) + } + @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/AccountFolder.kt b/src/main/kotlin/com/yapp/web2/domain/folder/entity/AccountFolder.kt index dd98115..23ea835 100644 --- a/src/main/kotlin/com/yapp/web2/domain/folder/entity/AccountFolder.kt +++ b/src/main/kotlin/com/yapp/web2/domain/folder/entity/AccountFolder.kt @@ -1,13 +1,7 @@ package com.yapp.web2.domain.folder.entity import com.yapp.web2.domain.account.entity.Account -import javax.persistence.Entity -import javax.persistence.GeneratedValue -import javax.persistence.Id -import javax.persistence.JoinColumn -import javax.persistence.ManyToOne -import javax.persistence.FetchType -import javax.persistence.GenerationType +import javax.persistence.* @Entity class AccountFolder( @@ -25,6 +19,7 @@ class AccountFolder( @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Long? = null + @Enumerated(value = EnumType.STRING) var authority: Authority = Authority.NONE fun changeAuthority(authority: Authority) { 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 63bf8fc..0a886e0 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 @@ -40,9 +40,8 @@ class Folder( var folders: MutableList? = mutableListOf() // 공유 상태 저장 - var sharedType: SharedType = SharedType.CLOSED - - var beforeSharedType: SharedType? = null + @Enumerated(value = EnumType.STRING) + var sharedType: SharedType = SharedType.ALL_CLOSED var rootFolderId: Long? = null @@ -191,4 +190,28 @@ class Folder( if(folder.rootFolderId == this.rootFolderId) return true return false } + + fun changeSharedTypeToOpen() { + if(this.sharedType == SharedType.INVITE) this.sharedType = SharedType.INVITE_AND_OPEN + else this.sharedType = SharedType.OPEN + } + + fun changeSharedTypeToInvite() { + if(this.sharedType == SharedType.OPEN) this.sharedType = SharedType.INVITE_AND_OPEN + else this.sharedType = SharedType.INVITE + } + + fun inverseShareType() { + this.sharedType = this.sharedType.inversionState() + } + + fun isInviteState(): Boolean { + if(this.sharedType == SharedType.INVITE || this.sharedType == SharedType.INVITE_AND_OPEN) return true + return false + } + + fun isOpenState(): Boolean { + if(this.sharedType == SharedType.OPEN || this.sharedType == SharedType.INVITE_AND_OPEN) return true + return false + } } \ No newline at end of file diff --git a/src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt b/src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt index 51818e0..b129ae6 100644 --- a/src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt +++ b/src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt @@ -1,5 +1,36 @@ package com.yapp.web2.domain.folder.entity enum class SharedType { - INVITE, OPEN, CLOSED + INVITE { + override fun inversionState(): SharedType { + return CLOSED_INVITE + } + }, + OPEN { + override fun inversionState(): SharedType { + return CLOSED_OPEN + } + }, + INVITE_AND_OPEN { + override fun inversionState(): SharedType { + return ALL_CLOSED + } + }, + CLOSED_INVITE { + override fun inversionState(): SharedType { + return INVITE + } + }, + CLOSED_OPEN { + override fun inversionState(): SharedType { + return OPEN + } + }, + ALL_CLOSED { + override fun inversionState(): SharedType { + return INVITE_AND_OPEN + } + }; + + abstract fun inversionState(): SharedType } \ 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 35a2d77..fbfddaf 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 @@ -329,6 +329,9 @@ class FolderService( val folder = folderRepository.findFolderById(rootFolderId) ?: throw FolderNotFoundException() if(!folder.isRootFolder()) throw RuntimeException("보관함이 아닙니다! 공유를 할 수 없습니다.") + // 폴더의 공유 상태 변경하기 + folder.changeSharedTypeToInvite() + // 하위 폴더들 모두 rootFolderId 추가해주기 val sharedFolderIdList = changeFolderToShared(folder, rootFolderId) @@ -362,9 +365,15 @@ class FolderService( fun encryptFolderId(folderId: Long): FolderTokenDto { val folder = folderRepository.findFolderById(folderId) ?: throw FolderNotFoundException() + folder.changeSharedTypeToOpen() return FolderTokenDto(jwtProvider.createFolderToken(folderId = folder.id!!)) } + fun inverseSharedType(folderId: Long) { + val folder = folderRepository.findFolderById(folderId) ?: throw FolderNotFoundException() + folder.inverseShareType() + } + fun getAccountListAtRootFolder(folderId: Long): AccountDto.FolderBelongAccountListDto { // 사용자가 account-folder에 속하여있지 않다면, 예외를 던진다. -> 필요할까? // folder를 통하여 account list를 받아와서 account를 dto로 변환한 리스트를 return한다.