From 7269136e035b2b153c3e44a979ace88ca97a4422 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 22 Nov 2024 15:49:37 +0900 Subject: [PATCH 01/12] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_inquiry/dto/ChatInquiryDetailResponse.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryDetailResponse.java 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..5ac87d68 --- /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.question_post.dto.response.MemberInfo; + +public record ChatInquiryDetailResponse( + Long chatInquiryId, + String inquiryMessage, + String inquiryStatus, + boolean isInquirer, + MemberInfo chatPartner +) { +} From 450fbfae2f38569de8d89d543f85bbbba9d7f76e Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 22 Nov 2024 15:50:14 +0900 Subject: [PATCH 02/12] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_inquiry/dto/ChatInquiryMapper.java | 19 +++++++++++++++++++ .../service/ChatInquiryService.java | 7 +++++++ 2 files changed, 26 insertions(+) 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..aa925eed 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 @@ -44,6 +44,25 @@ public static CreateChatInquiryResponse toCreateChatInquiryResponse( ); } + public static ChatInquiryDetailResponse toChatInquiryDetailResponse( + ChatInquiry chatInquiry, + Member member + ) { + boolean isInquirer = chatInquiry.getInquirer().equals(member); + Member chatPartner = isInquirer ? chatInquiry.getAnswerer() : chatInquiry.getInquirer(); + 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/service/ChatInquiryService.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryService.java index db7e13c8..cda72f8c 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,12 @@ 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, member); + } + @Transactional(readOnly = true) public PageResponse getChatInquiresByMember(Member member, Pageable pageable) { Slice responsePage = chatInquiryRepository.getChatInquiresByMember( From 0a09fe6f620a2e0e149a3617c0199e578de4b3b7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 22 Nov 2024 15:50:29 +0900 Subject: [PATCH 03/12] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ChatInquiryServiceTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 632bc320..b12882fc 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 @@ -7,6 +7,7 @@ import java.util.List; import java.util.Optional; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -21,6 +22,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 +136,24 @@ 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 + Assertions.assertThat(response.chatPartner().memberId()) + .isEqualTo(answerer.getId()); + } + @DisplayName("[회원이 속한 채팅 요청 목록을 조회할 수 있다.]") @Test void getChatInquiresByMember() { From 06b406ab8b1c5b14a21f22d571f7f5465597dfde Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 22 Nov 2024 15:50:43 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChatInquiryController.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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, From 6107af5a0ecdd7567504d035cae5d43002d8c83a Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 22 Nov 2024 15:50:53 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChatInquiryControllerTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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 { From 9dd0a01e219f2a55c71a8f7c085003f498aee1d8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 22 Nov 2024 19:01:30 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20API=20pk=20=ED=95=84=EB=93=9C=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..162dea00 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) From cb825b94cfaf5121bb933794bc11b8afe70ffce2 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 23 Nov 2024 13:51:02 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[rename]=20:=20memberInfo=20DTO=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dnd/gongmuin/answer/dto/AnswerDetailResponse.java | 2 +- src/main/java/com/dnd/gongmuin/answer/dto/AnswerMapper.java | 2 +- .../gongmuin/chat_inquiry/dto/ChatInquiryDetailResponse.java | 2 +- .../com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryMapper.java | 2 +- .../com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java | 2 +- .../gongmuin/chat_inquiry/dto/CreateChatInquiryResponse.java | 2 +- src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java | 2 +- .../gongmuin/chatroom/dto/response/ChatRoomDetailResponse.java | 2 +- .../gongmuin/chatroom/dto/response/ChatRoomSimpleResponse.java | 2 +- .../{question_post => member}/dto/response/MemberInfo.java | 2 +- .../com/dnd/gongmuin/question_post/dto/QuestionPostMapper.java | 2 +- .../question_post/dto/response/QuestionPostDetailResponse.java | 2 ++ .../dto/response/RegisterQuestionPostResponse.java | 2 ++ 13 files changed, 15 insertions(+), 11 deletions(-) rename src/main/java/com/dnd/gongmuin/{question_post => member}/dto/response/MemberInfo.java (67%) 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/dto/ChatInquiryDetailResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryDetailResponse.java index 5ac87d68..08aba1a3 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 @@ -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 ChatInquiryDetailResponse( Long chatInquiryId, 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 aa925eed..63003aa4 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 @@ -5,7 +5,7 @@ import com.dnd.gongmuin.chatroom.domain.ChatRoom; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; -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/dto/ChatInquiryResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java index 87bdb0e9..3b737d20 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 @@ -2,7 +2,7 @@ import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; import com.dnd.gongmuin.member.domain.JobGroup; -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; +import com.dnd.gongmuin.member.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/chatroom/dto/ChatRoomMapper.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java index 7f7eb957..0bbb7346 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java @@ -7,7 +7,7 @@ import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; -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/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/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..9a277761 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 @@ -9,7 +9,7 @@ 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.member.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, From 0440118e82d3468add28a0d6e88cfff16bd9897c Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 23 Nov 2024 14:34:57 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[remove]=20:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=98=88=EC=99=B8=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dnd/gongmuin/chatroom/exception/ChatErrorCode.java | 3 +-- .../gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) 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/test/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java b/src/test/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java index b12882fc..053238a6 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 @@ -7,7 +7,6 @@ import java.util.List; import java.util.Optional; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -150,7 +149,7 @@ void getChatInquiryById() { ChatInquiryDetailResponse response = chatInquiryService.getChatInquiryById(1L, inquirer); //then - Assertions.assertThat(response.chatPartner().memberId()) + assertThat(response.chatPartner().memberId()) .isEqualTo(answerer.getId()); } From 96b6fc98959cd6444c1a6c351706bd6a2fa4afa3 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 23 Nov 2024 14:35:51 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[refactor]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=ED=8C=8C=ED=8A=B8=EB=84=88=20=EA=B5=AC=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java | 8 ++++++++ .../java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java | 8 ++++++++ 2 files changed, 16 insertions(+) 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 162dea00..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 @@ -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/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; + } } From b267541930387a44064711963ef6c069927d88b5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 23 Nov 2024 14:36:39 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[refactor]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=ED=8C=8C=ED=8A=B8=EB=84=88=20=EA=B5=AC=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20mapper=EA=B0=80=20=EC=95=84=EB=8B=8C=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=82=B4=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_inquiry/dto/ChatInquiryMapper.java | 7 +++---- .../service/ChatInquiryService.java | 7 ++++++- .../gongmuin/chatroom/dto/ChatRoomMapper.java | 6 +++--- .../chatroom/service/ChatRoomService.java | 19 ++++++------------- 4 files changed, 18 insertions(+), 21 deletions(-) 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 63003aa4..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.question_post.domain.QuestionPost; import com.dnd.gongmuin.member.dto.response.MemberInfo; +import com.dnd.gongmuin.question_post.domain.QuestionPost; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -46,10 +46,9 @@ public static CreateChatInquiryResponse toCreateChatInquiryResponse( public static ChatInquiryDetailResponse toChatInquiryDetailResponse( ChatInquiry chatInquiry, - Member member + Member chatPartner, + boolean isInquirer ) { - boolean isInquirer = chatInquiry.getInquirer().equals(member); - Member chatPartner = isInquirer ? chatInquiry.getAnswerer() : chatInquiry.getInquirer(); return new ChatInquiryDetailResponse(chatInquiry.getId(), chatInquiry.getMessage(), chatInquiry.getStatus().getLabel(), 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 cda72f8c..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 @@ -74,7 +74,12 @@ public CreateChatInquiryResponse createChatInquiry(CreateChatInquiryRequest requ @Transactional(readOnly = true) public ChatInquiryDetailResponse getChatInquiryById(Long chatInquiryId, Member member) { ChatInquiry chatInquiry = getChatInquiryById(chatInquiryId); - return ChatInquiryMapper.toChatInquiryDetailResponse(chatInquiry, member); + + return ChatInquiryMapper.toChatInquiryDetailResponse( + chatInquiry, + chatInquiry.getChatPartner(member), + chatInquiry.isInquirer(member) + ); } @Transactional(readOnly = true) 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 0bbb7346..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.question_post.domain.QuestionPost; import com.dnd.gongmuin.member.dto.response.MemberInfo; +import com.dnd.gongmuin.question_post.domain.QuestionPost; 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/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); - } } From 066c46b9c8bacc913d7fd885c5c9a1f8916acb2f Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 23 Nov 2024 14:37:20 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[style]=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../question_post/dto/QuestionPostMapper.java | 2 +- .../chat/service/ChatRoomServiceTest.java | 22 ------------------- 2 files changed, 1 insertion(+), 23 deletions(-) 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 9a277761..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.member.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/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 From dcb9a194ebc26b129c31e5b1b9851ed2f94f1883 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 23 Nov 2024 17:16:34 +0900 Subject: [PATCH 12/12] =?UTF-8?q?[style]=20:=20=EC=A4=84=EB=B0=94=EA=BF=88?= =?UTF-8?q?=20=EC=B7=A8=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_inquiry/service/ChatInquiryServiceTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 58fc0a72..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 @@ -149,8 +149,7 @@ void getChatInquiryById() { ChatInquiryDetailResponse response = chatInquiryService.getChatInquiryById(1L, inquirer); //then - assertThat(response.chatPartner().memberId()) - .isEqualTo(answerer.getId()); + assertThat(response.chatPartner().memberId()).isEqualTo(answerer.getId()); } @DisplayName("[회원이 속한 채팅 요청 목록을 조회할 수 있다.]") @@ -257,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("[답변자가 채팅 요청을 거절할 때 채팅 거절 알림이 발행된다.]")