From 769d5c7c23d409d6450e323bd13f07029ba77cb5 Mon Sep 17 00:00:00 2001 From: Son Gahyun <77109954+hyun2371@users.noreply.github.com> Date: Sun, 8 Dec 2024 12:10:57 +0900 Subject: [PATCH] =?UTF-8?q?[feat=20#164]=20=EC=B1=84=ED=8C=85=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=EA=B0=92=20=EC=B6=94=EA=B0=80=20(#166)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [feat] : 채팅 요청 상세조회에 질문글, 크레딧 정보 포함 * [feat] : 채팅 요청 생성 응답 -> 크레딧 필드명 변경 * [test] : 응답 추가 및 필드명 변경 -> 테스트 반영 * [test] : createdAt 검증 제외 --- .../chat_inquiry/dto/ChatInquiryDetailResponse.java | 7 ++++++- .../gongmuin/chat_inquiry/dto/ChatInquiryMapper.java | 12 ++++++++++-- .../chat_inquiry/dto/CreateChatInquiryResponse.java | 2 +- .../chat_inquiry/service/ChatInquiryService.java | 1 + .../controller/ChatInquiryControllerTest.java | 10 ++++++++-- 5 files changed, 26 insertions(+), 6 deletions(-) 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 index 08aba1a3..0b686d4b 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryDetailResponse.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryDetailResponse.java @@ -7,6 +7,11 @@ public record ChatInquiryDetailResponse( String inquiryMessage, String inquiryStatus, boolean isInquirer, - MemberInfo chatPartner + int memberCredit, + Long questionPostId, + String targetJobGroup, + String title, + MemberInfo chatPartner, + String createdAt ) { } 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 ef1c5278..691c0eda 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 @@ -47,19 +47,27 @@ public static CreateChatInquiryResponse toCreateChatInquiryResponse( public static ChatInquiryDetailResponse toChatInquiryDetailResponse( ChatInquiry chatInquiry, + Member member, Member chatPartner, boolean isInquirer ) { - return new ChatInquiryDetailResponse(chatInquiry.getId(), + QuestionPost questionPost = chatInquiry.getQuestionPost(); + return new ChatInquiryDetailResponse( + chatInquiry.getId(), chatInquiry.getMessage(), chatInquiry.getStatus().getLabel(), isInquirer, + member.getCredit(), + questionPost.getId(), + questionPost.getJobGroup().toString(), + questionPost.getTitle(), new MemberInfo( chatPartner.getId(), chatPartner.getNickname(), chatPartner.getJobGroup().getLabel(), chatPartner.getProfileImageNo() - ) + ), + chatInquiry.getCreatedAt().toString() ); } 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 0a5dd812..8da2814f 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 @@ -6,7 +6,7 @@ public record CreateChatInquiryResponse( Long chatInquiryId, String inquiryMessage, String inquiryStatus, - int credit, + int memberCredit, MemberInfo chatPartner ) { } 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 d51725b5..0ef669c3 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 @@ -77,6 +77,7 @@ public ChatInquiryDetailResponse getChatInquiryById(Long chatInquiryId, Member m return ChatInquiryMapper.toChatInquiryDetailResponse( chatInquiry, + member, chatInquiry.getChatPartner(member), chatInquiry.isInquirer(member) ); 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 038f9c93..cc98553c 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 @@ -80,8 +80,9 @@ void createChatInquiry() throws Exception { .content(toJson(request)) .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) + .andExpect(jsonPath("$.chatPartner.memberId").value(answerer.getId())) .andExpect(jsonPath("$.inquiryStatus").value(InquiryStatus.PENDING.getLabel())) - .andExpect(jsonPath("$.credit").value(previousCredit - CHAT_REWARD)) + .andExpect(jsonPath("$.memberCredit").value(previousCredit - CHAT_REWARD)) .andDo(MockMvcResultHandlers.print()); } @@ -94,6 +95,7 @@ void getChatInquiryById() throws Exception { ChatInquiry chatInquiry = chatInquiryRepository.save( ChatInquiryFixture.chatInquiry(questionPost, loginMember, chatPartner, INQUIRY_MESSAGE) ); + memberRepository.save(loginMember); // credit 변경사항 flush //when & then mockMvc.perform(get("/api/chat/inquiries/{chatInquiryId}", chatInquiry.getId()) @@ -107,8 +109,12 @@ void getChatInquiryById() throws Exception { .value(chatPartner.getId())) .andExpect(jsonPath("$.isInquirer") .value(chatInquiry.getInquirer().equals(loginMember))) + .andExpect(jsonPath("$.memberCredit") + .value(loginMember.getCredit())) .andExpect(jsonPath("$.inquiryStatus") - .value(InquiryStatus.PENDING.getLabel())); + .value(InquiryStatus.PENDING.getLabel())) + .andExpect(jsonPath("$.questionPostId") + .value(chatInquiry.getQuestionPost().getId())); } @DisplayName("[회원의 채팅 요청 목록을 조회할 수 있다.]")