diff --git a/api/src/main/kotlin/com/backgu/amaker/api/chat/service/ChatRoomFacadeService.kt b/api/src/main/kotlin/com/backgu/amaker/api/chat/service/ChatRoomFacadeService.kt index 7b87e516..aa2df298 100644 --- a/api/src/main/kotlin/com/backgu/amaker/api/chat/service/ChatRoomFacadeService.kt +++ b/api/src/main/kotlin/com/backgu/amaker/api/chat/service/ChatRoomFacadeService.kt @@ -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 = chatRoomUserService.findAllByUser(user) @@ -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 = chatRoomService.findChatRoomsByWorkspaceId(workspaceId) val chatRoomUserMap: Map> = @@ -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 = chatRoomService.findNotRegisteredChatRoomsByWorkspaceId(workspaceId, userId) val chatRoomUserMap: Map> = @@ -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) diff --git a/api/src/main/kotlin/com/backgu/amaker/api/workspace/service/WorkspaceFacadeService.kt b/api/src/main/kotlin/com/backgu/amaker/api/workspace/service/WorkspaceFacadeService.kt index a7ab81a0..28c25136 100644 --- a/api/src/main/kotlin/com/backgu/amaker/api/workspace/service/WorkspaceFacadeService.kt +++ b/api/src/main/kotlin/com/backgu/amaker/api/workspace/service/WorkspaceFacadeService.kt @@ -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) } @@ -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) @@ -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)) diff --git a/api/src/test/kotlin/com/backgu/amaker/api/workspace/service/WorkspaceUserServiceTest.kt b/api/src/test/kotlin/com/backgu/amaker/api/workspace/service/WorkspaceUserServiceTest.kt index 99fa2dce..c3bc4f0e 100644 --- a/api/src/test/kotlin/com/backgu/amaker/api/workspace/service/WorkspaceUserServiceTest.kt +++ b/api/src/test/kotlin/com/backgu/amaker/api/workspace/service/WorkspaceUserServiceTest.kt @@ -33,7 +33,7 @@ class WorkspaceUserServiceTest : IntegrationTest() { // when & then assertThatCode { - workspaceUserService.validUserInWorkspace(user, workspace) + workspaceUserService.validateUserWorkspaceInActive(user, workspace) }.doesNotThrowAnyException() } @@ -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") diff --git a/infra/src/main/kotlin/com/backgu/amaker/application/workspace/WorkspaceUserService.kt b/infra/src/main/kotlin/com/backgu/amaker/application/workspace/WorkspaceUserService.kt index d016d263..075c7faf 100644 --- a/infra/src/main/kotlin/com/backgu/amaker/application/workspace/WorkspaceUserService.kt +++ b/infra/src/main/kotlin/com/backgu/amaker/application/workspace/WorkspaceUserService.kt @@ -33,7 +33,16 @@ class WorkspaceUserService( fun findWorkSpaceUserByWorkspaceId(workspaceId: Long): List = 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, ) { @@ -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( diff --git a/realtime/src/main/kotlin/com/backgu/amaker/realtime/session/service/SessionFacadeService.kt b/realtime/src/main/kotlin/com/backgu/amaker/realtime/session/service/SessionFacadeService.kt index 758cec85..20c62e64 100644 --- a/realtime/src/main/kotlin/com/backgu/amaker/realtime/session/service/SessionFacadeService.kt +++ b/realtime/src/main/kotlin/com/backgu/amaker/realtime/session/service/SessionFacadeService.kt @@ -22,7 +22,7 @@ class SessionFacadeService( workspaceId: Long, workspaceRealTimeSession: RealTimeSession, ) { - workspaceUserService.validUserInWorkspace(userId, workspaceId) + workspaceUserService.validateUserWorkspaceInActive(userId, workspaceId) workspaceSessionService.findDropOutSessionIfLimit(workspaceId, userId).forEach { if (it.realtimeId != serverConfig.id) {