From 2bad4b88fe2fcc27cafb63463b2b3c2fd0f44f71 Mon Sep 17 00:00:00 2001 From: bw1611 <97327583+leebuwon@users.noreply.github.com> Date: Sat, 17 Feb 2024 19:58:44 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20HashTage=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EC=9D=B8=EC=9B=90=20=EC=A0=9C=ED=95=9C=20exception=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#147)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/chatmember/service/ChatMemberService.java | 10 +++++++++- .../chatroom/dto/response/ChatRoomResponse.java | 2 ++ .../exception/OverParticipationException.java | 11 +++++++++++ .../tadak/chatroomservice/global/error/ErrorCode.java | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/exception/OverParticipationException.java diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/service/ChatMemberService.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/service/ChatMemberService.java index 8cc7fd0..ae5f30c 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/service/ChatMemberService.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatmember/service/ChatMemberService.java @@ -8,12 +8,15 @@ import com.tadak.chatroomservice.domain.chatroom.exception.AlreadyKickedException; import com.tadak.chatroomservice.domain.chatroom.exception.CannotTransferOwnershipException; import com.tadak.chatroomservice.domain.chatroom.exception.NotFoundChatMemberException; +import com.tadak.chatroomservice.domain.chatroom.exception.OverParticipationException; import com.tadak.chatroomservice.global.error.ErrorCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Objects; + @Service @Slf4j @RequiredArgsConstructor @@ -29,10 +32,15 @@ public EnterChatMemberResponse enterMember(ChatRoom chatRoom, String username) { .username(username) .build(); - chatMemberRepository.save(chatMember); + if (Objects.equals(chatRoom.getCapacity(), chatRoom.getParticipation())){ + throw new OverParticipationException(ErrorCode.OVER_CHATROOM_PARTICIPATION_ERROR); + } + // 채팅방 인원 증가 chatRoom.increaseParticipation(); + chatMemberRepository.save(chatMember); + return EnterChatMemberResponse.of(chatMember, chatRoom.getParticipation()); } diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomResponse.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomResponse.java index 877003d..e72aae3 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomResponse.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/dto/response/ChatRoomResponse.java @@ -15,6 +15,7 @@ public class ChatRoomResponse { private Long roomId; private String roomName; private String description; + private String hashtag; private Integer participation; private Integer capacity; private String owner; @@ -24,6 +25,7 @@ public static ChatRoomResponse from(ChatRoom chatRoom) { .roomId(chatRoom.getId()) .roomName(chatRoom.getRoomName()) .description(chatRoom.getDescription()) + .hashtag(chatRoom.getHashtag()) .participation(chatRoom.getParticipation()) .capacity(chatRoom.getCapacity()) .owner(chatRoom.getOwner()) diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/exception/OverParticipationException.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/exception/OverParticipationException.java new file mode 100644 index 0000000..6f34af2 --- /dev/null +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/domain/chatroom/exception/OverParticipationException.java @@ -0,0 +1,11 @@ +package com.tadak.chatroomservice.domain.chatroom.exception; + +import com.tadak.chatroomservice.global.error.ErrorCode; +import com.tadak.chatroomservice.global.error.common.BusinessException; + +public class OverParticipationException extends BusinessException { + + public OverParticipationException(ErrorCode errorCode) { + super(errorCode); + } +} diff --git a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/global/error/ErrorCode.java b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/global/error/ErrorCode.java index 719cc53..4e1a564 100644 --- a/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/global/error/ErrorCode.java +++ b/backend/chatroom-service/src/main/java/com/tadak/chatroomservice/global/error/ErrorCode.java @@ -20,6 +20,7 @@ public enum ErrorCode { NOT_OWNER_ERROR(1301, "G1300", "방장 권한이 없습니다."), KICKED_MEMBER_ERROR(1302, "G1300", "현재 강퇴당한 채팅 방 입니다."), CANNOT_TRANSFER_OWNER_ERROR(1303, "G1300", "해당 유저는 강퇴당한 유저이기 떄문에 방장 위임을 할 수 없습니다."), + OVER_CHATROOM_PARTICIPATION_ERROR(1304, "G1300", "해당 채팅 방은 인원이 가득차 있습니다."), /** * 1400 ~ 1499