Skip to content

Commit

Permalink
[#176] feature(보관함 잠금/해제)
Browse files Browse the repository at this point in the history
- SharedType에서 잠금해제 하는 기능 추가
- 폴더를 OPEN/INVITE/INVITE_AND_OPEN 상태로 변경하도록 하는 기능 추가
- ENUM 타입을 데이터베이스에 저장할 때 String 으로 저장할 수 있도록 수정
- 초대를 수락할 때, 보관함의 공유 상태확인 로직 추가
- 비회원이 보관함을 조회할 때, 보관함의 공유 상태확인 로직 추가
  • Loading branch information
Ji-Ha committed Aug 16, 2022
1 parent b737e04 commit ff317ac
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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.PageImpl
Expand All @@ -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
) {

Expand All @@ -39,6 +41,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
@@ -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(
Expand All @@ -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) {
Expand Down
29 changes: 26 additions & 3 deletions src/main/kotlin/com/yapp/web2/domain/folder/entity/Folder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class Folder(
var folders: MutableList<AccountFolder>? = mutableListOf()

// 공유 상태 저장
var sharedType: SharedType = SharedType.CLOSED

var beforeSharedType: SharedType? = null
@Enumerated(value = EnumType.STRING)
var sharedType: SharedType = SharedType.ALL_CLOSED

var rootFolderId: Long? = null

Expand Down Expand Up @@ -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
}
}
33 changes: 32 additions & 1 deletion src/main/kotlin/com/yapp/web2/domain/folder/entity/SharedType.kt
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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한다.
Expand Down

0 comments on commit ff317ac

Please sign in to comment.