diff --git a/src/main/java/com/dnd/gongmuin/chat/controller/ChatRoomController.java b/src/main/java/com/dnd/gongmuin/chat/controller/ChatRoomController.java index 1bf58690..66d76e81 100644 --- a/src/main/java/com/dnd/gongmuin/chat/controller/ChatRoomController.java +++ b/src/main/java/com/dnd/gongmuin/chat/controller/ChatRoomController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.dnd.gongmuin.chat.dto.request.CreateChatRoomRequest; @@ -58,9 +59,10 @@ public ResponseEntity createChatRoom( @Operation(summary = "채팅방 목록 조회 API", description = "회원의 채팅방 목록을 조회한다.") @GetMapping("/api/chat-rooms") public ResponseEntity> getChatRoomsByMember( + @RequestParam("status") String status, @AuthenticationPrincipal Member member ) { - List response = chatRoomService.getChatRoomsByMember(member); + List response = chatRoomService.getChatRoomsByMember(member, status); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/ChatStatus.java b/src/main/java/com/dnd/gongmuin/chat/domain/ChatStatus.java index 562a14d2..beef2fbe 100644 --- a/src/main/java/com/dnd/gongmuin/chat/domain/ChatStatus.java +++ b/src/main/java/com/dnd/gongmuin/chat/domain/ChatStatus.java @@ -1,5 +1,10 @@ package com.dnd.gongmuin.chat.domain; +import java.util.Arrays; + +import com.dnd.gongmuin.chat.exception.ChatErrorCode; +import com.dnd.gongmuin.common.exception.runtime.ValidationException; + import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -12,4 +17,15 @@ public enum ChatStatus { REJECTED("거절됨"); private final String label; + + public static ChatStatus from(String input) { + return Arrays.stream(values()) + .filter(status -> status.isEqual(input)) + .findAny() + .orElseThrow(() -> new ValidationException(ChatErrorCode.NOT_FOUND_CHAT_STATUS)); + } + + private boolean isEqual(String input) { + return input.equals(this.label); + } } diff --git a/src/main/java/com/dnd/gongmuin/chat/exception/ChatErrorCode.java b/src/main/java/com/dnd/gongmuin/chat/exception/ChatErrorCode.java index 20c74094..11635b5d 100644 --- a/src/main/java/com/dnd/gongmuin/chat/exception/ChatErrorCode.java +++ b/src/main/java/com/dnd/gongmuin/chat/exception/ChatErrorCode.java @@ -13,7 +13,8 @@ public enum ChatErrorCode implements ErrorCode { NOT_FOUND_CHAT_ROOM("해당 아이디의 채팅방이 존재하지 않습니다.", "CH_002"), UNAUTHORIZED_REQUEST("채팅 수락을 하거나 거절할 권한이 없습니다.", "CH_003"), UNABLE_TO_CHANGE_CHAT_STATUS("이미 수락했거나 거절한 요청입니다.", "CH_004"), - UNAUTHORIZED_CHAT_ROOM("권한이 없는 채팅방입니다", "CH_005"); + UNAUTHORIZED_CHAT_ROOM("권한이 없는 채팅방입니다.", "CH_005"), + NOT_FOUND_CHAT_STATUS("채팅방 상태값을 올바르게 입력해주세요.", "CH_006"); private final String message; private final String code; diff --git a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java index e4224266..a6259234 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java +++ b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java @@ -2,9 +2,10 @@ import java.util.List; +import com.dnd.gongmuin.chat.domain.ChatStatus; import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; import com.dnd.gongmuin.member.domain.Member; public interface ChatRoomQueryRepository { - List getChatRoomsByMember(Member member); + List getChatRoomsByMember(Member member, ChatStatus chatStatus); } diff --git a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java index 80aa490f..e7d51bf9 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java +++ b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java @@ -4,6 +4,7 @@ import java.util.List; +import com.dnd.gongmuin.chat.domain.ChatStatus; import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; import com.dnd.gongmuin.chat.dto.response.QChatRoomInfo; import com.dnd.gongmuin.member.domain.Member; @@ -16,7 +17,7 @@ public class ChatRoomQueryRepositoryImpl implements ChatRoomQueryRepository { private final JPAQueryFactory queryFactory; - public List getChatRoomsByMember(Member member) { + public List getChatRoomsByMember(Member member, ChatStatus chatStatus) { return queryFactory .select(new QChatRoomInfo( chatRoom.id, @@ -39,7 +40,8 @@ public List getChatRoomsByMember(Member member) { )) .from(chatRoom) .where(chatRoom.inquirer.id.eq(member.getId()) - .or(chatRoom.answerer.id.eq(member.getId()))) + .or(chatRoom.answerer.id.eq(member.getId())) + .and(chatRoom.status.eq(chatStatus))) .fetch(); } } diff --git a/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java b/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java index ffe4de2b..447f0952 100644 --- a/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java +++ b/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java @@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import com.dnd.gongmuin.chat.domain.ChatRoom; +import com.dnd.gongmuin.chat.domain.ChatStatus; import com.dnd.gongmuin.chat.dto.ChatMessageMapper; import com.dnd.gongmuin.chat.dto.ChatRoomMapper; import com.dnd.gongmuin.chat.dto.request.CreateChatRoomRequest; @@ -89,9 +90,9 @@ public ChatRoomDetailResponse createChatRoom(CreateChatRoomRequest request, Memb } @Transactional(readOnly = true) - public List getChatRoomsByMember(Member member) { + public List getChatRoomsByMember(Member member, String chatStatus) { // 회원 채팅방 정보 가져오기 - List chatRoomInfos = chatRoomRepository.getChatRoomsByMember(member); + List chatRoomInfos = chatRoomRepository.getChatRoomsByMember(member, ChatStatus.from(chatStatus)); // chatRoomId 리스트 추출 List chatRoomIds = chatRoomInfos.stream() .map(ChatRoomInfo::chatRoomId) diff --git a/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java b/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java index 68fcfd5e..a5f7e257 100644 --- a/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java @@ -123,7 +123,8 @@ void getChatRoomsByMember() throws Exception { ) ); mockMvc.perform(get("/api/chat-rooms") - .cookie(accessToken)) + .cookie(accessToken) + .param("status", ChatStatus.PENDING.getLabel())) .andExpect(status().isOk()) .andDo(MockMvcResultHandlers.print()); } diff --git a/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java b/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java index 8367a211..dbfdfd4d 100644 --- a/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import com.dnd.gongmuin.chat.domain.ChatRoom; +import com.dnd.gongmuin.chat.domain.ChatStatus; import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; import com.dnd.gongmuin.common.fixture.ChatRoomFixture; import com.dnd.gongmuin.common.fixture.MemberFixture; @@ -43,7 +44,7 @@ void getChatRoomsByMember() { chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, target, answerer)) )); //when - List chatRoomInfos = chatRoomRepository.getChatRoomsByMember(target); + List chatRoomInfos = chatRoomRepository.getChatRoomsByMember(target, ChatStatus.PENDING); //then Assertions.assertAll( () -> assertThat(chatRoomInfos).hasSize(2), diff --git a/src/test/java/com/dnd/gongmuin/post_interaction/controller/InteractionControllerTest.java b/src/test/java/com/dnd/gongmuin/post_interaction/controller/InteractionControllerTest.java index c0978acc..7aaf4839 100644 --- a/src/test/java/com/dnd/gongmuin/post_interaction/controller/InteractionControllerTest.java +++ b/src/test/java/com/dnd/gongmuin/post_interaction/controller/InteractionControllerTest.java @@ -71,7 +71,7 @@ void activateInteraction_old() throws Exception { mockMvc.perform(post("/api/question-posts/{questionPostId}/inactivated", questionPost.getId()) .contentType(APPLICATION_JSON) .cookie(accessToken) - .param("type", "추천") + .param("type", InteractionType.RECOMMEND.getLabel()) ) .andExpect(status().isOk()); }