diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/api/ChatMemberApi.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/api/ChatMemberApi.java index ce466b655..b4b056b7a 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/api/ChatMemberApi.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/api/ChatMemberApi.java @@ -73,4 +73,16 @@ ResponseEntity joinChatRoom( ) @ApiResponse(responseCode = "200", description = "채팅방 멤버 탈퇴 성공") ResponseEntity leaveChatRoom(@PathVariable("chatRoomId") Long chatRoomId, @PathVariable("chatMemberId") Long chatMemberId); + + @Operation(summary = "채팅방 멤버 추방", method = "DELETE", description = "채팅방 멤버를 추방한다. 채팅방장만이 채팅방 멤버를 추방할 수 있다.") + @Parameters({ + @Parameter(name = "chatRoomId", description = "채팅방 ID", required = true, in = ParameterIn.PATH), + @Parameter(name = "chatMemberId", description = "추방할 채팅방 멤버 ID (user id가 아님)", required = true, in = ParameterIn.PATH) + }) + @ApiResponseExplanations(errors = { + @ApiExceptionExplanation(value = ChatMemberErrorCode.class, constant = "NOT_FOUND", summary = "채팅방 멤버를 찾을 수 없음", description = "채팅방 멤버를 찾을 수 없어 채팅방 멤버 추방에 실패했습니다."), + @ApiExceptionExplanation(value = ChatMemberErrorCode.class, constant = "NOT_ADMIN", summary = "권한 없음", description = "권한이 없어 채팅방 멤버 추방에 실패했습니다.") + }) + @ApiResponse(responseCode = "200", description = "채팅방 멤버 추방 성공") + ResponseEntity banChatMember(@PathVariable("chatRoomId") Long chatRoomId, @PathVariable("chatMemberId") Long chatMemberId, @AuthenticationPrincipal SecurityUserDetails user); } diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/controller/ChatMemberController.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/controller/ChatMemberController.java index 9f975634a..467d01c92 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/controller/ChatMemberController.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/controller/ChatMemberController.java @@ -61,4 +61,13 @@ public ResponseEntity leaveChatRoom(@PathVariable("chatRoomId") Long chatRoom return ResponseEntity.ok(SuccessResponse.noContent()); } + + @Override + @DeleteMapping("/{chatMemberId}/ban") + @PreAuthorize("isAuthenticated() and @chatRoomManager.hasPermission(principal.userId, #chatRoomId)") + public ResponseEntity banChatMember(@PathVariable("chatRoomId") Long chatRoomId, @PathVariable("chatMemberId") Long chatMemberId, @AuthenticationPrincipal SecurityUserDetails user) { + chatMemberUseCase.banChatMember(user.getUserId(), chatMemberId, chatRoomId); + + return ResponseEntity.ok(SuccessResponse.noContent()); + } } diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/usecase/ChatMemberUseCase.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/usecase/ChatMemberUseCase.java index 7878aaed5..631bfd0c0 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/usecase/ChatMemberUseCase.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/usecase/ChatMemberUseCase.java @@ -7,6 +7,8 @@ import kr.co.pennyway.api.apis.chat.service.ChatMemberJoinService; import kr.co.pennyway.api.apis.chat.service.ChatMemberSearchService; import kr.co.pennyway.common.annotation.UseCase; +import kr.co.pennyway.domain.context.chat.dto.ChatMemberBanCommand; +import kr.co.pennyway.domain.context.chat.service.ChatMemberBanService; import kr.co.pennyway.domain.context.chat.service.ChatRoomLeaveService; import kr.co.pennyway.domain.domains.chatroom.domain.ChatRoom; import kr.co.pennyway.domain.domains.member.dto.ChatMemberResult; @@ -24,6 +26,7 @@ public class ChatMemberUseCase { private final ChatMemberJoinService chatMemberJoinService; private final ChatMemberSearchService chatMemberSearchService; private final ChatRoomLeaveService chatRoomLeaveService; + private final ChatMemberBanService chatMemberBanService; public ChatRoomRes.Detail joinChatRoom(Long userId, Long chatRoomId, Integer password) { Triple chatRoom = chatMemberJoinService.execute(userId, chatRoomId, password); @@ -40,4 +43,8 @@ public List readChatMembers(Long chatRoomId, Set new ChatMemberErrorException(ChatMemberErrorCode.NOT_FOUND)); + + if (!admin.isAdmin()) { + throw new ChatMemberErrorException(ChatMemberErrorCode.NOT_ADMIN); + } + + ChatMember targetMember = chatMemberRdbService.readChatMemberByChatMemberId(command.targetMemberId()) + .orElseThrow(() -> new ChatMemberErrorException(ChatMemberErrorCode.NOT_FOUND)); + + targetMember.ban(); + + chatMemberRdbService.update(targetMember); + } +}