Skip to content

Commit

Permalink
Merge pull request #177 from YAPP-19th/feature/#176-공유_보관함_잠금_기능
Browse files Browse the repository at this point in the history
[#176] 공유 보관함 잠금 기능
  • Loading branch information
Ji-Ha authored Aug 23, 2022
2 parents 61869b7 + 080edf8 commit 66f7d22
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Pageable
Expand All @@ -15,6 +16,7 @@ import java.time.LocalDate
@Transactional(readOnly = true)
class BookmarkPageService(
private val bookmarkRepository: BookmarkRepository,
private val folderService: FolderService,
private val jwtProvider: JwtProvider
) {

Expand All @@ -34,6 +36,8 @@ class BookmarkPageService(

fun getAllPageByEncryptFolderId(token: String, pageable: Pageable): Page<Bookmark> {
val folderId = jwtProvider.getIdFromToken(token)
val folder = folderService.findByFolderId(folderId)
if(!folder.isOpenState()) throw RuntimeException("보관함이 조회잠금상태입니다. 조회할 수 없습니다!")
return bookmarkRepository.findAllByFolderIdAndDeletedIsFalse(folderId, pageable)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AccountFolder(
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null

@Enumerated(EnumType.STRING)
@Enumerated(value = EnumType.STRING)
var authority: Authority = Authority.NONE

fun changeAuthority(authority: Authority) {
Expand Down
29 changes: 27 additions & 2 deletions src/main/kotlin/com/yapp/web2/domain/folder/entity/Folder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class Folder(
@OneToMany(mappedBy = "folder", cascade = [CascadeType.ALL], orphanRemoval = true)
var folders: MutableList<AccountFolder>? = mutableListOf()

// TODO: 2022/05/06 공유 북마크인지 확인하기 위해서 추가한 컬럼
var share: Boolean? = false
// 공유 상태 저장
@Enumerated(value = EnumType.STRING)
var sharedType: SharedType = SharedType.ALL_CLOSED

var rootFolderId: Long? = null

Expand Down Expand Up @@ -189,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
}
}
36 changes: 36 additions & 0 deletions src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.yapp.web2.domain.folder.entity

enum class SharedType {
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ class FolderService(
val folder = folderRepository.findFolderById(rootFolderId) ?: throw FolderNotFoundException()
if(!folder.isRootFolder()) throw RuntimeException("보관함이 아닙니다! 공유를 할 수 없습니다.")

// 폴더의 공유 상태 변경하기
folder.changeSharedTypeToInvite()

// 하위 폴더들 모두 rootFolderId 추가해주기
val sharedFolderIdList = changeFolderToShared(folder, rootFolderId)

Expand Down Expand Up @@ -383,9 +386,15 @@ class FolderService(
require(folderId > 0) { "folderId must be greater than zero" }

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 {
require(folderId > 0) { "folderId must be greater than zero" }

Expand Down

0 comments on commit 66f7d22

Please sign in to comment.