Skip to content

Commit

Permalink
[#168] feature(exit Shared): 공유 보관함에서 exit하는 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji-Ha committed Jul 15, 2022
1 parent 726323c commit 5926652
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,20 @@ class AccountController(
return ResponseEntity.status(HttpStatus.OK).body(accountService.checkExtension(extensionVersion))
}

@ApiOperation(value = "폴더 토큰을 통하여 공유 폴더에 초대받는 API")
@GetMapping("/invite/{folderToken}")
fun acceptInvitation(request: HttpServletRequest, @PathVariable folderToken: String): ResponseEntity<String> {
fun acceptInvitation(request: HttpServletRequest, @ApiParam(value = "폴더 토큰") @PathVariable folderToken: String): ResponseEntity<String> {
val token = ControllerUtil.extractAccessToken(request)
accountService.acceptInvitation(token, folderToken)
return ResponseEntity.status(HttpStatus.OK).body("good")
return ResponseEntity.status(HttpStatus.OK).body(Message.SUCCESS)
}

@ApiOperation(value = "folderId를 통하여 공유 폴더에서 나가는 API")
@GetMapping("/exit/{folderId}")
fun exitSharedFolder(request: HttpServletRequest, @ApiParam(value = "폴더 아이디") @PathVariable folderId: Long): ResponseEntity<String> {
val token = ControllerUtil.extractAccessToken(request)
accountService.exitSharedFolder(folderId, token)
return ResponseEntity.status(HttpStatus.OK).body(Message.SUCCESS)
}

@ApiOperation("회원가입 API")
Expand Down
14 changes: 8 additions & 6 deletions src/main/kotlin/com/yapp/web2/domain/account/entity/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.yapp.web2.domain.account.entity

import com.yapp.web2.domain.BaseTimeEntity
import com.yapp.web2.domain.folder.entity.AccountFolder
import com.yapp.web2.domain.folder.entity.Folder
import com.yapp.web2.security.jwt.TokenDto
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
Expand Down Expand Up @@ -98,7 +99,7 @@ class Account(
@Column
var deleted: Boolean = false

@OneToMany(mappedBy = "account")
@OneToMany(mappedBy = "account", cascade = [CascadeType.ALL])
var accountFolderList: MutableList<AccountFolder> = mutableListOf()

@ApiModel(description = "소셜로그인 DTO")
Expand Down Expand Up @@ -166,11 +167,12 @@ class Account(
val nickName: String
)

fun hasAccountFolder(accountFolder: AccountFolder): Boolean {
for (af in this.accountFolderList)
if (accountFolder == af) return true

return false
fun removeFolderInAccountFolder(folder: Folder) {
for(af in this.accountFolderList)
if (af.folder == folder) {
accountFolderList.remove(af)
return
}
}

fun softDeleteAccount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,31 @@ class AccountService(
val folderId = jwtProvider.getIdFromToken(folderToken)
val rootFolder = folderService.findByFolderId(folderId)

if(rootFolder.rootFolderId != null) throw FolderNotRootException()
if (rootFolder.rootFolderId != null) throw FolderNotRootException()

val accountFolder = AccountFolder(account, rootFolder)
accountFolder.changeAuthority(Authority.INVITEE)
// account에 굳이 추가하지 않아도 account-folder에 추가가 된다.
// 왜???
if(account.isInsideAccountFolder(accountFolder)) throw AlreadyInvitedException()
if (account.isInsideAccountFolder(accountFolder)) throw AlreadyInvitedException()
// account.addAccountFolder(accountFolder)
rootFolder.folders?.add(accountFolder)
}


fun exitSharedFolder(folderId: Long, token: String) {
val account = jwtProvider.getAccountFromToken(token)
val folder = folderService.findByFolderId(folderId)
var exitFolder = folder.rootFolderId?.let {
folderService.findByFolderId(it)
} ?: folder

account.removeFolderInAccountFolder(exitFolder)
}

fun signIn(request: AccountRequestDto.SignInRequest): Account.AccountLoginSuccess? {
val account = accountRepository.findByEmail(request.email) ?: throw IllegalStateException(Message.NOT_EXIST_EMAIL)
val account =
accountRepository.findByEmail(request.email) ?: throw IllegalStateException(Message.NOT_EXIST_EMAIL)

if (!passwordEncoder.matches(request.password, account.password)) {
throw IllegalStateException(Message.USER_PASSWORD_MISMATCH)
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/yapp/web2/domain/folder/entity/Folder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,10 @@ class Folder(
fun updateBookmarkCount(count: Int) {
this.bookmarkCount += count
}

fun setRootFolder(folder: Folder) {
folder.rootFolderId?.let {
this.rootFolderId = it
} ?: let { this.rootFolderId = folder.id }
}
}

0 comments on commit 5926652

Please sign in to comment.