Skip to content

Commit

Permalink
Merge pull request #108 from soma-baekgu/feature/BG-384-invitee-works…
Browse files Browse the repository at this point in the history
…pace-view

[BG-384] 초대받은 사용자가 워크스페이스 정보를 조회할 수 있도록 확장
  • Loading branch information
GGHDMS authored Sep 2, 2024
2 parents 321592d + af466e4 commit c26dbba
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ChatRoomFacadeService(
val user: User = userService.getById(userId)
val workspace: Workspace = workspaceService.getById(workspaceId)

workspaceUserService.validUserInWorkspace(user, workspace)
workspaceUserService.validateUserWorkspaceInActive(user, workspace)

// 유저의 채팅방 목록 조회
val chatRoomMys: List<ChatRoomUser> = chatRoomUserService.findAllByUser(user)
Expand Down Expand Up @@ -86,7 +86,7 @@ class ChatRoomFacadeService(
): BriefChatRoomViewDto {
val user: User = userService.getById(userId)
val workspace: Workspace = workspaceService.getById(workspaceId)
workspaceUserService.validUserInWorkspace(user, workspace)
workspaceUserService.validateUserWorkspaceInActive(user, workspace)

val chatRooms: List<ChatRoom> = chatRoomService.findChatRoomsByWorkspaceId(workspaceId)
val chatRoomUserMap: Map<Long, List<ChatRoomUser>> =
Expand All @@ -111,7 +111,7 @@ class ChatRoomFacadeService(
): BriefChatRoomViewDto {
val user: User = userService.getById(userId)
val workspace: Workspace = workspaceService.getById(workspaceId)
workspaceUserService.validUserInWorkspace(user, workspace)
workspaceUserService.validateUserWorkspaceInActive(user, workspace)

val chatRooms: List<ChatRoom> = chatRoomService.findNotRegisteredChatRoomsByWorkspaceId(workspaceId, userId)
val chatRoomUserMap: Map<Long, List<ChatRoomUser>> =
Expand Down Expand Up @@ -154,7 +154,7 @@ class ChatRoomFacadeService(
): ChatRoomUser {
val user: User = userService.getById(userId)
val workspace: Workspace = workspaceService.getById(workspaceId)
workspaceUserService.validUserInWorkspace(user, workspace)
workspaceUserService.validateUserWorkspaceInActive(user, workspace)

val chatRoom = chatRoomService.getChatRoomByWorkspaceIdAndChatRoomId(workspaceId, chatRoomId)
chatRoomUserService.validateUserNotInChatRoom(user, chatRoom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ class WorkspaceFacadeService(
userId: String,
workspaceId: Long,
): WorkspaceDto {
val user: User = userService.getById(userId)
workspaceUserService.validateUserInWorkspace(userId, workspaceId)
val workspace: Workspace = workspaceService.getWorkspaceById(workspaceId)

workspaceUserService.validUserInWorkspace(user, workspace)

return WorkspaceDto.of(workspace)
}

Expand Down Expand Up @@ -94,7 +92,7 @@ class WorkspaceFacadeService(
val user: User = userService.getById(userId)
val workspace: Workspace = workspaceService.getWorkspaceById(workspaceId)

workspaceUserService.validUserInWorkspace(user, workspace)
workspaceUserService.validateUserWorkspaceInActive(user, workspace)

val workspaceUsers = workspaceUserService.findWorkSpaceUserByWorkspaceId(workspaceId)

Expand All @@ -120,7 +118,7 @@ class WorkspaceFacadeService(
val user: User = userService.getById(userId)
val workspace: Workspace = workspaceService.getWorkspaceById(workspaceId)

workspaceUserService.validUserInWorkspace(user, workspace)
workspaceUserService.validateUserWorkspaceInActive(user, workspace)

return ChatRoomDto
.of(chatRoomService.getDefaultChatRoomByWorkspace(workspace))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WorkspaceUserServiceTest : IntegrationTest() {

// when & then
assertThatCode {
workspaceUserService.validUserInWorkspace(user, workspace)
workspaceUserService.validateUserWorkspaceInActive(user, workspace)
}.doesNotThrowAnyException()
}

Expand All @@ -50,7 +50,7 @@ class WorkspaceUserServiceTest : IntegrationTest() {
fixtures.workspaceUser.createPersistedWorkspaceUser(workspaceId = workspace.id, leaderId = diffUser)

// when & then
assertThatThrownBy { workspaceUserService.validUserInWorkspace(user, workspace) }
assertThatThrownBy { workspaceUserService.validateUserWorkspaceInActive(user, workspace) }
.isInstanceOf(BusinessException::class.java)
.hasMessage("워크스페이스에 접근할 수 없습니다.")
.extracting("statusCode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ class WorkspaceUserService(
fun findWorkSpaceUserByWorkspaceId(workspaceId: Long): List<WorkspaceUser> =
workspaceUserRepository.findByWorkspaceId(workspaceId).map { it.toDomain() }

fun validUserInWorkspace(
fun validateUserInWorkspace(
userId: String,
workspaceId: Long,
) {
if (!workspaceUserRepository.existsByUserIdAndWorkspaceId(userId, workspaceId)) {
throw BusinessException(StatusCode.WORKSPACE_UNREACHABLE)
}
}

fun validateUserWorkspaceInActive(
userId: String,
workspaceId: Long,
) {
Expand All @@ -47,11 +56,11 @@ class WorkspaceUserService(
}
}

fun validUserInWorkspace(
fun validateUserWorkspaceInActive(
user: User,
workspace: Workspace,
) {
validUserInWorkspace(user.id, workspace.id)
validateUserWorkspaceInActive(user.id, workspace.id)
}

fun validateUserNotRelatedInWorkspace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SessionFacadeService(
workspaceId: Long,
workspaceRealTimeSession: RealTimeSession<WebSocketSession>,
) {
workspaceUserService.validUserInWorkspace(userId, workspaceId)
workspaceUserService.validateUserWorkspaceInActive(userId, workspaceId)

workspaceSessionService.findDropOutSessionIfLimit(workspaceId, userId).forEach {
if (it.realtimeId != serverConfig.id) {
Expand Down

0 comments on commit c26dbba

Please sign in to comment.