11package io .twogether .nbe_5_7_2_02team .chat .service ;
22
3+ import static io .twogether .nbe_5_7_2_02team .chat .domain .ChatMemberStatus .LEFT ;
4+ import static io .twogether .nbe_5_7_2_02team .chat .domain .ChatMemberStatus .OFFLINE ;
35import static io .twogether .nbe_5_7_2_02team .chat .domain .ChatMemberStatus .ONLINE ;
4- import static io .twogether .nbe_5_7_2_02team .global .response .error .ErrorCode .CHAT_MEMBER_ALREADY_EXISTS ;
56import static io .twogether .nbe_5_7_2_02team .global .response .error .ErrorCode .CHAT_MEMBER_NOT_ENTER ;
67import static io .twogether .nbe_5_7_2_02team .global .response .error .ErrorCode .CHAT_MEMBER_UNDEFINED_STATUS ;
78import static io .twogether .nbe_5_7_2_02team .global .response .error .ErrorCode .CHAT_ROOM_EMPTY ;
1617import io .twogether .nbe_5_7_2_02team .global .exception .ErrorException ;
1718import io .twogether .nbe_5_7_2_02team .member .domain .Member ;
1819
20+ import java .util .Arrays ;
1921import lombok .RequiredArgsConstructor ;
2022
2123import org .springframework .security .core .annotation .AuthenticationPrincipal ;
@@ -39,7 +41,7 @@ public List<ChatRoomGetResponse> getChatRoomListByUser(
3941 @ AuthenticationPrincipal UserDetails userDetails ) {
4042 Member member = checkUserLogin .checkUserLogin (userDetails );
4143
42- List <ChatMember > chatMemberList = chatMemberRepository .findByMember (member );
44+ List <ChatMember > chatMemberList = chatMemberRepository .findByMemberAndChatMemberStatusIn (member , Arrays . asList ( ONLINE , OFFLINE ) );
4345
4446 return chatMemberList .stream ()
4547 .map (chatMember -> ChatRoomGetResponse .from (chatMember .getChatRoom ()))
@@ -68,7 +70,11 @@ public Long createChatMember(Long chatroomId, UserDetails userDetails) {
6870 ChatMember chatMember = chatMemberRepository .findByChatRoomAndMember (chatRoom , member );
6971
7072 if (chatMember != null ) {
71- throw new ErrorException (CHAT_MEMBER_ALREADY_EXISTS );
73+ if (chatMember .getChatMemberStatus () == LEFT ) {
74+ chatMember .setChatMemberStatus (ONLINE );
75+ }
76+
77+ return chatMember .getId ();
7278 }
7379
7480 Long id =
@@ -105,7 +111,7 @@ public Long updateChatMember(
105111 throw new ErrorException (CHAT_MEMBER_UNDEFINED_STATUS );
106112 }
107113
108- chatMember .updateStatus (chatMemberStatus );
114+ chatMember .setChatMemberStatus (chatMemberStatus );
109115 return chatMemberRepository .save (chatMember ).getId ();
110116 }
111117}
0 commit comments