diff --git a/src/main/java/com/dnd/gongmuin/answer/dto/AnswerDetailResponse.java b/src/main/java/com/dnd/gongmuin/answer/dto/AnswerDetailResponse.java index fa09a159..dc74d5da 100644 --- a/src/main/java/com/dnd/gongmuin/answer/dto/AnswerDetailResponse.java +++ b/src/main/java/com/dnd/gongmuin/answer/dto/AnswerDetailResponse.java @@ -1,6 +1,6 @@ package com.dnd.gongmuin.answer.dto; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; +import com.dnd.gongmuin.member.dto.response.MemberInfo; public record AnswerDetailResponse( Long answerId, diff --git a/src/main/java/com/dnd/gongmuin/answer/dto/AnswerMapper.java b/src/main/java/com/dnd/gongmuin/answer/dto/AnswerMapper.java index b6187fb1..5738fae7 100644 --- a/src/main/java/com/dnd/gongmuin/answer/dto/AnswerMapper.java +++ b/src/main/java/com/dnd/gongmuin/answer/dto/AnswerMapper.java @@ -2,7 +2,7 @@ import com.dnd.gongmuin.answer.domain.Answer; import com.dnd.gongmuin.member.domain.Member; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; +import com.dnd.gongmuin.member.dto.response.MemberInfo; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryController.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryController.java index 4ee2e0e4..c9818a41 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryController.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController; import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryDetailResponse; import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryResponse; @@ -42,7 +43,17 @@ public ResponseEntity createChatInquiry( return ResponseEntity.ok(response); } - @Operation(summary = "채팅방 요청 목록 조회 API", description = "회원의 채팅방 목록을 조회한다.") + @Operation(summary = "채팅 요청 상세 조회 API", description = "채팅방 요청을 조회한다.") + @GetMapping("/api/chat/inquiries/{chatInquiryId}") + public ResponseEntity getChatInquiryById( + @PathVariable("chatInquiryId") Long chatInquiryId, + @AuthenticationPrincipal Member member + ) { + ChatInquiryDetailResponse response = chatInquiryService.getChatInquiryById(chatInquiryId, member); + return ResponseEntity.ok(response); + } + + @Operation(summary = "채팅 요청 목록 조회 API", description = "회원의 채팅 목록을 조회한다.") @GetMapping("/api/chat/inquiries") public ResponseEntity> getChatInquiresByMember( @AuthenticationPrincipal Member member, diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java index 378b4bf6..2b905042 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java @@ -31,7 +31,7 @@ public class ChatInquiry extends TimeBaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "chat_proposal_id", nullable = false) + @Column(name = "chat_inquiry_id", nullable = false) private Long id; @ManyToOne(fetch = LAZY) @@ -90,4 +90,12 @@ public void updateStatusRejected() { status = InquiryStatus.REJECTED; inquirer.increaseCredit(CHAT_REWARD); } + + public boolean isInquirer(Member member) { + return member.equals(this.inquirer); + } + + public Member getChatPartner(Member member) { + return isInquirer(member) ? this.answerer : this.inquirer; + } } diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryDetailResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryDetailResponse.java new file mode 100644 index 00000000..08aba1a3 --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryDetailResponse.java @@ -0,0 +1,12 @@ +package com.dnd.gongmuin.chat_inquiry.dto; + +import com.dnd.gongmuin.member.dto.response.MemberInfo; + +public record ChatInquiryDetailResponse( + Long chatInquiryId, + String inquiryMessage, + String inquiryStatus, + boolean isInquirer, + MemberInfo chatPartner +) { +} diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryMapper.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryMapper.java index 4a3486ec..6e55d9de 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryMapper.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryMapper.java @@ -4,8 +4,8 @@ import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; import com.dnd.gongmuin.chatroom.domain.ChatRoom; import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.member.dto.response.MemberInfo; import com.dnd.gongmuin.question_post.domain.QuestionPost; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -44,6 +44,24 @@ public static CreateChatInquiryResponse toCreateChatInquiryResponse( ); } + public static ChatInquiryDetailResponse toChatInquiryDetailResponse( + ChatInquiry chatInquiry, + Member chatPartner, + boolean isInquirer + ) { + return new ChatInquiryDetailResponse(chatInquiry.getId(), + chatInquiry.getMessage(), + chatInquiry.getStatus().getLabel(), + isInquirer, + new MemberInfo( + chatPartner.getId(), + chatPartner.getNickname(), + chatPartner.getJobGroup().getLabel(), + chatPartner.getProfileImageNo() + ) + ); + } + public static AcceptChatResponse toAcceptChatResponse( ChatInquiry chatInquiry, ChatRoom chatRoom diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java index 7e827ae7..384bc5f8 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java @@ -1,8 +1,10 @@ package com.dnd.gongmuin.chat_inquiry.dto; +import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; +import com.dnd.gongmuin.member.domain.JobGroup; +import com.dnd.gongmuin.member.dto.response.MemberInfo; import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; import com.dnd.gongmuin.member.domain.Member; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; import com.querydsl.core.annotations.QueryProjection; public record ChatInquiryResponse( diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryResponse.java index 24080f16..cb77519d 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryResponse.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryResponse.java @@ -1,6 +1,6 @@ package com.dnd.gongmuin.chat_inquiry.dto; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; +import com.dnd.gongmuin.member.dto.response.MemberInfo; public record CreateChatInquiryResponse( Long chatInquiryId, diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryService.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryService.java index db7e13c8..44f2db35 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryService.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryService.java @@ -11,6 +11,7 @@ import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryDetailResponse; import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryMapper; import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; @@ -70,6 +71,17 @@ public CreateChatInquiryResponse createChatInquiry(CreateChatInquiryRequest requ return ChatInquiryMapper.toCreateChatInquiryResponse(chatInquiry); } + @Transactional(readOnly = true) + public ChatInquiryDetailResponse getChatInquiryById(Long chatInquiryId, Member member) { + ChatInquiry chatInquiry = getChatInquiryById(chatInquiryId); + + return ChatInquiryMapper.toChatInquiryDetailResponse( + chatInquiry, + chatInquiry.getChatPartner(member), + chatInquiry.isInquirer(member) + ); + } + @Transactional(readOnly = true) public PageResponse getChatInquiresByMember(Member member, Pageable pageable) { Slice responsePage = chatInquiryRepository.getChatInquiresByMember( diff --git a/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java index 97a6be8c..9fa16197 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java @@ -58,4 +58,12 @@ public static ChatRoom of( ) { return new ChatRoom(questionPost, inquirer, answerer); } + + public boolean isInquirer(Member member) { + return member.equals(this.inquirer); + } + + public Member getChatPartner(Member member) { + return isInquirer(member) ? this.answerer : this.inquirer; + } } diff --git a/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java index 7f7eb957..58e21e0c 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java @@ -6,8 +6,8 @@ import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.member.dto.response.MemberInfo; import com.dnd.gongmuin.question_post.domain.QuestionPost; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -29,10 +29,10 @@ public static ChatRoom toChatRoom( public static ChatRoomDetailResponse toChatRoomDetailResponse( ChatRoom chatRoom, - Member chatPartner + Member chatPartner, + boolean isInquirer ) { QuestionPost questionPost = chatRoom.getQuestionPost(); - boolean isInquirer = !chatPartner.equals(chatRoom.getInquirer()); return new ChatRoomDetailResponse( questionPost.getId(), questionPost.getJobGroup().getLabel(), diff --git a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomDetailResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomDetailResponse.java index 86b3fb3e..6c90366e 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomDetailResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomDetailResponse.java @@ -1,6 +1,6 @@ package com.dnd.gongmuin.chatroom.dto.response; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; +import com.dnd.gongmuin.member.dto.response.MemberInfo; public record ChatRoomDetailResponse( Long questionPostId, diff --git a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomSimpleResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomSimpleResponse.java index aa7fa435..b4737ff8 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomSimpleResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomSimpleResponse.java @@ -1,6 +1,6 @@ package com.dnd.gongmuin.chatroom.dto.response; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; +import com.dnd.gongmuin.member.dto.response.MemberInfo; public record ChatRoomSimpleResponse( Long chatRoomId, diff --git a/src/main/java/com/dnd/gongmuin/chatroom/exception/ChatErrorCode.java b/src/main/java/com/dnd/gongmuin/chatroom/exception/ChatErrorCode.java index c3b182b8..24429e5a 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/exception/ChatErrorCode.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/exception/ChatErrorCode.java @@ -10,8 +10,7 @@ public enum ChatErrorCode implements ErrorCode { INVALID_MESSAGE_TYPE("메시지 타입을 올바르게 입력해주세요.", "CH_001"), - NOT_FOUND_CHAT_ROOM("해당 아이디의 채팅방이 존재하지 않습니다.", "CH_002"), - UNAUTHORIZED_CHAT_ROOM("채팅방 조회 권한이 없습니다.", "CH_003"); + NOT_FOUND_CHAT_ROOM("해당 아이디의 채팅방이 존재하지 않습니다.", "CH_002"); private final String message; private final String code; diff --git a/src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java b/src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java index 69d9d916..d0b7b0dd 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java @@ -25,7 +25,6 @@ import com.dnd.gongmuin.common.dto.PageMapper; import com.dnd.gongmuin.common.dto.PageResponse; import com.dnd.gongmuin.common.exception.runtime.NotFoundException; -import com.dnd.gongmuin.common.exception.runtime.ValidationException; import com.dnd.gongmuin.member.domain.Member; import lombok.RequiredArgsConstructor; @@ -73,8 +72,12 @@ public PageResponse getChatRoomsByMember(Member member, @Transactional(readOnly = true) public ChatRoomDetailResponse getChatRoomById(Long chatRoomId, Member member) { ChatRoom chatRoom = getChatRoomById(chatRoomId); - Member chatPartner = getChatPartner(member, chatRoom); - return ChatRoomMapper.toChatRoomDetailResponse(chatRoom, chatPartner); + + return ChatRoomMapper.toChatRoomDetailResponse( + chatRoom, + chatRoom.getChatPartner(member), + chatRoom.isInquirer(member) + ); } private List getChatRoomSimpleResponses(List latestChatMessages, @@ -101,14 +104,4 @@ private ChatRoom getChatRoomById(Long id) { return chatRoomRepository.findById(id) .orElseThrow(() -> new NotFoundException(ChatErrorCode.NOT_FOUND_CHAT_ROOM)); } - - private Member getChatPartner(Member member, ChatRoom chatRoom) { - if (member.equals(chatRoom.getAnswerer())) { - return chatRoom.getInquirer(); - } - if (member.equals(chatRoom.getInquirer())) { - return chatRoom.getAnswerer(); - } - throw new ValidationException(ChatErrorCode.UNAUTHORIZED_CHAT_ROOM); - } } diff --git a/src/main/java/com/dnd/gongmuin/question_post/dto/response/MemberInfo.java b/src/main/java/com/dnd/gongmuin/member/dto/response/MemberInfo.java similarity index 67% rename from src/main/java/com/dnd/gongmuin/question_post/dto/response/MemberInfo.java rename to src/main/java/com/dnd/gongmuin/member/dto/response/MemberInfo.java index f16a0c4f..0556c88b 100644 --- a/src/main/java/com/dnd/gongmuin/question_post/dto/response/MemberInfo.java +++ b/src/main/java/com/dnd/gongmuin/member/dto/response/MemberInfo.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.question_post.dto.response; +package com.dnd.gongmuin.member.dto.response; public record MemberInfo( Long memberId, diff --git a/src/main/java/com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java b/src/main/java/com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java index 6375bd9e..698eb808 100644 --- a/src/main/java/com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java +++ b/src/main/java/com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java @@ -6,10 +6,10 @@ import com.dnd.gongmuin.member.domain.JobGroup; import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.member.dto.response.MemberInfo; import com.dnd.gongmuin.question_post.domain.QuestionPost; import com.dnd.gongmuin.question_post.domain.QuestionPostImage; import com.dnd.gongmuin.question_post.dto.request.RegisterQuestionPostRequest; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; import com.dnd.gongmuin.question_post.dto.response.QuestionPostDetailResponse; import com.dnd.gongmuin.question_post.dto.response.RegisterQuestionPostResponse; import com.dnd.gongmuin.question_post.dto.response.UpdateQuestionPostResponse; diff --git a/src/main/java/com/dnd/gongmuin/question_post/dto/response/QuestionPostDetailResponse.java b/src/main/java/com/dnd/gongmuin/question_post/dto/response/QuestionPostDetailResponse.java index 935cb504..de942c56 100644 --- a/src/main/java/com/dnd/gongmuin/question_post/dto/response/QuestionPostDetailResponse.java +++ b/src/main/java/com/dnd/gongmuin/question_post/dto/response/QuestionPostDetailResponse.java @@ -2,6 +2,8 @@ import java.util.List; +import com.dnd.gongmuin.member.dto.response.MemberInfo; + public record QuestionPostDetailResponse( Long questionPostId, String title, diff --git a/src/main/java/com/dnd/gongmuin/question_post/dto/response/RegisterQuestionPostResponse.java b/src/main/java/com/dnd/gongmuin/question_post/dto/response/RegisterQuestionPostResponse.java index fc1633c5..649285fc 100644 --- a/src/main/java/com/dnd/gongmuin/question_post/dto/response/RegisterQuestionPostResponse.java +++ b/src/main/java/com/dnd/gongmuin/question_post/dto/response/RegisterQuestionPostResponse.java @@ -2,6 +2,8 @@ import java.util.List; +import com.dnd.gongmuin.member.dto.response.MemberInfo; + public record RegisterQuestionPostResponse( Long questionPostId, String title, diff --git a/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java b/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java index 67a03769..c00e2eaa 100644 --- a/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java @@ -24,12 +24,10 @@ import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; -import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; import com.dnd.gongmuin.chatroom.repository.ChatMessageQueryRepository; import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; import com.dnd.gongmuin.chatroom.service.ChatRoomService; -import com.dnd.gongmuin.common.exception.runtime.ValidationException; import com.dnd.gongmuin.common.fixture.ChatMessageFixture; import com.dnd.gongmuin.common.fixture.ChatRoomFixture; import com.dnd.gongmuin.common.fixture.MemberFixture; @@ -158,24 +156,4 @@ void getChatRoomById_Answerer() { .isEqualTo(inquirer.getId()) ); } - - @DisplayName("[채팅방에 속하지 않은 사람은 채팅방을 조회할 수 없다.]") - @Test - void getChatRoomById_Unauthorized() { - //given - Long chatRoomId = 1L; - Member inquirer = MemberFixture.member(1L); - Member answerer = MemberFixture.member(2L); - Member unrelatedMember = MemberFixture.member(3L); - QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatRoom chatRoom = ChatRoomFixture.chatRoom(questionPost, inquirer, answerer); - - given(chatRoomRepository.findById(chatRoomId)) - .willReturn(Optional.of(chatRoom)); - - //when & then - assertThatThrownBy(() -> chatRoomService.getChatRoomById(chatRoomId, unrelatedMember)) - .isInstanceOf(ValidationException.class) - .hasMessageContaining(ChatErrorCode.UNAUTHORIZED_CHAT_ROOM.getMessage()); - } } \ No newline at end of file diff --git a/src/test/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryControllerTest.java b/src/test/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryControllerTest.java index 992bffe2..4b3e0c88 100644 --- a/src/test/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryControllerTest.java +++ b/src/test/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryControllerTest.java @@ -57,6 +57,7 @@ void teardown() { creditHistoryRepository.deleteAll(); memberRepository.deleteAll(); questionPostRepository.deleteAll(); + chatInquiryRepository.deleteAll(); chatRoomRepository.deleteAll(); chatMessageRepository.deleteAll(); } @@ -82,6 +83,32 @@ void createChatInquiry() throws Exception { .andDo(MockMvcResultHandlers.print()); } + @DisplayName("[채팅 요청 아이디로 상세 채팅 요청을 조회할 수 있다.]") + @Test + void getChatInquiryById() throws Exception { + //given + Member chatPartner = memberRepository.save(MemberFixture.member5()); + QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(loginMember)); + ChatInquiry chatInquiry = chatInquiryRepository.save( + ChatInquiryFixture.chatInquiry(questionPost, loginMember, chatPartner, INQUIRY_MESSAGE) + ); + + //when & then + mockMvc.perform(get("/api/chat/inquiries/{chatInquiryId}", chatInquiry.getId()) + .cookie(accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.chatInquiryId") + .value(chatInquiry.getId())) + .andExpect(jsonPath("$.inquiryStatus") + .value(InquiryStatus.PENDING.getLabel())) + .andExpect(jsonPath("$.chatPartner.memberId") + .value(chatPartner.getId())) + .andExpect(jsonPath("$.isInquirer") + .value(chatInquiry.getInquirer().equals(loginMember))) + .andExpect(jsonPath("$.inquiryStatus") + .value(InquiryStatus.PENDING.getLabel())); + } + @DisplayName("[회원의 채팅 요청 목록을 조회할 수 있다.]") @Test void getChatInquiresByMember() throws Exception { diff --git a/src/test/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java b/src/test/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java index 7ec73484..e522871f 100644 --- a/src/test/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java +++ b/src/test/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java @@ -21,6 +21,7 @@ import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryDetailResponse; import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryResponse; @@ -134,6 +135,23 @@ void createInquiry_fails() { .hasMessageContaining(MemberErrorCode.NOT_ENOUGH_CREDIT.getMessage()); } + @DisplayName("[채팅 요청 아이디로 채팅 요청 상세를 조회할 수 있다.]") + @Test + void getChatInquiryById() { + //given + Member inquirer = MemberFixture.member(1L); + Member answerer = MemberFixture.member(2L); + given(chatInquiryRepository.findById(1L)) + .willReturn(Optional.of(ChatInquiryFixture.chatInquiry( + 1L, QuestionPostFixture.questionPost(inquirer), inquirer, answerer, INQUIRY_MESSAGE) + )); + //when + ChatInquiryDetailResponse response = chatInquiryService.getChatInquiryById(1L, inquirer); + + //then + assertThat(response.chatPartner().memberId()).isEqualTo(answerer.getId()); + } + @DisplayName("[회원이 속한 채팅 요청 목록을 조회할 수 있다.]") @Test void getChatInquiresByMember() { @@ -238,8 +256,7 @@ void rejectChat() { RejectChatResponse response = chatInquiryService.rejectChat(chatInquiryId, answerer); //then - assertThat(response.inquiryStatus()) - .isEqualTo(InquiryStatus.REJECTED.getLabel()); + assertThat(response.inquiryStatus()).isEqualTo(InquiryStatus.REJECTED.getLabel()); } @DisplayName("[답변자가 채팅 요청을 거절할 때 채팅 거절 알림이 발행된다.]")