Skip to content

Commit

Permalink
Feat: HashTage 추가, 인원 제한 exception 추가 (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
leebuwon authored Feb 17, 2024
1 parent 5744ecd commit 2bad4b8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2bad4b8

Please sign in to comment.