From 5052f7563f8bde990b885984d843f9f30e69c226 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 21:41:09 +0900 Subject: [PATCH 01/44] =?UTF-8?q?[refactor]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=83=81=EB=8C=80=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnd/gongmuin/chat/service/ChatRoomService.java | 11 +++++------ .../java/com/dnd/gongmuin/member/domain/Member.java | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) 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 8e6bd754..71a7cb40 100644 --- a/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java +++ b/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java @@ -141,7 +141,7 @@ public PageResponse getChatProposalsByMember(Member member @Transactional(readOnly = true) public ChatRoomDetailResponse getChatRoomById(Long chatRoomId, Member member) { ChatRoom chatRoom = getChatRoomById(chatRoomId); - Member chatPartner = getChatPartner(member.getId(), chatRoom); + Member chatPartner = getChatPartner(member, chatRoom); return ChatRoomMapper.toChatRoomDetailResponse(chatRoom, chatPartner); } @@ -236,14 +236,13 @@ private Member getMemberById(Long id) { .orElseThrow(() -> new NotFoundException(MemberErrorCode.NOT_FOUND_MEMBER)); } - private Member getChatPartner(Long memberId, ChatRoom chatRoom) { - if (Objects.equals(chatRoom.getAnswerer().getId(), memberId)) { + private Member getChatPartner(Member member, ChatRoom chatRoom) { + if (member.isEqualMember(chatRoom.getAnswerer().getId())) { return chatRoom.getInquirer(); - } else if (Objects.equals(chatRoom.getInquirer().getId(), memberId)) { + } else if (member.isEqualMember(chatRoom.getInquirer().getId())) { return chatRoom.getAnswerer(); - } else { - throw new ValidationException(ChatErrorCode.UNAUTHORIZED_CHAT_ROOM); } + throw new ValidationException(ChatErrorCode.UNAUTHORIZED_CHAT_ROOM); } } diff --git a/src/main/java/com/dnd/gongmuin/member/domain/Member.java b/src/main/java/com/dnd/gongmuin/member/domain/Member.java index 87b1ce57..aa7cd70c 100644 --- a/src/main/java/com/dnd/gongmuin/member/domain/Member.java +++ b/src/main/java/com/dnd/gongmuin/member/domain/Member.java @@ -133,6 +133,10 @@ public void updateProfile(String nickname, JobGroup jobGroup, JobCategory jobCat this.jobCategory = jobCategory; } + public boolean isEqualMember(Long id) { + return this.id.equals(id); + } + private int setRandomNumber() { Random random = new Random(); return random.nextInt(1, 10); From 4aa549bf95641602b6f8014efce1a42361e879da Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 21:46:07 +0900 Subject: [PATCH 02/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=EB=B0=A9=20=EC=83=81=ED=83=9C=20=ED=95=84=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnd/gongmuin/chat/domain/ChatRoom.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/ChatRoom.java b/src/main/java/com/dnd/gongmuin/chat/domain/ChatRoom.java index 6ee3898d..67a0057b 100644 --- a/src/main/java/com/dnd/gongmuin/chat/domain/ChatRoom.java +++ b/src/main/java/com/dnd/gongmuin/chat/domain/ChatRoom.java @@ -51,15 +51,10 @@ public class ChatRoom extends TimeBaseEntity { foreignKey = @ForeignKey(NO_CONSTRAINT)) private Member answerer; - @Enumerated(STRING) - @Column(name = "status", nullable = false) - private ChatStatus status; - private ChatRoom(QuestionPost questionPost, Member inquirer, Member answerer) { this.questionPost = questionPost; this.inquirer = inquirer; this.answerer = answerer; - this.status = ChatStatus.PENDING; inquirer.decreaseCredit(CHAT_REWARD); } @@ -70,20 +65,4 @@ public static ChatRoom of( ) { return new ChatRoom(questionPost, inquirer, answerer); } - - public void updateStatusAccepted() { - if (status != ChatStatus.PENDING) { - throw new ValidationException(ChatErrorCode.UNABLE_TO_CHANGE_CHAT_STATUS); - } - status = ChatStatus.ACCEPTED; - answerer.increaseCredit(CHAT_REWARD); - } - - public void updateStatusRejected() { - if (status != ChatStatus.PENDING) { - throw new ValidationException(ChatErrorCode.UNABLE_TO_CHANGE_CHAT_STATUS); - } - status = ChatStatus.REJECTED; - inquirer.increaseCredit(CHAT_REWARD); - } } From 9045156c9a6404da1a8d0ba65ced56e351459bab Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 21:46:33 +0900 Subject: [PATCH 03/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=20=ED=95=84=EB=93=9C=20->=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=9A=94=EC=B2=AD=20=EC=83=81=ED=83=9C=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/domain/{ChatStatus.java => InquiryStatus.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/java/com/dnd/gongmuin/chat/domain/{ChatStatus.java => InquiryStatus.java} (89%) diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/ChatStatus.java b/src/main/java/com/dnd/gongmuin/chat/domain/InquiryStatus.java similarity index 89% rename from src/main/java/com/dnd/gongmuin/chat/domain/ChatStatus.java rename to src/main/java/com/dnd/gongmuin/chat/domain/InquiryStatus.java index beef2fbe..e3c04ac3 100644 --- a/src/main/java/com/dnd/gongmuin/chat/domain/ChatStatus.java +++ b/src/main/java/com/dnd/gongmuin/chat/domain/InquiryStatus.java @@ -10,7 +10,7 @@ @Getter @RequiredArgsConstructor -public enum ChatStatus { +public enum InquiryStatus { PENDING("요청중"), ACCEPTED("수락됨"), @@ -18,7 +18,7 @@ public enum ChatStatus { private final String label; - public static ChatStatus from(String input) { + public static InquiryStatus from(String input) { return Arrays.stream(values()) .filter(status -> status.isEqual(input)) .findAny() From e4718a17780c898de81f8c77b0ace7e44cb08755 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 21:47:11 +0900 Subject: [PATCH 04/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=20=ED=95=84=EB=93=9C=20->=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=9A=94=EC=B2=AD=20=EC=83=81=ED=83=9C=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gongmuin/chat/dto/response/ChatProposalInfo.java | 6 +++--- .../chat/repository/ChatRoomQueryRepository.java | 1 - .../chat/repository/ChatRoomQueryRepositoryImpl.java | 12 ++++++------ .../chat/repository/ChatRoomRepositoryTest.java | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalInfo.java b/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalInfo.java index 4fbe75d4..9d97036e 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalInfo.java +++ b/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalInfo.java @@ -1,6 +1,6 @@ package com.dnd.gongmuin.chat.dto.response; -import com.dnd.gongmuin.chat.domain.ChatStatus; +import com.dnd.gongmuin.chat.domain.InquiryStatus; import com.dnd.gongmuin.member.domain.JobGroup; import com.querydsl.core.annotations.QueryProjection; @@ -16,7 +16,7 @@ public record ChatProposalInfo( @QueryProjection public ChatProposalInfo( Long chatRoomId, - ChatStatus chatStatus, + InquiryStatus inquiryStatus, boolean isInquirer, Long partnerId, String partnerNickname, @@ -25,7 +25,7 @@ public ChatProposalInfo( ) { this( chatRoomId, - chatStatus.getLabel(), + inquiryStatus.getLabel(), isInquirer, partnerId, partnerNickname, 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 8e6e3d67..d277b820 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java +++ b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java @@ -5,7 +5,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import com.dnd.gongmuin.chat.domain.ChatStatus; import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; import com.dnd.gongmuin.member.domain.Member; 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 2d1a8342..8cda6e0b 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java +++ b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java @@ -10,7 +10,7 @@ import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; -import com.dnd.gongmuin.chat.domain.ChatStatus; +import com.dnd.gongmuin.chat.domain.InquiryStatus; import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; import com.dnd.gongmuin.chat.dto.response.QChatProposalInfo; @@ -54,7 +54,7 @@ public Slice getChatRoomsByMember( .from(chatRoom) .where(chatRoom.inquirer.id.eq(member.getId()) .or(chatRoom.answerer.id.eq(member.getId())) - .and(chatRoom.status.eq(ChatStatus.ACCEPTED))) + .and(chatRoom.status.eq(InquiryStatus.ACCEPTED))) .fetch(); boolean hasNext = hasNext(pageable.getPageSize(), content); @@ -91,7 +91,7 @@ public Slice getChatProposalsByMember(Member member, Pageable .from(chatRoom) .where(chatRoom.inquirer.id.eq(member.getId()) .or(chatRoom.answerer.id.eq(member.getId())) - .and(chatRoom.status.in(List.of(ChatStatus.REJECTED, ChatStatus.PENDING)))) + .and(chatRoom.status.in(List.of(InquiryStatus.REJECTED, InquiryStatus.PENDING)))) .fetch(); boolean hasNext = hasNext(pageable.getPageSize(), content); @@ -104,17 +104,17 @@ public List getAutoRejectedInquirerIds() { .from(chatRoom) .where( chatRoom.createdAt.loe(LocalDateTime.now().minusWeeks(1)), - chatRoom.status.eq(ChatStatus.PENDING) + chatRoom.status.eq(InquiryStatus.PENDING) ) .fetch(); } public void updateChatRoomStatusRejected() { queryFactory.update(chatRoom) - .set(chatRoom.status, ChatStatus.REJECTED) + .set(chatRoom.status, InquiryStatus.REJECTED) .where( chatRoom.createdAt.loe(LocalDateTime.now().minusWeeks(1)), - chatRoom.status.eq(ChatStatus.PENDING) + chatRoom.status.eq(InquiryStatus.PENDING) ) .execute(); } 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 45b34212..3a44a458 100644 --- a/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java @@ -14,7 +14,7 @@ import org.springframework.test.util.ReflectionTestUtils; import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.ChatStatus; +import com.dnd.gongmuin.chat.domain.InquiryStatus; import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; import com.dnd.gongmuin.common.fixture.ChatRoomFixture; @@ -125,8 +125,8 @@ void updateChatRoomStatusRejected() { ChatRoom chatRoom1 = chatRoomRepository.findById(chatRooms.get(0).getId()).orElseThrow(); ChatRoom chatRoom2 = chatRoomRepository.findById(chatRooms.get(1).getId()).orElseThrow(); assertAll( - () -> assertThat(chatRoom1.getStatus()).isEqualTo(ChatStatus.REJECTED), - () -> assertThat(chatRoom2.getStatus()).isEqualTo(ChatStatus.PENDING) + () -> assertThat(chatRoom1.getStatus()).isEqualTo(InquiryStatus.REJECTED), + () -> assertThat(chatRoom2.getStatus()).isEqualTo(InquiryStatus.PENDING) ); } } \ No newline at end of file From 147f1e537eeb89decb38c2fb47270c41c41bdc94 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 21:47:24 +0900 Subject: [PATCH 05/44] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=20=ED=95=84=EB=93=9C=20->=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=9A=94=EC=B2=AD=20=EC=83=81=ED=83=9C=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/ChatRoomControllerTest.java | 10 +++++----- .../gongmuin/chat/service/ChatRoomServiceTest.java | 12 ++++++------ .../dnd/gongmuin/common/fixture/ChatRoomFixture.java | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) 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 b0b9a4ee..699f206a 100644 --- a/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java @@ -15,7 +15,7 @@ import com.dnd.gongmuin.chat.domain.ChatMessage; import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.ChatStatus; +import com.dnd.gongmuin.chat.domain.InquiryStatus; import com.dnd.gongmuin.chat.dto.request.CreateChatRoomRequest; import com.dnd.gongmuin.chat.repository.ChatMessageRepository; import com.dnd.gongmuin.chat.repository.ChatRoomRepository; @@ -195,13 +195,13 @@ void getChatProposalsByMember() throws Exception { .andExpect(jsonPath("$.content[0].latestMessage").value("21")) .andExpect(jsonPath("$.content[0].chatPartner.memberId").value(member1.getId())) .andExpect(jsonPath("$.content[0].isInquirer").value(true)) - .andExpect(jsonPath("$.content[0].chatStatus").value(ChatStatus.PENDING.getLabel())) + .andExpect(jsonPath("$.content[0].chatStatus").value(InquiryStatus.PENDING.getLabel())) .andExpect(jsonPath("$.content[1].chatRoomId").value(chatRoom1.getId())) .andExpect(jsonPath("$.content[1].latestMessage").value("11")) .andExpect(jsonPath("$.content[1].chatPartner.memberId").value(member1.getId())) .andExpect(jsonPath("$.content[1].isInquirer").value(false)) - .andExpect(jsonPath("$.content[1].chatStatus").value(ChatStatus.PENDING.getLabel())) + .andExpect(jsonPath("$.content[1].chatStatus").value(InquiryStatus.PENDING.getLabel())) .andDo(MockMvcResultHandlers.print()); } @@ -236,7 +236,7 @@ void acceptChatRoom() throws Exception { mockMvc.perform(patch("/api/chat-rooms/{chatRoomId}/accept", chatRoom.getId()) .cookie(accessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.chatStatus").value(ChatStatus.ACCEPTED.getLabel())) + .andExpect(jsonPath("$.chatStatus").value(InquiryStatus.ACCEPTED.getLabel())) .andExpect(jsonPath("$.credit").value(previousAnswererCredit + CHAT_REWARD)); } @@ -250,6 +250,6 @@ void rejectChatRoom() throws Exception { mockMvc.perform(patch("/api/chat-rooms/{chatRoomId}/reject", chatRoom.getId()) .cookie(accessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.chatStatus").value(ChatStatus.REJECTED.getLabel())); + .andExpect(jsonPath("$.chatStatus").value(InquiryStatus.REJECTED.getLabel())); } } \ No newline at end of file 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 1775ddb6..d63e9d9b 100644 --- a/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java @@ -21,7 +21,7 @@ import com.dnd.gongmuin.chat.domain.ChatMessage; import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.ChatStatus; +import com.dnd.gongmuin.chat.domain.InquiryStatus; import com.dnd.gongmuin.chat.domain.MessageType; import com.dnd.gongmuin.chat.dto.request.CreateChatRoomRequest; import com.dnd.gongmuin.chat.dto.response.AcceptChatResponse; @@ -237,7 +237,7 @@ void getChatProposalsByMember() { Member targetMember = MemberFixture.member(1L); Member partner = MemberFixture.member(2L); ChatProposalInfo chatProposalInfo = new ChatProposalInfo( - chatRoomId, ChatStatus.PENDING, true, partner.getId(), + chatRoomId, InquiryStatus.PENDING, true, partner.getId(), partner.getNickname(), partner.getJobGroup(), partner.getProfileImageNo() ); LatestChatMessage latestChatMessage = new LatestChatMessage( @@ -357,7 +357,7 @@ void acceptChat() { //then assertAll( () -> assertThat(response.chatStatus()) - .isEqualTo(ChatStatus.ACCEPTED.getLabel()), + .isEqualTo(InquiryStatus.ACCEPTED.getLabel()), () -> assertThat(response.credit()) .isEqualTo(previousCredit + CHAT_REWARD) ); @@ -383,7 +383,7 @@ void acceptChatWithEventPublish() { //then assertAll( () -> assertThat(response.chatStatus()) - .isEqualTo(ChatStatus.ACCEPTED.getLabel()), + .isEqualTo(InquiryStatus.ACCEPTED.getLabel()), () -> assertThat(response.credit()) .isEqualTo(previousCredit + CHAT_REWARD), () -> verify(eventPublisher, times(1)).publishEvent(any(NotificationEvent.class)) @@ -408,7 +408,7 @@ void rejectChat() { //then assertThat(response.chatStatus()) - .isEqualTo(ChatStatus.REJECTED.getLabel()); + .isEqualTo(InquiryStatus.REJECTED.getLabel()); } @DisplayName("[답변자가 채팅 요청을 거절할 때 채팅 거절 알림이 발행된다.]") @@ -429,7 +429,7 @@ void rejectChatWithEventPublish() { //then assertAll( - () -> assertThat(response.chatStatus()).isEqualTo(ChatStatus.REJECTED.getLabel()), + () -> assertThat(response.chatStatus()).isEqualTo(InquiryStatus.REJECTED.getLabel()), () -> verify(eventPublisher, times(1)).publishEvent(any(NotificationEvent.class)) ); } diff --git a/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java b/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java index e0406b68..c1e88d39 100644 --- a/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java +++ b/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java @@ -3,7 +3,7 @@ import org.springframework.test.util.ReflectionTestUtils; import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.ChatStatus; +import com.dnd.gongmuin.chat.domain.InquiryStatus; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; @@ -35,7 +35,7 @@ public static ChatRoom acceptedChatRoom( inquirer, answerer ); - ReflectionTestUtils.setField(chatRoom, "status", ChatStatus.ACCEPTED); + ReflectionTestUtils.setField(chatRoom, "status", InquiryStatus.ACCEPTED); return chatRoom; } From e0f4be5e22ba5ebd78fa10ee23f34101572ff665 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 21:47:53 +0900 Subject: [PATCH 06/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnd/gongmuin/chat/domain/ChatInquiry.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/main/java/com/dnd/gongmuin/chat/domain/ChatInquiry.java diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/ChatInquiry.java b/src/main/java/com/dnd/gongmuin/chat/domain/ChatInquiry.java new file mode 100644 index 00000000..c0c1080c --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat/domain/ChatInquiry.java @@ -0,0 +1,93 @@ +package com.dnd.gongmuin.chat.domain; + +import static jakarta.persistence.ConstraintMode.*; +import static jakarta.persistence.EnumType.*; +import static jakarta.persistence.FetchType.*; + +import com.dnd.gongmuin.chat.exception.ChatErrorCode; +import com.dnd.gongmuin.common.entity.TimeBaseEntity; +import com.dnd.gongmuin.common.exception.runtime.ValidationException; +import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.question_post.domain.QuestionPost; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ChatInquiry extends TimeBaseEntity { + private static final int CHAT_REWARD = 2000; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "chat_proposal_id", nullable = false) + private Long id; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "question_post_id", + nullable = false, + foreignKey = @ForeignKey(NO_CONSTRAINT)) + private QuestionPost questionPost; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "inquirer_id", nullable = false, + foreignKey = @ForeignKey(NO_CONSTRAINT)) + private Member inquirer; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "answerer_id", nullable = false, + foreignKey = @ForeignKey(NO_CONSTRAINT)) + private Member answerer; + + @Enumerated(STRING) + @Column(name = "status", nullable = false) + private InquiryStatus status; + + @Column(name = "message", nullable = false) + private String message; + + private ChatInquiry(QuestionPost questionPost, Member inquirer, Member answerer, String message) { + this.questionPost = questionPost; + this.inquirer = inquirer; + this.answerer = answerer; + this.status = InquiryStatus.PENDING; + this.message = message; + inquirer.decreaseCredit(CHAT_REWARD); + } + + public static ChatInquiry of( + QuestionPost questionPost, + Member inquirer, + Member answerer, + String message + ) { + return new ChatInquiry(questionPost, inquirer, answerer, message); + } + + public void updateStatusAccepted() { + if (status != InquiryStatus.PENDING) { + throw new ValidationException(ChatErrorCode.UNABLE_TO_CHANGE_CHAT_STATUS); + } + status = InquiryStatus.ACCEPTED; + answerer.increaseCredit(CHAT_REWARD); + } + + public void updateStatusRejected() { + if (status != InquiryStatus.PENDING) { + throw new ValidationException(ChatErrorCode.UNABLE_TO_CHANGE_CHAT_STATUS); + } + status = InquiryStatus.REJECTED; + inquirer.increaseCredit(CHAT_REWARD); + } +} From d45a616ac177a2e3bc6c58ac729a9ae69c708aaa Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 21:50:32 +0900 Subject: [PATCH 07/44] =?UTF-8?q?[rename]=20:=20chat=20=EB=94=94=EB=A0=89?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=20=EC=9D=B4=EB=A6=84=20chatroom=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChatRoomQueryRepositoryImpl.java | 129 ----------------- .../controller/ChatMessageController.java | 8 +- .../controller/ChatRoomController.java | 20 +-- .../domain/ChatInquiry.java | 4 +- .../domain/ChatMessage.java | 2 +- .../{chat => chatroom}/domain/ChatRoom.java | 6 +- .../domain/InquiryStatus.java | 4 +- .../domain/MessageType.java | 4 +- .../dto/ChatMessageMapper.java | 12 +- .../dto/ChatRoomMapper.java | 22 +-- .../dto/request/ChatMessageRequest.java | 2 +- .../dto/request/CreateChatRoomRequest.java | 2 +- .../dto/response/AcceptChatResponse.java | 2 +- .../dto/response/ChatMessageResponse.java | 2 +- .../dto/response/ChatProposalInfo.java | 4 +- .../dto/response/ChatProposalResponse.java | 2 +- .../dto/response/ChatRoomDetailResponse.java | 2 +- .../dto/response/ChatRoomInfo.java | 2 +- .../dto/response/ChatRoomSimpleResponse.java | 2 +- .../dto/response/CreateChatRoomResponse.java | 2 +- .../dto/response/LatestChatMessage.java | 2 +- .../dto/response/RejectChatResponse.java | 2 +- .../exception/ChatErrorCode.java | 2 +- .../ChatMessageQueryRepository.java | 4 +- .../repository/ChatMessageRepository.java | 4 +- .../repository/ChatRoomQueryRepository.java | 6 +- .../ChatRoomQueryRepositoryImpl.java | 131 ++++++++++++++++++ .../repository/ChatRoomRepository.java | 4 +- .../scheduler/ChatScheduler.java | 4 +- .../service/ChatMessageService.java | 12 +- .../service/ChatRoomService.java | 38 ++--- .../controller/ChatRoomControllerTest.java | 12 +- .../ChatMessageQueryRepositoryTest.java | 4 +- .../repository/ChatRoomRepositoryTest.java | 9 +- .../chat/service/ChatRoomServiceTest.java | 39 +++--- .../common/fixture/ChatMessageFixture.java | 4 +- .../common/fixture/ChatRoomFixture.java | 4 +- 37 files changed, 258 insertions(+), 256 deletions(-) delete mode 100644 src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/controller/ChatMessageController.java (76%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/controller/ChatRoomController.java (86%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/domain/ChatInquiry.java (96%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/domain/ChatMessage.java (95%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/domain/ChatRoom.java (87%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/domain/InquiryStatus.java (86%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/domain/MessageType.java (86%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/ChatMessageMapper.java (76%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/ChatRoomMapper.java (81%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/request/ChatMessageRequest.java (88%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/request/CreateChatRoomRequest.java (86%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/AcceptChatResponse.java (60%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/ChatMessageResponse.java (72%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/ChatProposalInfo.java (86%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/ChatProposalResponse.java (84%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/ChatRoomDetailResponse.java (83%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/ChatRoomInfo.java (91%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/ChatRoomSimpleResponse.java (82%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/CreateChatRoomResponse.java (82%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/LatestChatMessage.java (75%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/dto/response/RejectChatResponse.java (55%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/exception/ChatErrorCode.java (94%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/repository/ChatMessageQueryRepository.java (93%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/repository/ChatMessageRepository.java (80%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/repository/ChatRoomQueryRepository.java (72%) create mode 100644 src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepositoryImpl.java rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/repository/ChatRoomRepository.java (63%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/scheduler/ChatScheduler.java (82%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/service/ChatMessageService.java (68%) rename src/main/java/com/dnd/gongmuin/{chat => chatroom}/service/ChatRoomService.java (88%) diff --git a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java b/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java deleted file mode 100644 index 8cda6e0b..00000000 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.dnd.gongmuin.chat.repository; - - -import static com.dnd.gongmuin.chat.domain.QChatRoom.*; - -import java.time.LocalDateTime; -import java.util.List; - -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; -import org.springframework.data.domain.SliceImpl; - -import com.dnd.gongmuin.chat.domain.InquiryStatus; -import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; -import com.dnd.gongmuin.chat.dto.response.QChatProposalInfo; -import com.dnd.gongmuin.chat.dto.response.QChatRoomInfo; -import com.dnd.gongmuin.member.domain.Member; -import com.querydsl.core.types.dsl.CaseBuilder; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class ChatRoomQueryRepositoryImpl implements ChatRoomQueryRepository { - - private final JPAQueryFactory queryFactory; - - public Slice getChatRoomsByMember( - Member member, - Pageable pageable - ) { - List content = queryFactory - .select(new QChatRoomInfo( - chatRoom.id, - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(chatRoom.answerer.id) - .otherwise(chatRoom.inquirer.id), - - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(chatRoom.answerer.nickname) - .otherwise(chatRoom.inquirer.nickname), - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(chatRoom.answerer.jobGroup) - .otherwise(chatRoom.inquirer.jobGroup), - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(chatRoom.answerer.profileImageNo) - .otherwise(chatRoom.inquirer.profileImageNo) - )) - .from(chatRoom) - .where(chatRoom.inquirer.id.eq(member.getId()) - .or(chatRoom.answerer.id.eq(member.getId())) - .and(chatRoom.status.eq(InquiryStatus.ACCEPTED))) - .fetch(); - - boolean hasNext = hasNext(pageable.getPageSize(), content); - return new SliceImpl<>(content, pageable, hasNext); - } - - public Slice getChatProposalsByMember(Member member, Pageable pageable){ - List content = queryFactory - .select(new QChatProposalInfo( - chatRoom.id, - chatRoom.status, - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(true) - .otherwise(false), - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(chatRoom.answerer.id) - .otherwise(chatRoom.inquirer.id), - - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(chatRoom.answerer.nickname) - .otherwise(chatRoom.inquirer.nickname), - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(chatRoom.answerer.jobGroup) - .otherwise(chatRoom.inquirer.jobGroup), - new CaseBuilder() - .when(chatRoom.inquirer.id.eq(member.getId())) - .then(chatRoom.answerer.profileImageNo) - .otherwise(chatRoom.inquirer.profileImageNo) - )) - .from(chatRoom) - .where(chatRoom.inquirer.id.eq(member.getId()) - .or(chatRoom.answerer.id.eq(member.getId())) - .and(chatRoom.status.in(List.of(InquiryStatus.REJECTED, InquiryStatus.PENDING)))) - .fetch(); - - boolean hasNext = hasNext(pageable.getPageSize(), content); - return new SliceImpl<>(content, pageable, hasNext); - } - - public List getAutoRejectedInquirerIds() { - return queryFactory - .select(chatRoom.inquirer.id) - .from(chatRoom) - .where( - chatRoom.createdAt.loe(LocalDateTime.now().minusWeeks(1)), - chatRoom.status.eq(InquiryStatus.PENDING) - ) - .fetch(); - } - - public void updateChatRoomStatusRejected() { - queryFactory.update(chatRoom) - .set(chatRoom.status, InquiryStatus.REJECTED) - .where( - chatRoom.createdAt.loe(LocalDateTime.now().minusWeeks(1)), - chatRoom.status.eq(InquiryStatus.PENDING) - ) - .execute(); - } - - private boolean hasNext(int pageSize, List items) { - if (items.size() <= pageSize) { - return false; - } - items.remove(pageSize); - return true; - } -} diff --git a/src/main/java/com/dnd/gongmuin/chat/controller/ChatMessageController.java b/src/main/java/com/dnd/gongmuin/chatroom/controller/ChatMessageController.java similarity index 76% rename from src/main/java/com/dnd/gongmuin/chat/controller/ChatMessageController.java rename to src/main/java/com/dnd/gongmuin/chatroom/controller/ChatMessageController.java index 0ce6aac0..f35016cd 100644 --- a/src/main/java/com/dnd/gongmuin/chat/controller/ChatMessageController.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/controller/ChatMessageController.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.controller; +package com.dnd.gongmuin.chatroom.controller; import org.springframework.messaging.handler.annotation.DestinationVariable; import org.springframework.messaging.handler.annotation.MessageMapping; @@ -6,9 +6,9 @@ import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.stereotype.Controller; -import com.dnd.gongmuin.chat.dto.request.ChatMessageRequest; -import com.dnd.gongmuin.chat.dto.response.ChatMessageResponse; -import com.dnd.gongmuin.chat.service.ChatMessageService; +import com.dnd.gongmuin.chatroom.dto.request.ChatMessageRequest; +import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; +import com.dnd.gongmuin.chatroom.service.ChatMessageService; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/dnd/gongmuin/chat/controller/ChatRoomController.java b/src/main/java/com/dnd/gongmuin/chatroom/controller/ChatRoomController.java similarity index 86% rename from src/main/java/com/dnd/gongmuin/chat/controller/ChatRoomController.java rename to src/main/java/com/dnd/gongmuin/chatroom/controller/ChatRoomController.java index fed5fe37..585c2af4 100644 --- a/src/main/java/com/dnd/gongmuin/chat/controller/ChatRoomController.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/controller/ChatRoomController.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.controller; +package com.dnd.gongmuin.chatroom.controller; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; @@ -10,15 +10,15 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import com.dnd.gongmuin.chat.dto.request.CreateChatRoomRequest; -import com.dnd.gongmuin.chat.dto.response.AcceptChatResponse; -import com.dnd.gongmuin.chat.dto.response.ChatMessageResponse; -import com.dnd.gongmuin.chat.dto.response.ChatProposalResponse; -import com.dnd.gongmuin.chat.dto.response.ChatRoomDetailResponse; -import com.dnd.gongmuin.chat.dto.response.ChatRoomSimpleResponse; -import com.dnd.gongmuin.chat.dto.response.CreateChatRoomResponse; -import com.dnd.gongmuin.chat.dto.response.RejectChatResponse; -import com.dnd.gongmuin.chat.service.ChatRoomService; +import com.dnd.gongmuin.chatroom.dto.request.CreateChatRoomRequest; +import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomDetailResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; +import com.dnd.gongmuin.chatroom.dto.response.CreateChatRoomResponse; +import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; +import com.dnd.gongmuin.chatroom.service.ChatRoomService; import com.dnd.gongmuin.common.dto.PageResponse; import com.dnd.gongmuin.member.domain.Member; diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/ChatInquiry.java b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatInquiry.java similarity index 96% rename from src/main/java/com/dnd/gongmuin/chat/domain/ChatInquiry.java rename to src/main/java/com/dnd/gongmuin/chatroom/domain/ChatInquiry.java index c0c1080c..def4c84d 100644 --- a/src/main/java/com/dnd/gongmuin/chat/domain/ChatInquiry.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatInquiry.java @@ -1,10 +1,10 @@ -package com.dnd.gongmuin.chat.domain; +package com.dnd.gongmuin.chatroom.domain; import static jakarta.persistence.ConstraintMode.*; import static jakarta.persistence.EnumType.*; import static jakarta.persistence.FetchType.*; -import com.dnd.gongmuin.chat.exception.ChatErrorCode; +import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; import com.dnd.gongmuin.common.entity.TimeBaseEntity; import com.dnd.gongmuin.common.exception.runtime.ValidationException; import com.dnd.gongmuin.member.domain.Member; diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/ChatMessage.java b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatMessage.java similarity index 95% rename from src/main/java/com/dnd/gongmuin/chat/domain/ChatMessage.java rename to src/main/java/com/dnd/gongmuin/chatroom/domain/ChatMessage.java index b41bf5ab..ce72029e 100644 --- a/src/main/java/com/dnd/gongmuin/chat/domain/ChatMessage.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatMessage.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.domain; +package com.dnd.gongmuin.chatroom.domain; import static lombok.AccessLevel.*; diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/ChatRoom.java b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java similarity index 87% rename from src/main/java/com/dnd/gongmuin/chat/domain/ChatRoom.java rename to src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java index 67a0057b..52f49517 100644 --- a/src/main/java/com/dnd/gongmuin/chat/domain/ChatRoom.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java @@ -1,18 +1,14 @@ -package com.dnd.gongmuin.chat.domain; +package com.dnd.gongmuin.chatroom.domain; import static jakarta.persistence.ConstraintMode.*; -import static jakarta.persistence.EnumType.*; import static jakarta.persistence.FetchType.*; -import com.dnd.gongmuin.chat.exception.ChatErrorCode; import com.dnd.gongmuin.common.entity.TimeBaseEntity; -import com.dnd.gongmuin.common.exception.runtime.ValidationException; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.Enumerated; import jakarta.persistence.ForeignKey; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/InquiryStatus.java b/src/main/java/com/dnd/gongmuin/chatroom/domain/InquiryStatus.java similarity index 86% rename from src/main/java/com/dnd/gongmuin/chat/domain/InquiryStatus.java rename to src/main/java/com/dnd/gongmuin/chatroom/domain/InquiryStatus.java index e3c04ac3..66723e0f 100644 --- a/src/main/java/com/dnd/gongmuin/chat/domain/InquiryStatus.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/domain/InquiryStatus.java @@ -1,8 +1,8 @@ -package com.dnd.gongmuin.chat.domain; +package com.dnd.gongmuin.chatroom.domain; import java.util.Arrays; -import com.dnd.gongmuin.chat.exception.ChatErrorCode; +import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; import com.dnd.gongmuin.common.exception.runtime.ValidationException; import lombok.Getter; diff --git a/src/main/java/com/dnd/gongmuin/chat/domain/MessageType.java b/src/main/java/com/dnd/gongmuin/chatroom/domain/MessageType.java similarity index 86% rename from src/main/java/com/dnd/gongmuin/chat/domain/MessageType.java rename to src/main/java/com/dnd/gongmuin/chatroom/domain/MessageType.java index 9850fee1..f469ceb1 100644 --- a/src/main/java/com/dnd/gongmuin/chat/domain/MessageType.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/domain/MessageType.java @@ -1,8 +1,8 @@ -package com.dnd.gongmuin.chat.domain; +package com.dnd.gongmuin.chatroom.domain; import java.util.Arrays; -import com.dnd.gongmuin.chat.exception.ChatErrorCode; +import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; import com.dnd.gongmuin.common.exception.runtime.ValidationException; import lombok.Getter; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/ChatMessageMapper.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatMessageMapper.java similarity index 76% rename from src/main/java/com/dnd/gongmuin/chat/dto/ChatMessageMapper.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/ChatMessageMapper.java index 8771d82a..98a45f07 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/ChatMessageMapper.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatMessageMapper.java @@ -1,10 +1,10 @@ -package com.dnd.gongmuin.chat.dto; +package com.dnd.gongmuin.chatroom.dto; -import com.dnd.gongmuin.chat.domain.ChatMessage; -import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.MessageType; -import com.dnd.gongmuin.chat.dto.request.ChatMessageRequest; -import com.dnd.gongmuin.chat.dto.response.ChatMessageResponse; +import com.dnd.gongmuin.chatroom.domain.ChatMessage; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.domain.MessageType; +import com.dnd.gongmuin.chatroom.dto.request.ChatMessageRequest; +import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/ChatRoomMapper.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java similarity index 81% rename from src/main/java/com/dnd/gongmuin/chat/dto/ChatRoomMapper.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java index a759af5a..3b24baf0 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/ChatRoomMapper.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java @@ -1,15 +1,15 @@ -package com.dnd.gongmuin.chat.dto; +package com.dnd.gongmuin.chatroom.dto; -import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.dto.response.AcceptChatResponse; -import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chat.dto.response.ChatProposalResponse; -import com.dnd.gongmuin.chat.dto.response.ChatRoomDetailResponse; -import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; -import com.dnd.gongmuin.chat.dto.response.ChatRoomSimpleResponse; -import com.dnd.gongmuin.chat.dto.response.CreateChatRoomResponse; -import com.dnd.gongmuin.chat.dto.response.LatestChatMessage; -import com.dnd.gongmuin.chat.dto.response.RejectChatResponse; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomDetailResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; +import com.dnd.gongmuin.chatroom.dto.response.CreateChatRoomResponse; +import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; +import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; import com.dnd.gongmuin.question_post.dto.response.MemberInfo; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/request/ChatMessageRequest.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/request/ChatMessageRequest.java similarity index 88% rename from src/main/java/com/dnd/gongmuin/chat/dto/request/ChatMessageRequest.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/request/ChatMessageRequest.java index 3fe88baf..650ac0c1 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/request/ChatMessageRequest.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/request/ChatMessageRequest.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.request; +package com.dnd.gongmuin.chatroom.dto.request; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/request/CreateChatRoomRequest.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/request/CreateChatRoomRequest.java similarity index 86% rename from src/main/java/com/dnd/gongmuin/chat/dto/request/CreateChatRoomRequest.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/request/CreateChatRoomRequest.java index d6ae8686..de940f12 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/request/CreateChatRoomRequest.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/request/CreateChatRoomRequest.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.request; +package com.dnd.gongmuin.chatroom.dto.request; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/AcceptChatResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/AcceptChatResponse.java similarity index 60% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/AcceptChatResponse.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/AcceptChatResponse.java index 5f64d562..b854c779 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/AcceptChatResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/AcceptChatResponse.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; public record AcceptChatResponse( String chatStatus, diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatMessageResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatMessageResponse.java similarity index 72% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/ChatMessageResponse.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatMessageResponse.java index 368fb1c7..ab02a180 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatMessageResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatMessageResponse.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; public record ChatMessageResponse( Long senderId, diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalInfo.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalInfo.java similarity index 86% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalInfo.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalInfo.java index 9d97036e..277f59a3 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalInfo.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalInfo.java @@ -1,6 +1,6 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; -import com.dnd.gongmuin.chat.domain.InquiryStatus; +import com.dnd.gongmuin.chatroom.domain.InquiryStatus; import com.dnd.gongmuin.member.domain.JobGroup; import com.querydsl.core.annotations.QueryProjection; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalResponse.java similarity index 84% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalResponse.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalResponse.java index 7dc09842..5af289e7 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatProposalResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalResponse.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; import com.dnd.gongmuin.question_post.dto.response.MemberInfo; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomDetailResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomDetailResponse.java similarity index 83% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomDetailResponse.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomDetailResponse.java index 390acf66..ebbea641 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomDetailResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomDetailResponse.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; import com.dnd.gongmuin.question_post.dto.response.MemberInfo; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomInfo.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomInfo.java similarity index 91% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomInfo.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomInfo.java index 52bc26f3..885c37d6 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomInfo.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomInfo.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; import com.dnd.gongmuin.member.domain.JobGroup; import com.querydsl.core.annotations.QueryProjection; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomSimpleResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomSimpleResponse.java similarity index 82% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomSimpleResponse.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomSimpleResponse.java index 136b893c..aa7fa435 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomSimpleResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatRoomSimpleResponse.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; import com.dnd.gongmuin.question_post.dto.response.MemberInfo; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/CreateChatRoomResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/CreateChatRoomResponse.java similarity index 82% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/CreateChatRoomResponse.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/CreateChatRoomResponse.java index 04622f6c..199ef30d 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/CreateChatRoomResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/CreateChatRoomResponse.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; import com.dnd.gongmuin.question_post.dto.response.MemberInfo; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/LatestChatMessage.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/LatestChatMessage.java similarity index 75% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/LatestChatMessage.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/LatestChatMessage.java index 57934805..cd73a5af 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/LatestChatMessage.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/LatestChatMessage.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; import java.time.LocalDateTime; diff --git a/src/main/java/com/dnd/gongmuin/chat/dto/response/RejectChatResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/RejectChatResponse.java similarity index 55% rename from src/main/java/com/dnd/gongmuin/chat/dto/response/RejectChatResponse.java rename to src/main/java/com/dnd/gongmuin/chatroom/dto/response/RejectChatResponse.java index ae22300e..1d532ef0 100644 --- a/src/main/java/com/dnd/gongmuin/chat/dto/response/RejectChatResponse.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/RejectChatResponse.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.dto.response; +package com.dnd.gongmuin.chatroom.dto.response; public record RejectChatResponse( String chatStatus diff --git a/src/main/java/com/dnd/gongmuin/chat/exception/ChatErrorCode.java b/src/main/java/com/dnd/gongmuin/chatroom/exception/ChatErrorCode.java similarity index 94% rename from src/main/java/com/dnd/gongmuin/chat/exception/ChatErrorCode.java rename to src/main/java/com/dnd/gongmuin/chatroom/exception/ChatErrorCode.java index 11635b5d..dca2559f 100644 --- a/src/main/java/com/dnd/gongmuin/chat/exception/ChatErrorCode.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/exception/ChatErrorCode.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.exception; +package com.dnd.gongmuin.chatroom.exception; import com.dnd.gongmuin.common.exception.ErrorCode; diff --git a/src/main/java/com/dnd/gongmuin/chat/repository/ChatMessageQueryRepository.java b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatMessageQueryRepository.java similarity index 93% rename from src/main/java/com/dnd/gongmuin/chat/repository/ChatMessageQueryRepository.java rename to src/main/java/com/dnd/gongmuin/chatroom/repository/ChatMessageQueryRepository.java index 50c7f193..7edf46a0 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatMessageQueryRepository.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatMessageQueryRepository.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.repository; +package com.dnd.gongmuin.chatroom.repository; import java.util.List; @@ -10,7 +10,7 @@ import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.stereotype.Component; -import com.dnd.gongmuin.chat.dto.response.LatestChatMessage; +import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/dnd/gongmuin/chat/repository/ChatMessageRepository.java b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatMessageRepository.java similarity index 80% rename from src/main/java/com/dnd/gongmuin/chat/repository/ChatMessageRepository.java rename to src/main/java/com/dnd/gongmuin/chatroom/repository/ChatMessageRepository.java index 1572e546..4a5f1c05 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatMessageRepository.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatMessageRepository.java @@ -1,11 +1,11 @@ -package com.dnd.gongmuin.chat.repository; +package com.dnd.gongmuin.chatroom.repository; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; -import com.dnd.gongmuin.chat.domain.ChatMessage; +import com.dnd.gongmuin.chatroom.domain.ChatMessage; @Repository public interface ChatMessageRepository extends MongoRepository { diff --git a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepository.java similarity index 72% rename from src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java rename to src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepository.java index d277b820..d1b7cea5 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepository.java @@ -1,12 +1,12 @@ -package com.dnd.gongmuin.chat.repository; +package com.dnd.gongmuin.chatroom.repository; import java.util.List; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; import com.dnd.gongmuin.member.domain.Member; public interface ChatRoomQueryRepository { diff --git a/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepositoryImpl.java b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepositoryImpl.java new file mode 100644 index 00000000..fc81ff99 --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepositoryImpl.java @@ -0,0 +1,131 @@ +package com.dnd.gongmuin.chatroom.repository; + + +import static com.dnd.gongmuin.chat.domain.QChatRoom.*; + +import java.time.LocalDateTime; +import java.util.List; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; + +import com.dnd.gongmuin.chatroom.domain.InquiryStatus; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; +import com.dnd.gongmuin.chat.dto.response.QChatProposalInfo; +import com.dnd.gongmuin.chat.dto.response.QChatRoomInfo; +import com.dnd.gongmuin.chatroom.domain.QChatRoom; +import com.dnd.gongmuin.chatroom.dto.response.QChatRoomInfo; +import com.dnd.gongmuin.member.domain.Member; +import com.querydsl.core.types.dsl.CaseBuilder; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class ChatRoomQueryRepositoryImpl implements ChatRoomQueryRepository { + + private final JPAQueryFactory queryFactory; + + public Slice getChatRoomsByMember( + Member member, + Pageable pageable + ) { + List content = queryFactory + .select(new QChatRoomInfo( + QChatRoom.chatRoom.id, + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(QChatRoom.chatRoom.answerer.id) + .otherwise(QChatRoom.chatRoom.inquirer.id), + + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(QChatRoom.chatRoom.answerer.nickname) + .otherwise(QChatRoom.chatRoom.inquirer.nickname), + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(QChatRoom.chatRoom.answerer.jobGroup) + .otherwise(QChatRoom.chatRoom.inquirer.jobGroup), + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(QChatRoom.chatRoom.answerer.profileImageNo) + .otherwise(QChatRoom.chatRoom.inquirer.profileImageNo) + )) + .from(QChatRoom.chatRoom) + .where(QChatRoom.chatRoom.inquirer.id.eq(member.getId()) + .or(QChatRoom.chatRoom.answerer.id.eq(member.getId())) + .and(QChatRoom.chatRoom.status.eq(InquiryStatus.ACCEPTED))) + .fetch(); + + boolean hasNext = hasNext(pageable.getPageSize(), content); + return new SliceImpl<>(content, pageable, hasNext); + } + + public Slice getChatProposalsByMember(Member member, Pageable pageable){ + List content = queryFactory + .select(new QChatProposalInfo( + QChatRoom.chatRoom.id, + QChatRoom.chatRoom.status, + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(true) + .otherwise(false), + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(QChatRoom.chatRoom.answerer.id) + .otherwise(QChatRoom.chatRoom.inquirer.id), + + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(QChatRoom.chatRoom.answerer.nickname) + .otherwise(QChatRoom.chatRoom.inquirer.nickname), + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(QChatRoom.chatRoom.answerer.jobGroup) + .otherwise(QChatRoom.chatRoom.inquirer.jobGroup), + new CaseBuilder() + .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) + .then(QChatRoom.chatRoom.answerer.profileImageNo) + .otherwise(QChatRoom.chatRoom.inquirer.profileImageNo) + )) + .from(QChatRoom.chatRoom) + .where(QChatRoom.chatRoom.inquirer.id.eq(member.getId()) + .or(QChatRoom.chatRoom.answerer.id.eq(member.getId())) + .and(QChatRoom.chatRoom.status.in(List.of(InquiryStatus.REJECTED, InquiryStatus.PENDING)))) + .fetch(); + + boolean hasNext = hasNext(pageable.getPageSize(), content); + return new SliceImpl<>(content, pageable, hasNext); + } + + public List getAutoRejectedInquirerIds() { + return queryFactory + .select(QChatRoom.chatRoom.inquirer.id) + .from(QChatRoom.chatRoom) + .where( + QChatRoom.chatRoom.createdAt.loe(LocalDateTime.now().minusWeeks(1)), + QChatRoom.chatRoom.status.eq(InquiryStatus.PENDING) + ) + .fetch(); + } + + public void updateChatRoomStatusRejected() { + queryFactory.update(QChatRoom.chatRoom) + .set(QChatRoom.chatRoom.status, InquiryStatus.REJECTED) + .where( + QChatRoom.chatRoom.createdAt.loe(LocalDateTime.now().minusWeeks(1)), + QChatRoom.chatRoom.status.eq(InquiryStatus.PENDING) + ) + .execute(); + } + + private boolean hasNext(int pageSize, List items) { + if (items.size() <= pageSize) { + return false; + } + items.remove(pageSize); + return true; + } +} diff --git a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomRepository.java b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomRepository.java similarity index 63% rename from src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomRepository.java rename to src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomRepository.java index 8499787d..ddd13b13 100644 --- a/src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomRepository.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomRepository.java @@ -1,8 +1,8 @@ -package com.dnd.gongmuin.chat.repository; +package com.dnd.gongmuin.chatroom.repository; import org.springframework.data.jpa.repository.JpaRepository; -import com.dnd.gongmuin.chat.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; public interface ChatRoomRepository extends JpaRepository, ChatRoomQueryRepository { } diff --git a/src/main/java/com/dnd/gongmuin/chat/scheduler/ChatScheduler.java b/src/main/java/com/dnd/gongmuin/chatroom/scheduler/ChatScheduler.java similarity index 82% rename from src/main/java/com/dnd/gongmuin/chat/scheduler/ChatScheduler.java rename to src/main/java/com/dnd/gongmuin/chatroom/scheduler/ChatScheduler.java index 54a0e03e..d5ca459e 100644 --- a/src/main/java/com/dnd/gongmuin/chat/scheduler/ChatScheduler.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/scheduler/ChatScheduler.java @@ -1,10 +1,10 @@ -package com.dnd.gongmuin.chat.scheduler; +package com.dnd.gongmuin.chatroom.scheduler; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import com.dnd.gongmuin.chat.service.ChatRoomService; +import com.dnd.gongmuin.chatroom.service.ChatRoomService; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/dnd/gongmuin/chat/service/ChatMessageService.java b/src/main/java/com/dnd/gongmuin/chatroom/service/ChatMessageService.java similarity index 68% rename from src/main/java/com/dnd/gongmuin/chat/service/ChatMessageService.java rename to src/main/java/com/dnd/gongmuin/chatroom/service/ChatMessageService.java index e9b248bf..9be22443 100644 --- a/src/main/java/com/dnd/gongmuin/chat/service/ChatMessageService.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/service/ChatMessageService.java @@ -1,13 +1,13 @@ -package com.dnd.gongmuin.chat.service; +package com.dnd.gongmuin.chatroom.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.dnd.gongmuin.chat.domain.ChatMessage; -import com.dnd.gongmuin.chat.dto.ChatMessageMapper; -import com.dnd.gongmuin.chat.dto.request.ChatMessageRequest; -import com.dnd.gongmuin.chat.dto.response.ChatMessageResponse; -import com.dnd.gongmuin.chat.repository.ChatMessageRepository; +import com.dnd.gongmuin.chatroom.domain.ChatMessage; +import com.dnd.gongmuin.chatroom.dto.ChatMessageMapper; +import com.dnd.gongmuin.chatroom.dto.request.ChatMessageRequest; +import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; +import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java b/src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java similarity index 88% rename from src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java rename to src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java index 71a7cb40..0657708a 100644 --- a/src/main/java/com/dnd/gongmuin/chat/service/ChatRoomService.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chat.service; +package com.dnd.gongmuin.chatroom.service; import java.util.Comparator; import java.util.List; @@ -12,24 +12,24 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.dto.ChatMessageMapper; -import com.dnd.gongmuin.chat.dto.ChatRoomMapper; -import com.dnd.gongmuin.chat.dto.request.CreateChatRoomRequest; -import com.dnd.gongmuin.chat.dto.response.AcceptChatResponse; -import com.dnd.gongmuin.chat.dto.response.ChatMessageResponse; -import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chat.dto.response.ChatProposalResponse; -import com.dnd.gongmuin.chat.dto.response.ChatRoomDetailResponse; -import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; -import com.dnd.gongmuin.chat.dto.response.ChatRoomSimpleResponse; -import com.dnd.gongmuin.chat.dto.response.CreateChatRoomResponse; -import com.dnd.gongmuin.chat.dto.response.LatestChatMessage; -import com.dnd.gongmuin.chat.dto.response.RejectChatResponse; -import com.dnd.gongmuin.chat.exception.ChatErrorCode; -import com.dnd.gongmuin.chat.repository.ChatMessageQueryRepository; -import com.dnd.gongmuin.chat.repository.ChatMessageRepository; -import com.dnd.gongmuin.chat.repository.ChatRoomRepository; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.dto.ChatMessageMapper; +import com.dnd.gongmuin.chatroom.dto.ChatRoomMapper; +import com.dnd.gongmuin.chatroom.dto.request.CreateChatRoomRequest; +import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomDetailResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; +import com.dnd.gongmuin.chatroom.dto.response.CreateChatRoomResponse; +import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; +import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; +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.common.dto.PageMapper; import com.dnd.gongmuin.common.dto.PageResponse; import com.dnd.gongmuin.common.exception.runtime.NotFoundException; 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 699f206a..bf36f111 100644 --- a/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java @@ -13,12 +13,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -import com.dnd.gongmuin.chat.domain.ChatMessage; -import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.InquiryStatus; -import com.dnd.gongmuin.chat.dto.request.CreateChatRoomRequest; -import com.dnd.gongmuin.chat.repository.ChatMessageRepository; -import com.dnd.gongmuin.chat.repository.ChatRoomRepository; +import com.dnd.gongmuin.chatroom.domain.ChatMessage; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.domain.InquiryStatus; +import com.dnd.gongmuin.chatroom.dto.request.CreateChatRoomRequest; +import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; +import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; import com.dnd.gongmuin.common.fixture.ChatMessageFixture; import com.dnd.gongmuin.common.fixture.ChatRoomFixture; import com.dnd.gongmuin.common.fixture.MemberFixture; diff --git a/src/test/java/com/dnd/gongmuin/chat/repository/ChatMessageQueryRepositoryTest.java b/src/test/java/com/dnd/gongmuin/chat/repository/ChatMessageQueryRepositoryTest.java index 085ccf7a..b50db93f 100644 --- a/src/test/java/com/dnd/gongmuin/chat/repository/ChatMessageQueryRepositoryTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/repository/ChatMessageQueryRepositoryTest.java @@ -12,7 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import com.dnd.gongmuin.chat.dto.response.LatestChatMessage; +import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; +import com.dnd.gongmuin.chatroom.repository.ChatMessageQueryRepository; +import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; import com.dnd.gongmuin.common.fixture.ChatMessageFixture; import com.dnd.gongmuin.common.support.TestContainerSupport; 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 3a44a458..b78f1791 100644 --- a/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java @@ -13,10 +13,11 @@ import org.springframework.data.domain.PageRequest; import org.springframework.test.util.ReflectionTestUtils; -import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.InquiryStatus; -import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.domain.InquiryStatus; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; +import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; import com.dnd.gongmuin.common.fixture.ChatRoomFixture; import com.dnd.gongmuin.common.fixture.MemberFixture; import com.dnd.gongmuin.common.fixture.QuestionPostFixture; 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 d63e9d9b..c171926b 100644 --- a/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java @@ -19,25 +19,26 @@ import org.springframework.data.domain.SliceImpl; import org.springframework.test.util.ReflectionTestUtils; -import com.dnd.gongmuin.chat.domain.ChatMessage; -import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.InquiryStatus; -import com.dnd.gongmuin.chat.domain.MessageType; -import com.dnd.gongmuin.chat.dto.request.CreateChatRoomRequest; -import com.dnd.gongmuin.chat.dto.response.AcceptChatResponse; -import com.dnd.gongmuin.chat.dto.response.ChatMessageResponse; -import com.dnd.gongmuin.chat.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chat.dto.response.ChatProposalResponse; -import com.dnd.gongmuin.chat.dto.response.ChatRoomDetailResponse; -import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; -import com.dnd.gongmuin.chat.dto.response.ChatRoomSimpleResponse; -import com.dnd.gongmuin.chat.dto.response.CreateChatRoomResponse; -import com.dnd.gongmuin.chat.dto.response.LatestChatMessage; -import com.dnd.gongmuin.chat.dto.response.RejectChatResponse; -import com.dnd.gongmuin.chat.exception.ChatErrorCode; -import com.dnd.gongmuin.chat.repository.ChatMessageQueryRepository; -import com.dnd.gongmuin.chat.repository.ChatMessageRepository; -import com.dnd.gongmuin.chat.repository.ChatRoomRepository; +import com.dnd.gongmuin.chatroom.domain.ChatMessage; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.domain.InquiryStatus; +import com.dnd.gongmuin.chatroom.domain.MessageType; +import com.dnd.gongmuin.chatroom.dto.request.CreateChatRoomRequest; +import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatProposalResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomDetailResponse; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; +import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; +import com.dnd.gongmuin.chatroom.dto.response.CreateChatRoomResponse; +import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; +import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; +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; diff --git a/src/test/java/com/dnd/gongmuin/common/fixture/ChatMessageFixture.java b/src/test/java/com/dnd/gongmuin/common/fixture/ChatMessageFixture.java index f907d048..bc859239 100644 --- a/src/test/java/com/dnd/gongmuin/common/fixture/ChatMessageFixture.java +++ b/src/test/java/com/dnd/gongmuin/common/fixture/ChatMessageFixture.java @@ -4,8 +4,8 @@ import org.springframework.test.util.ReflectionTestUtils; -import com.dnd.gongmuin.chat.domain.ChatMessage; -import com.dnd.gongmuin.chat.domain.MessageType; +import com.dnd.gongmuin.chatroom.domain.ChatMessage; +import com.dnd.gongmuin.chatroom.domain.MessageType; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java b/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java index c1e88d39..7b1e9b41 100644 --- a/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java +++ b/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java @@ -2,8 +2,8 @@ import org.springframework.test.util.ReflectionTestUtils; -import com.dnd.gongmuin.chat.domain.ChatRoom; -import com.dnd.gongmuin.chat.domain.InquiryStatus; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.domain.InquiryStatus; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; From b7d2a756595187208a28b289b0692216b88a686f Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:00:44 +0900 Subject: [PATCH 08/44] =?UTF-8?q?[rename]=20:=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EA=B4=80=EB=A0=A8=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gongmuin/{chatroom => chat_inquiry}/domain/ChatInquiry.java | 2 +- .../{chatroom => chat_inquiry}/domain/InquiryStatus.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/main/java/com/dnd/gongmuin/{chatroom => chat_inquiry}/domain/ChatInquiry.java (98%) rename src/main/java/com/dnd/gongmuin/{chatroom => chat_inquiry}/domain/InquiryStatus.java (93%) diff --git a/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatInquiry.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java similarity index 98% rename from src/main/java/com/dnd/gongmuin/chatroom/domain/ChatInquiry.java rename to src/main/java/com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java index def4c84d..86efde25 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatInquiry.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/domain/ChatInquiry.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chatroom.domain; +package com.dnd.gongmuin.chat_inquiry.domain; import static jakarta.persistence.ConstraintMode.*; import static jakarta.persistence.EnumType.*; diff --git a/src/main/java/com/dnd/gongmuin/chatroom/domain/InquiryStatus.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/domain/InquiryStatus.java similarity index 93% rename from src/main/java/com/dnd/gongmuin/chatroom/domain/InquiryStatus.java rename to src/main/java/com/dnd/gongmuin/chat_inquiry/domain/InquiryStatus.java index 66723e0f..4a940ad0 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/domain/InquiryStatus.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/domain/InquiryStatus.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chatroom.domain; +package com.dnd.gongmuin.chat_inquiry.domain; import java.util.Arrays; From 0f27c1c68c7629919789b8105ed60f289a840804 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:01:28 +0900 Subject: [PATCH 09/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_inquiry/dto/ChatInquiryResponse.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java 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 new file mode 100644 index 00000000..60650583 --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java @@ -0,0 +1,39 @@ +package com.dnd.gongmuin.chat_inquiry.dto; + +import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; +import com.dnd.gongmuin.member.domain.JobGroup; +import com.querydsl.core.annotations.QueryProjection; + +public record ChatInquiryResponse( + Long chatInquiryId, + String message, + String chatStatus, + boolean isInquirer, + Long partnerId, + String partnerNickname, + String partnerJobGroup, + int partnerProfileImageNo +) { + @QueryProjection + public ChatInquiryResponse( + Long chatInquiryId, + String message, + InquiryStatus inquiryStatus, + boolean isInquirer, + Long partnerId, + String partnerNickname, + JobGroup partnerJobGroup, + int partnerProfileImageNo + ) { + this( + chatInquiryId, + message, + inquiryStatus.getLabel(), + isInquirer, + partnerId, + partnerNickname, + partnerJobGroup.getLabel(), + partnerProfileImageNo + ); + } +} From 74318aa7c5f1fdadeeeb115253c40ae819631c40 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:01:49 +0900 Subject: [PATCH 10/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EA=B4=80=EB=A0=A8=20repository=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChatInquiryQueryRepository.java | 17 ++++ .../ChatInquiryQueryRepositoryImpl.java | 92 +++++++++++++++++++ .../repository/ChatInquiryRepository.java | 8 ++ 3 files changed, 117 insertions(+) create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryQueryRepository.java create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryQueryRepositoryImpl.java create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepository.java diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryQueryRepository.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryQueryRepository.java new file mode 100644 index 00000000..126d693f --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryQueryRepository.java @@ -0,0 +1,17 @@ +package com.dnd.gongmuin.chat_inquiry.repository; + +import java.util.List; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; + +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; +import com.dnd.gongmuin.member.domain.Member; + +public interface ChatInquiryQueryRepository { + Slice getChatInquiresByMember(Member member, Pageable pageable); + + List getAutoRejectedInquirerIds(); + + void updateChatInquiryStatusRejected(); +} diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryQueryRepositoryImpl.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryQueryRepositoryImpl.java new file mode 100644 index 00000000..0510d2df --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryQueryRepositoryImpl.java @@ -0,0 +1,92 @@ +package com.dnd.gongmuin.chat_inquiry.repository; + +import static com.dnd.gongmuin.chat_inquiry.domain.QChatInquiry.*; + +import java.time.LocalDateTime; +import java.util.List; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.SliceImpl; + +import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; +import com.dnd.gongmuin.chat_inquiry.dto.QChatInquiryResponse; +import com.dnd.gongmuin.member.domain.Member; +import com.querydsl.core.types.dsl.CaseBuilder; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class ChatInquiryQueryRepositoryImpl implements ChatInquiryQueryRepository { + + private final JPAQueryFactory queryFactory; + + public Slice getChatInquiresByMember(Member member, Pageable pageable) { + List content = queryFactory + .select(new QChatInquiryResponse( + chatInquiry.id, + chatInquiry.message, + chatInquiry.status, + new CaseBuilder() + .when(chatInquiry.inquirer.id.eq(member.getId())) + .then(true) + .otherwise(false), + new CaseBuilder() + .when(chatInquiry.inquirer.id.eq(member.getId())) + .then(chatInquiry.answerer.id) + .otherwise(chatInquiry.inquirer.id), + new CaseBuilder() + .when(chatInquiry.inquirer.id.eq(member.getId())) + .then(chatInquiry.answerer.nickname) + .otherwise(chatInquiry.inquirer.nickname), + new CaseBuilder() + .when(chatInquiry.inquirer.id.eq(member.getId())) + .then(chatInquiry.answerer.jobGroup) + .otherwise(chatInquiry.inquirer.jobGroup), + new CaseBuilder() + .when(chatInquiry.inquirer.id.eq(member.getId())) + .then(chatInquiry.answerer.profileImageNo) + .otherwise(chatInquiry.inquirer.profileImageNo) + )) + .from(chatInquiry) + .where(chatInquiry.inquirer.id.eq(member.getId()) + .or(chatInquiry.answerer.id.eq(member.getId())) + .and(chatInquiry.status.in(List.of(InquiryStatus.REJECTED, InquiryStatus.PENDING)))) + .orderBy(chatInquiry.createdAt.desc()) + .fetch(); + + boolean hasNext = hasNext(pageable.getPageSize(), content); + return new SliceImpl<>(content, pageable, hasNext); + } + + public List getAutoRejectedInquirerIds() { + return queryFactory + .select(chatInquiry.inquirer.id) + .from(chatInquiry) + .where( + chatInquiry.createdAt.loe(LocalDateTime.now().minusWeeks(1)), + chatInquiry.status.eq(InquiryStatus.PENDING) + ) + .fetch(); + } + + public void updateChatInquiryStatusRejected() { + queryFactory.update(chatInquiry) + .set(chatInquiry.status, InquiryStatus.REJECTED) + .where( + chatInquiry.createdAt.loe(LocalDateTime.now().minusWeeks(1)), + chatInquiry.status.eq(InquiryStatus.PENDING) + ) + .execute(); + } + + private boolean hasNext(int pageSize, List items) { + if (items.size() <= pageSize) { + return false; + } + items.remove(pageSize); + return true; + } +} diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepository.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepository.java new file mode 100644 index 00000000..a10cb885 --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepository.java @@ -0,0 +1,8 @@ +package com.dnd.gongmuin.chat_inquiry.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; + +public interface ChatInquiryRepository extends JpaRepository, ChatInquiryQueryRepository { +} From fe72adba523f2c6bd99f986c35104268bf74a8d5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:06:16 +0900 Subject: [PATCH 11/44] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20repository=20=EB=8F=99=EC=A0=81=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=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 --- .../repository/ChatInquiryRepositoryTest.java | 100 ++++++++++++++++++ .../common/fixture/ChatInquiryFixture.java | 26 +++++ 2 files changed, 126 insertions(+) create mode 100644 src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java create mode 100644 src/test/java/com/dnd/gongmuin/common/fixture/ChatInquiryFixture.java diff --git a/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java b/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java new file mode 100644 index 00000000..b720eee2 --- /dev/null +++ b/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java @@ -0,0 +1,100 @@ +package com.dnd.gongmuin.chat_inquiry.repository; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +import java.time.LocalDateTime; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.test.util.ReflectionTestUtils; +import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; +import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; +import com.dnd.gongmuin.common.fixture.ChatInquiryFixture; +import com.dnd.gongmuin.common.fixture.MemberFixture; +import com.dnd.gongmuin.common.fixture.QuestionPostFixture; +import com.dnd.gongmuin.common.support.DataJpaTestSupport; +import com.dnd.gongmuin.credit_history.repository.CreditHistoryRepository; +import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.member.repository.MemberRepository; +import com.dnd.gongmuin.question_post.domain.QuestionPost; +import com.dnd.gongmuin.question_post.repository.QuestionPostRepository; + +@DisplayName("[ChatInquiryRepository 테스트]") +class ChatInquiryRepositoryTest extends DataJpaTestSupport { + + private final PageRequest pageRequest = PageRequest.of(0, 10); + private final String chatMessage = "와우"; + + @Autowired + ChatInquiryRepository chatInquiryRepository; + @Autowired + MemberRepository memberRepository; + @Autowired + QuestionPostRepository questionPostRepository; + + @Autowired + CreditHistoryRepository creditHistoryRepository; + + @DisplayName("회원의 채팅 요청 목록을 조회할 수 있다.") + @Test + void getChatInquiresByMember() { + //given + Member questioner = memberRepository.save(MemberFixture.member()); + Member target = memberRepository.save(MemberFixture.member()); + Member answerer = memberRepository.save(MemberFixture.member()); + QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(questioner)); + List chatInquiries = chatInquiryRepository.saveAll(List.of( + chatInquiryRepository.save(ChatInquiryFixture.chatInquiry(questionPost, target, answerer, chatMessage)), + chatInquiryRepository.save(ChatInquiryFixture.chatInquiry(questionPost, questioner, target, chatMessage)), + chatInquiryRepository.save(ChatInquiryFixture.chatInquiry(questionPost, questioner, answerer, chatMessage)) + )); + + //when + List responses = chatInquiryRepository.getChatInquiresByMember(target, pageRequest) + .getContent(); + + //then + Assertions.assertAll( + () -> assertThat(responses).hasSize(2), + () -> assertThat(responses.get(0).chatInquiryId()).isEqualTo(chatInquiries.get(1).getId()), + () -> assertThat(responses.get(0).partnerId()).isEqualTo(questioner.getId()), + () -> assertThat(responses.get(1).chatInquiryId()).isEqualTo(chatInquiries.get(0).getId()), + () -> assertThat(responses.get(1).partnerId()).isEqualTo(answerer.getId()) + ); + } + + @DisplayName("요청중인 채팅방이 일주일이 지나면, 채팅방 상태를 거절함으로 바꾼다.") + @Test + void updateChatInquiryStatusRejected() { + //given + Member questioner = memberRepository.save(MemberFixture.member()); + Member answerer = memberRepository.save(MemberFixture.member()); + QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(questioner)); + + List chatInquiries = chatInquiryRepository.saveAll(List.of( + chatInquiryRepository.save(ChatInquiryFixture.chatInquiry(questionPost, questioner, answerer, chatMessage)), + chatInquiryRepository.save(ChatInquiryFixture.chatInquiry(questionPost, questioner, answerer, chatMessage)) + )); + ReflectionTestUtils.setField(chatInquiries.get(0), "createdAt", LocalDateTime.now().minusWeeks(1)); + + //when + chatInquiryRepository.updateChatInquiryStatusRejected(); + + em.flush(); + em.clear(); + + //then + ChatInquiry chatInquiry1 = chatInquiryRepository.findById(chatInquiries.get(0).getId()).orElseThrow(); + ChatInquiry chatInquiry2 = chatInquiryRepository.findById(chatInquiries.get(1).getId()).orElseThrow(); + assertAll( + () -> assertThat(chatInquiry1.getStatus()).isEqualTo(InquiryStatus.REJECTED), + () -> assertThat(chatInquiry2.getStatus()).isEqualTo(InquiryStatus.PENDING) + ); + } +} \ No newline at end of file diff --git a/src/test/java/com/dnd/gongmuin/common/fixture/ChatInquiryFixture.java b/src/test/java/com/dnd/gongmuin/common/fixture/ChatInquiryFixture.java new file mode 100644 index 00000000..0a96912c --- /dev/null +++ b/src/test/java/com/dnd/gongmuin/common/fixture/ChatInquiryFixture.java @@ -0,0 +1,26 @@ +package com.dnd.gongmuin.common.fixture; + +import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; +import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.question_post.domain.QuestionPost; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ChatInquiryFixture { + + public static ChatInquiry chatInquiry( + QuestionPost questionPost, + Member inquirer, + Member answerer, + String message + ) { + return ChatInquiry.of( + questionPost, + inquirer, + answerer, + message + ); + } +} From 92f41f10e5c06ce5aede513e46127bba1a7a0277 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:16:07 +0900 Subject: [PATCH 12/44] =?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=9D=EC=84=B1=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/CreateChatInquiryRequest.java | 15 +++++++++++++++ .../dto/CreateChatInquiryResponse.java | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryRequest.java create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryResponse.java diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryRequest.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryRequest.java new file mode 100644 index 00000000..c88d4c2a --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryRequest.java @@ -0,0 +1,15 @@ +package com.dnd.gongmuin.chat_inquiry.dto; + +import jakarta.validation.constraints.NotNull; + +public record CreateChatInquiryRequest( + @NotNull(message = "질문 게시글 아이디는 필수 입력 항목입니다.") + Long questionPostId, + + @NotNull(message = "답변자 아이디는 필수 입력 항목입니다.") + Long answererId, + + @NotNull(message = "요청 메시지는 필수 입력 항목입니다.") + String message +) { +} 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 new file mode 100644 index 00000000..96beff32 --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/CreateChatInquiryResponse.java @@ -0,0 +1,12 @@ +package com.dnd.gongmuin.chat_inquiry.dto; + +public record CreateChatInquiryResponse( + Long chatInquiryId, + String message, + String chatStatus, + Long partnerId, + String partnerNickname, + String partnerJobGroup, + int partnerProfileImageNo +) { +} From 7683018da170dc35ed5373ea6b71d44af00b5b7c Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:16:26 +0900 Subject: [PATCH 13/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20dto=20mapper=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/ChatInquiryMapper.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryMapper.java 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 new file mode 100644 index 00000000..d978f995 --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/ChatInquiryMapper.java @@ -0,0 +1,45 @@ +package com.dnd.gongmuin.chat_inquiry.dto; + +import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; +import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; +import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; +import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.question_post.domain.QuestionPost; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ChatInquiryMapper { + + public static ChatInquiry toChatInquiry( + QuestionPost questionPost, + Member inquirer, + Member answerer, + String message + ) { + return ChatInquiry.of( + questionPost, + inquirer, + answerer, + message + ); + } + + public static CreateChatInquiryResponse toCreateChatInquiryResponse( + ChatInquiry chatInquiry + ) { + Member answerer = chatInquiry.getAnswerer(); + return new CreateChatInquiryResponse( + chatInquiry.getId(), + chatInquiry.getMessage(), + InquiryStatus.PENDING.getLabel(), + answerer.getId(), + answerer.getNickname(), + answerer.getJobGroup().getLabel(), + answerer.getProfileImageNo() + ); + } +} From e6648dc6daafd68501889ce2471217916838682f Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:23:04 +0900 Subject: [PATCH 14/44] =?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=9D=EC=84=B1=20API=20=EB=A9=94?= =?UTF-8?q?=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 | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryController.java 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 new file mode 100644 index 00000000..6b0fe7ca --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryController.java @@ -0,0 +1,41 @@ +package com.dnd.gongmuin.chat_inquiry.controller; + +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; +import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; +import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryResponse; +import com.dnd.gongmuin.chat_inquiry.dto.RejectChatResponse; +import com.dnd.gongmuin.chat_inquiry.service.ChatInquiryService; +import com.dnd.gongmuin.common.dto.PageResponse; +import com.dnd.gongmuin.member.domain.Member; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; + +@Tag(name = "채팅 요청 API") +@RestController +@RequiredArgsConstructor +public class ChatInquiryController { + + private final ChatInquiryService chatInquiryService; + + @Operation(summary = "채팅 요청 API", description = "답변자 아이디로 채팅 요청을 생성한다.") + @GetMapping("/api/chat/inquiries") + public ResponseEntity getChatProposalsByMember( + CreateChatInquiryRequest request, + @AuthenticationPrincipal Member member + ) { + CreateChatInquiryResponse response + = chatInquiryService.createChatInquiry(request, member); + return ResponseEntity.ok(response); + } +} From 1847d29992a757d46f72a1d15447cebfb1cab517 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:24:52 +0900 Subject: [PATCH 15/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=88=98=EB=9D=BD=20=EB=B0=8F=20=EA=B1=B0?= =?UTF-8?q?=EC=A0=88=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ChatInquiryService.java | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/main/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryService.java 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 new file mode 100644 index 00000000..85749783 --- /dev/null +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryService.java @@ -0,0 +1,127 @@ +package com.dnd.gongmuin.chat_inquiry.service; + +import java.util.List; +import java.util.Objects; + +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; +import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryMapper; +import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; +import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryResponse; +import com.dnd.gongmuin.chat_inquiry.repository.ChatInquiryRepository; +import com.dnd.gongmuin.chat_inquiry.dto.RejectChatResponse; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.dto.ChatRoomMapper; +import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; +import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; +import com.dnd.gongmuin.common.exception.runtime.NotFoundException; +import com.dnd.gongmuin.common.exception.runtime.ValidationException; +import com.dnd.gongmuin.credit_history.domain.CreditType; +import com.dnd.gongmuin.credit_history.service.CreditHistoryService; +import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.member.exception.MemberErrorCode; +import com.dnd.gongmuin.member.repository.MemberRepository; +import com.dnd.gongmuin.notification.domain.NotificationType; +import com.dnd.gongmuin.notification.dto.NotificationEvent; +import com.dnd.gongmuin.question_post.domain.QuestionPost; +import com.dnd.gongmuin.question_post.exception.QuestionPostErrorCode; +import com.dnd.gongmuin.question_post.repository.QuestionPostRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class ChatInquiryService { + + private static final int CHAT_REWARD = 2000; + private final ChatInquiryRepository chatInquiryRepository; + private final ChatRoomRepository chatRoomRepository; + private final MemberRepository memberRepository; + private final QuestionPostRepository questionPostRepository; + private final CreditHistoryService creditHistoryService; + private final ApplicationEventPublisher eventPublisher; + + @Transactional + public CreateChatInquiryResponse createChatInquiry(CreateChatInquiryRequest request, Member inquirer) { + QuestionPost questionPost = getQuestionPostById(request.questionPostId()); + Member answerer = getMemberById(request.answererId()); + + ChatInquiry chatInquiry = chatInquiryRepository.save( + ChatInquiryMapper.toChatInquiry(questionPost, inquirer, answerer, request.message()) + ); + + eventPublisher.publishEvent( + new NotificationEvent(NotificationType.CHAT_REQUEST, chatInquiry.getId(), inquirer.getId(), answerer) + ); + creditHistoryService.saveChatCreditHistory(CreditType.CHAT_REQUEST, inquirer); + + return ChatInquiryMapper.toCreateChatInquiryResponse(chatInquiry); + } + + @Transactional + public AcceptChatResponse acceptChat(Long chatInquiryId, Member answerer) { + ChatInquiry chatInquiry = getChatProposalById(chatInquiryId); + validateIfAnswerer(answerer, chatInquiry); + chatInquiry.updateStatusAccepted(); + creditHistoryService.saveChatCreditHistory(CreditType.CHAT_ACCEPT, answerer); + + ChatRoom chatRoom = chatRoomRepository.save( + ChatRoomMapper.toChatRoom(chatInquiry.getQuestionPost(), chatInquiry.getInquirer(), answerer) + ); + eventPublisher.publishEvent( + new NotificationEvent(NotificationType.CHAT_ACCEPT, chatInquiry.getId(), answerer.getId(), + chatInquiry.getInquirer()) + ); + + return ChatInquiryMapper.toAcceptChatResponse(chatInquiry, chatRoom); + } + + @Transactional + public RejectChatResponse rejectChat(Long chatInquiryId, Member answerer) { + ChatInquiry chatInquiry = getChatProposalById(chatInquiryId); + + validateIfAnswerer(answerer, chatInquiry); + chatInquiry.updateStatusRejected(); + creditHistoryService.saveChatCreditHistory(CreditType.CHAT_REFUND, chatInquiry.getInquirer()); + eventPublisher.publishEvent( + new NotificationEvent(NotificationType.CHAT_REJECT, chatInquiry.getId(), answerer.getId(), + chatInquiry.getInquirer()) + ); + + return ChatInquiryMapper.toRejectChatResponse(chatInquiry); + } + + @Transactional + public void rejectChatAuto() { + List rejectedInquirerIds = chatInquiryRepository.getAutoRejectedInquirerIds(); + chatInquiryRepository.updateChatInquiryStatusRejected(); + memberRepository.refundInMemberIds(rejectedInquirerIds, CHAT_REWARD); + creditHistoryService.saveCreditHistoryInMemberIds(rejectedInquirerIds, CreditType.CHAT_REFUND, CHAT_REWARD); + } + + private ChatInquiry getChatProposalById(Long id) { + return chatInquiryRepository.findById(id) + .orElseThrow(() -> new NotFoundException(ChatErrorCode.NOT_FOUND_CHAT_ROOM)); + } + + private static void validateIfAnswerer(Member member, ChatInquiry chatInquiry) { + if (!Objects.equals(member.getId(), chatInquiry.getAnswerer().getId())) { + throw new ValidationException(ChatErrorCode.UNAUTHORIZED_REQUEST); + } + } + + + private QuestionPost getQuestionPostById(Long id) { + return questionPostRepository.findById(id) + .orElseThrow(() -> new NotFoundException(QuestionPostErrorCode.NOT_FOUND_QUESTION_POST)); + } + + private Member getMemberById(Long id) { + return memberRepository.findById(id) + .orElseThrow(() -> new NotFoundException(MemberErrorCode.NOT_FOUND_MEMBER)); + } +} From da6927374007dc2cfac80f5f537c0a060eab5706 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:25:47 +0900 Subject: [PATCH 16/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=88=98=EB=9D=BD=20=EB=B0=8F=20=EA=B1=B0?= =?UTF-8?q?=EC=A0=88=20API=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChatInquiryController.java | 20 +++++++++++++++++++ .../dto}/AcceptChatResponse.java | 3 ++- .../dto}/RejectChatResponse.java | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) rename src/main/java/com/dnd/gongmuin/{chatroom/dto/response => chat_inquiry/dto}/AcceptChatResponse.java (51%) rename src/main/java/com/dnd/gongmuin/{chatroom/dto/response => chat_inquiry/dto}/RejectChatResponse.java (55%) 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 6b0fe7ca..ab74f818 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 @@ -38,4 +38,24 @@ public ResponseEntity getChatProposalsByMember( = chatInquiryService.createChatInquiry(request, member); return ResponseEntity.ok(response); } + + @Operation(summary = "채팅 수락 API", description = "채팅방에서 요청자와의 채팅을 수락한다.") + @PatchMapping("/api/chat/inquires/{chatInquiryId}/accept") + public ResponseEntity acceptChat( + @PathVariable("chatInquiryId") Long chatInquiryId, + @AuthenticationPrincipal Member member + ) { + AcceptChatResponse response = chatInquiryService.acceptChat(chatInquiryId, member); + return ResponseEntity.ok(response); + } + + @Operation(summary = "채팅 거절 API", description = "채팅방에서 요청자와의 채팅을 거절한다.") + @PatchMapping("/api/chat/inquires/{chatInquiryId}/reject") + public ResponseEntity rejectChat( + @PathVariable("chatInquiryId") Long chatInquiryId, + @AuthenticationPrincipal Member member + ) { + RejectChatResponse response = chatInquiryService.rejectChat(chatInquiryId, member); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/AcceptChatResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/AcceptChatResponse.java similarity index 51% rename from src/main/java/com/dnd/gongmuin/chatroom/dto/response/AcceptChatResponse.java rename to src/main/java/com/dnd/gongmuin/chat_inquiry/dto/AcceptChatResponse.java index b854c779..2d1d9188 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/AcceptChatResponse.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/AcceptChatResponse.java @@ -1,6 +1,7 @@ -package com.dnd.gongmuin.chatroom.dto.response; +package com.dnd.gongmuin.chat_inquiry.dto; public record AcceptChatResponse( + Long createdChatRoomId, String chatStatus, int credit ) { diff --git a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/RejectChatResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/RejectChatResponse.java similarity index 55% rename from src/main/java/com/dnd/gongmuin/chatroom/dto/response/RejectChatResponse.java rename to src/main/java/com/dnd/gongmuin/chat_inquiry/dto/RejectChatResponse.java index 1d532ef0..d4310260 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/RejectChatResponse.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/RejectChatResponse.java @@ -1,4 +1,4 @@ -package com.dnd.gongmuin.chatroom.dto.response; +package com.dnd.gongmuin.chat_inquiry.dto; public record RejectChatResponse( String chatStatus From 20dc9b75e23c9bb3528f63fc609f1f0aa626ca03 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:27:18 +0900 Subject: [PATCH 17/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EB=AA=A9=EB=A1=9D=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/service/ChatInquiryService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 85749783..5dbaa7d9 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 @@ -4,12 +4,15 @@ import java.util.Objects; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryMapper; +import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryResponse; import com.dnd.gongmuin.chat_inquiry.repository.ChatInquiryRepository; @@ -18,6 +21,8 @@ import com.dnd.gongmuin.chatroom.dto.ChatRoomMapper; import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; +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.credit_history.domain.CreditType; @@ -62,6 +67,14 @@ public CreateChatInquiryResponse createChatInquiry(CreateChatInquiryRequest requ return ChatInquiryMapper.toCreateChatInquiryResponse(chatInquiry); } + @Transactional(readOnly = true) + public PageResponse getChatInquiresByMember(Member member, Pageable pageable) { + Slice responsePage = chatInquiryRepository.getChatInquiresByMember( + member, pageable + ); + return PageMapper.toPageResponse(responsePage); + } + @Transactional public AcceptChatResponse acceptChat(Long chatInquiryId, Member answerer) { ChatInquiry chatInquiry = getChatProposalById(chatInquiryId); From dfe26aa11bb4aee1f6a019cdfe0867856a60b77a Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:28:12 +0900 Subject: [PATCH 18/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EB=AA=A9=EB=A1=9D=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 | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 ab74f818..9ff0cdfd 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 @@ -39,6 +39,17 @@ public ResponseEntity getChatProposalsByMember( return ResponseEntity.ok(response); } + @Operation(summary = "채팅방 요청 목록 조회 API", description = "회원의 채팅방 목록을 조회한다.") + @GetMapping("/api/chat/inquires") + public ResponseEntity> getChatProposalsByMember( + @AuthenticationPrincipal Member member, + Pageable pageable + ) { + PageResponse response + = chatInquiryService.getChatInquiresByMember(member, pageable); + return ResponseEntity.ok(response); + } + @Operation(summary = "채팅 수락 API", description = "채팅방에서 요청자와의 채팅을 수락한다.") @PatchMapping("/api/chat/inquires/{chatInquiryId}/accept") public ResponseEntity acceptChat( From 4e8278f0badb979aa772bd5dacad37b5fdb699ea Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:29:47 +0900 Subject: [PATCH 19/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EC=88=98=EB=9D=BD=20=EA=B1=B0=EC=A0=88=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20mapper=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/ChatInquiryMapper.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 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 d978f995..d11c60a4 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 @@ -3,8 +3,6 @@ import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; import com.dnd.gongmuin.chatroom.domain.ChatRoom; -import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; -import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; @@ -42,4 +40,21 @@ public static CreateChatInquiryResponse toCreateChatInquiryResponse( answerer.getProfileImageNo() ); } + + public static AcceptChatResponse toAcceptChatResponse( + ChatInquiry chatInquiry, + ChatRoom chatRoom + ) { + return new AcceptChatResponse( + chatRoom.getId(), + chatInquiry.getStatus().getLabel(), + chatInquiry.getAnswerer().getCredit() + ); + } + + public static RejectChatResponse toRejectChatResponse(ChatInquiry chatInquiry) { + return new RejectChatResponse( + chatInquiry.getStatus().getLabel() + ); + } } From 27039a81371c0d1f8b7794de09cdac2e6a54866d Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:31:33 +0900 Subject: [PATCH 20/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EA=B1=B0=EC=A0=88=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/ChatInquiryScheduler.java} | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename src/main/java/com/dnd/gongmuin/{chatroom/scheduler/ChatScheduler.java => chat_inquiry/scheduler/ChatInquiryScheduler.java} (58%) diff --git a/src/main/java/com/dnd/gongmuin/chatroom/scheduler/ChatScheduler.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/scheduler/ChatInquiryScheduler.java similarity index 58% rename from src/main/java/com/dnd/gongmuin/chatroom/scheduler/ChatScheduler.java rename to src/main/java/com/dnd/gongmuin/chat_inquiry/scheduler/ChatInquiryScheduler.java index d5ca459e..63e9b945 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/scheduler/ChatScheduler.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/scheduler/ChatInquiryScheduler.java @@ -1,23 +1,23 @@ -package com.dnd.gongmuin.chatroom.scheduler; +package com.dnd.gongmuin.chat_inquiry.scheduler; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import com.dnd.gongmuin.chat_inquiry.service.ChatInquiryService; import com.dnd.gongmuin.chatroom.service.ChatRoomService; import lombok.RequiredArgsConstructor; @Component @RequiredArgsConstructor -public class ChatScheduler { +public class ChatInquiryScheduler { - private final ChatRoomService chatRoomService; + private final ChatInquiryService chatInquiryService; @Transactional @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") - public void rejectChatRequest() { - chatRoomService.rejectChatAuto(); + public void rejectChatInquiry() { + chatInquiryService.rejectChatAuto(); } - } From 80315f8795dc033dcb45554756b99f4a0f434398 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:38:35 +0900 Subject: [PATCH 21/44] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ChatInquiryServiceTest.java | 249 ++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 src/test/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java 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 new file mode 100644 index 00000000..e8560591 --- /dev/null +++ b/src/test/java/com/dnd/gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java @@ -0,0 +1,249 @@ +package com.dnd.gongmuin.chat_inquiry.service; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.SliceImpl; +import org.springframework.test.util.ReflectionTestUtils; + +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.ChatInquiryResponse; +import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; +import com.dnd.gongmuin.chat_inquiry.dto.RejectChatResponse; +import com.dnd.gongmuin.chat_inquiry.repository.ChatInquiryRepository; +import com.dnd.gongmuin.chatroom.domain.ChatRoom; +import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; +import com.dnd.gongmuin.common.exception.runtime.ValidationException; +import com.dnd.gongmuin.common.fixture.ChatInquiryFixture; +import com.dnd.gongmuin.common.fixture.ChatRoomFixture; +import com.dnd.gongmuin.common.fixture.MemberFixture; +import com.dnd.gongmuin.common.fixture.QuestionPostFixture; +import com.dnd.gongmuin.credit_history.domain.CreditType; +import com.dnd.gongmuin.credit_history.service.CreditHistoryService; +import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.member.exception.MemberErrorCode; +import com.dnd.gongmuin.member.repository.MemberRepository; +import com.dnd.gongmuin.notification.dto.NotificationEvent; +import com.dnd.gongmuin.question_post.domain.QuestionPost; +import com.dnd.gongmuin.question_post.repository.QuestionPostRepository; + +@DisplayName("[채팅 요청 서비스 단위 테스트]") +@ExtendWith(MockitoExtension.class) +class ChatInquiryServiceTest{ + + private static final int CHAT_REWARD = 2000; + private static final String CHAT_MESSAGE = "와"; + private static final String REQUEST_MESSAGE_POSTFIX = "님이 채팅을 요청하셨습니다."; + private final PageRequest pageRequest = PageRequest.of(0, 5); + + @Mock + private ChatRoomRepository chatRoomRepository; + + @Mock + private ChatInquiryRepository chatInquiryRepository; + + @Mock + private MemberRepository memberRepository; + + @Mock + private QuestionPostRepository questionPostRepository; + + @Mock + private ApplicationEventPublisher eventPublisher; + + @Mock + private CreditHistoryService creditHistoryService; + + @InjectMocks + private ChatInquiryService chatInquiryService; + + @DisplayName("[요청자의 크레딧이 2000미만이면 채팅을 요청할 수 없다.]") + @Test + void createChatRoom_fail() { + //given + Member inquirer = MemberFixture.member(1L); + Member answerer = MemberFixture.member(2L); + ReflectionTestUtils.setField(inquirer, "credit", 1999); + QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); + CreateChatInquiryRequest request = new CreateChatInquiryRequest( + questionPost.getId(), + answerer.getId(), + CHAT_MESSAGE + ); + + given(questionPostRepository.findById(questionPost.getId())) + .willReturn(Optional.of(questionPost)); + given(memberRepository.findById(answerer.getId())) + .willReturn(Optional.of(answerer)); + + //when & then + assertThatThrownBy(() -> chatInquiryService.createChatInquiry(request, inquirer)) + .isInstanceOf(ValidationException.class) + .hasMessageContaining(MemberErrorCode.NOT_ENOUGH_CREDIT.getMessage()); + } + + @DisplayName("[회원이 속한 채팅 요청 목록을 조회할 수 있다.]") + @Test + void getChatProposalsByMember() { + //given + Long chatInquiryId = 1L; + Member targetMember = MemberFixture.member(1L); + Member partner = MemberFixture.member(2L); + ChatInquiryResponse chatInquiryResponse = new ChatInquiryResponse( + chatInquiryId, CHAT_MESSAGE, InquiryStatus.PENDING, true, partner.getId(), + partner.getNickname(), partner.getJobGroup(), partner.getProfileImageNo() + ); + given(chatInquiryRepository.getChatInquiresByMember(targetMember, pageRequest)) + .willReturn(new SliceImpl<>(List.of(chatInquiryResponse), pageRequest, false)); + + //when + List response = chatInquiryService.getChatInquiresByMember( + targetMember, pageRequest).content(); + + //then + assertAll( + () -> assertThat(response).hasSize(1), + () -> assertThat(response.get(0).chatInquiryId()) + .isEqualTo(chatInquiryId), + () -> assertThat(response.get(0).partnerId()) + .isEqualTo(partner.getId()), + () -> assertThat(response.get(0).message()) + .isEqualTo(CHAT_MESSAGE) + ); + } + + @DisplayName("[답변자가 채팅 요청을 수락할 수 있다.]") + @Test + void acceptChat() { + //given + Long chatInquiryId = 1L; + Member inquirer = MemberFixture.member(1L); + Member answerer = MemberFixture.member(2L); + int previousCredit = answerer.getCredit(); + QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, CHAT_MESSAGE); + ChatRoom chatRoom = ChatRoomFixture.chatRoom(1L, questionPost, inquirer, answerer); + given(chatInquiryRepository.findById(chatInquiryId)) + .willReturn(Optional.of(chatInquiry)); + given(chatRoomRepository.save(any(ChatRoom.class))) + .willReturn(chatRoom); + + //when + AcceptChatResponse response = chatInquiryService.acceptChat(chatInquiryId, answerer); + + //then + assertAll( + () -> assertThat(response.chatStatus()) + .isEqualTo(InquiryStatus.ACCEPTED.getLabel()), + () -> assertThat(response.credit()) + .isEqualTo(previousCredit + CHAT_REWARD) + ); + } + + @DisplayName("[답변자가 채팅 요청을 수락할 때 채팅 수락 알림이 발행된다.]") + @Test + void acceptChatWithEventPublish() { + //given + Long chatInquiryId = 1L; + Member inquirer = MemberFixture.member(1L); + Member answerer = MemberFixture.member(2L); + int previousCredit = answerer.getCredit(); + QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, CHAT_MESSAGE); + ChatRoom chatRoom = ChatRoomFixture.chatRoom(1L, questionPost, inquirer, answerer); + given(chatInquiryRepository.findById(chatInquiryId)) + .willReturn(Optional.of(chatInquiry)); + given(chatRoomRepository.save(any(ChatRoom.class))) + .willReturn(chatRoom); + + //when + AcceptChatResponse response = chatInquiryService.acceptChat(chatInquiryId, answerer); + + //then + assertAll( + () -> assertThat(response.chatStatus()) + .isEqualTo(InquiryStatus.ACCEPTED.getLabel()), + () -> assertThat(response.credit()) + .isEqualTo(previousCredit + CHAT_REWARD), + () -> verify(eventPublisher, times(1)).publishEvent(any(NotificationEvent.class)) + ); + } + + @DisplayName("[답변자가 채팅 요청을 거절할 수 있다.]") + @Test + void rejectChat() { + //given + Long chatInquiryId = 1L; + Member inquirer = MemberFixture.member(1L); + Member answerer = MemberFixture.member(2L); + QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, CHAT_MESSAGE); + + given(chatInquiryRepository.findById(chatInquiryId)) + .willReturn(Optional.of(chatInquiry)); + + //when + RejectChatResponse response = chatInquiryService.rejectChat(chatInquiryId, answerer); + + //then + assertThat(response.chatStatus()) + .isEqualTo(InquiryStatus.REJECTED.getLabel()); + } + + @DisplayName("[답변자가 채팅 요청을 거절할 때 채팅 거절 알림이 발행된다.]") + @Test + void rejectChatWithEventPublish() { + //given + Long chatInquiryId = 1L; + Member inquirer = MemberFixture.member(1L); + Member answerer = MemberFixture.member(2L); + QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, CHAT_MESSAGE); + + given(chatInquiryRepository.findById(chatInquiryId)) + .willReturn(Optional.of(chatInquiry)); + + //when + RejectChatResponse response = chatInquiryService.rejectChat(chatInquiryId, answerer); + + //then + assertAll( + () -> assertThat(response.chatStatus()).isEqualTo(InquiryStatus.REJECTED.getLabel()), + () -> verify(eventPublisher, times(1)).publishEvent(any(NotificationEvent.class)) + ); + } + + @DisplayName("일주일이 지난 요청에 경우 자동으로 거절하고, 요청자에게 크레딧을 반환한다.") + @Test + void rejectChatAuto() { + // given + List rejectedInquirerIds = List.of(1L, 2L); + given(chatInquiryRepository.getAutoRejectedInquirerIds()) + .willReturn(rejectedInquirerIds); + + // when + chatInquiryService.rejectChatAuto(); + + // then + verify(chatInquiryRepository).getAutoRejectedInquirerIds(); + verify(chatInquiryRepository).updateChatInquiryStatusRejected(); + verify(memberRepository).refundInMemberIds(rejectedInquirerIds, CHAT_REWARD); + verify(creditHistoryService).saveCreditHistoryInMemberIds( + rejectedInquirerIds, CreditType.CHAT_REFUND, CHAT_REWARD + ); + } +} \ No newline at end of file From 03f12bdd25898dc413f230e17b91564c6964e0cc Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:40:18 +0900 Subject: [PATCH 22/44] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20API=20=ED=86=B5=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChatInquiryControllerTest.java | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/test/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryControllerTest.java 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 new file mode 100644 index 00000000..541886ec --- /dev/null +++ b/src/test/java/com/dnd/gongmuin/chat_inquiry/controller/ChatInquiryControllerTest.java @@ -0,0 +1,125 @@ +package com.dnd.gongmuin.chat_inquiry.controller; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.util.List; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; + +import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; +import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; +import com.dnd.gongmuin.chat_inquiry.repository.ChatInquiryRepository; +import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; +import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; +import com.dnd.gongmuin.common.fixture.ChatInquiryFixture; +import com.dnd.gongmuin.common.fixture.MemberFixture; +import com.dnd.gongmuin.common.fixture.QuestionPostFixture; +import com.dnd.gongmuin.common.support.ApiTestSupport; +import com.dnd.gongmuin.credit_history.repository.CreditHistoryRepository; +import com.dnd.gongmuin.member.domain.Member; +import com.dnd.gongmuin.member.repository.MemberRepository; +import com.dnd.gongmuin.question_post.domain.QuestionPost; +import com.dnd.gongmuin.question_post.repository.QuestionPostRepository; + +@DisplayName("[채팅 요청 통합 테스트]") +class ChatInquiryControllerTest extends ApiTestSupport { + + private static final int CHAT_REWARD = 2000; + private static final String CHAT_MESSAGE = "와"; + + @Autowired + private ChatMessageRepository chatMessageRepository; + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private QuestionPostRepository questionPostRepository; + + @Autowired + private ChatRoomRepository chatRoomRepository; + + @Autowired + private ChatInquiryRepository chatInquiryRepository; + + @Autowired + private CreditHistoryRepository creditHistoryRepository; + + @AfterEach + void teardown() { + creditHistoryRepository.deleteAll(); + memberRepository.deleteAll(); + questionPostRepository.deleteAll(); + chatRoomRepository.deleteAll(); + chatMessageRepository.deleteAll(); + } + + @DisplayName("[회원의 채팅 요청 목록을 조회할 수 있다.]") + @Test + void getChatInquiresByMember() throws Exception { + //given + Member member1 = memberRepository.save(MemberFixture.member4()); + Member member2 = memberRepository.save(MemberFixture.member5()); + List questionPosts = questionPostRepository.saveAll( + List.of( + questionPostRepository.save(QuestionPostFixture.questionPost(member1)), + questionPostRepository.save(QuestionPostFixture.questionPost(member2)) + ) + ); + ChatInquiry chatInquiry1 = chatInquiryRepository.save( + ChatInquiryFixture.chatInquiry(questionPosts.get(0), member1, loginMember, CHAT_MESSAGE)); + ChatInquiry chatInquiry2 = chatInquiryRepository.save( + ChatInquiryFixture.chatInquiry(questionPosts.get(1), loginMember, member2, CHAT_MESSAGE)); + + // when & then + mockMvc.perform(get("/api/chat/inquires") + .cookie(accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.size").value(2)) + .andExpect(jsonPath("$.content[0].chatInquiryId").value(chatInquiry2.getId())) // 내림차순 + .andExpect(jsonPath("$.content[0].partnerId").value(member2.getId())) + .andExpect(jsonPath("$.content[0].isInquirer").value(true)) + .andExpect(jsonPath("$.content[0].chatStatus").value(InquiryStatus.PENDING.getLabel())) + + .andExpect(jsonPath("$.content[1].chatInquiryId").value(chatInquiry1.getId())) + .andExpect(jsonPath("$.content[1].partnerId").value(member1.getId())) + .andExpect(jsonPath("$.content[1].isInquirer").value(false)) + .andExpect(jsonPath("$.content[1].chatStatus").value(InquiryStatus.PENDING.getLabel())) + .andDo(MockMvcResultHandlers.print()); + } + + @DisplayName("[답변자가 채팅 요청을 수락할 수 있다.]") + @Test + void acceptChatRoom() throws Exception { + Member inquirer = memberRepository.save(MemberFixture.member4()); + QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(inquirer)); + ChatInquiry chatInquiry = chatInquiryRepository.save( + ChatInquiryFixture.chatInquiry(questionPost, inquirer, loginMember, CHAT_MESSAGE)); + int previousAnswererCredit = loginMember.getCredit(); + + mockMvc.perform(patch("/api/chat/inquires/{chatInquiryId}/accept", chatInquiry.getId()) + .cookie(accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.chatStatus").value(InquiryStatus.ACCEPTED.getLabel())) + .andExpect(jsonPath("$.credit").value(previousAnswererCredit + CHAT_REWARD)); + } + + @DisplayName("[답변자가 채팅 요청을 거절할 수 있다.]") + @Test + void rejectChatRoom() throws Exception { + Member inquirer = memberRepository.save(MemberFixture.member4()); + QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(inquirer)); + ChatInquiry chatInquiry = chatInquiryRepository.save( + ChatInquiryFixture.chatInquiry(questionPost, inquirer, loginMember, CHAT_MESSAGE)); + + mockMvc.perform(patch("/api/chat/inquires/{chatInquiryId}/reject", chatInquiry.getId()) + .cookie(accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.chatStatus").value(InquiryStatus.REJECTED.getLabel())); + } +} \ No newline at end of file From 56452917320098f25e43d8fd9c81f866dcd5ca45 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:42:59 +0900 Subject: [PATCH 23/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20->=20=EC=B1=84=ED=8C=85=EC=9A=94=EC=B2=AD=20repository?= =?UTF-8?q?=EB=A1=9C=20=EC=98=AE=EA=B8=B4=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ChatRoomQueryRepository.java | 8 -- .../ChatRoomQueryRepositoryImpl.java | 100 +++--------------- 2 files changed, 17 insertions(+), 91 deletions(-) diff --git a/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepository.java b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepository.java index d1b7cea5..aedb80ea 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepository.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepository.java @@ -1,20 +1,12 @@ package com.dnd.gongmuin.chatroom.repository; -import java.util.List; - import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; import com.dnd.gongmuin.member.domain.Member; public interface ChatRoomQueryRepository { Slice getChatRoomsByMember(Member member, Pageable pageable); - Slice getChatProposalsByMember(Member member, Pageable pageable); - - List getAutoRejectedInquirerIds(); - - void updateChatRoomStatusRejected(); } diff --git a/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepositoryImpl.java b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepositoryImpl.java index fc81ff99..39988f07 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepositoryImpl.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/repository/ChatRoomQueryRepositoryImpl.java @@ -1,21 +1,14 @@ package com.dnd.gongmuin.chatroom.repository; +import static com.dnd.gongmuin.chatroom.domain.QChatRoom.*; -import static com.dnd.gongmuin.chat.domain.QChatRoom.*; - -import java.time.LocalDateTime; import java.util.List; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; -import com.dnd.gongmuin.chatroom.domain.InquiryStatus; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; -import com.dnd.gongmuin.chat.dto.response.QChatProposalInfo; -import com.dnd.gongmuin.chat.dto.response.QChatRoomInfo; -import com.dnd.gongmuin.chatroom.domain.QChatRoom; import com.dnd.gongmuin.chatroom.dto.response.QChatRoomInfo; import com.dnd.gongmuin.member.domain.Member; import com.querydsl.core.types.dsl.CaseBuilder; @@ -34,93 +27,34 @@ public Slice getChatRoomsByMember( ) { List content = queryFactory .select(new QChatRoomInfo( - QChatRoom.chatRoom.id, + chatRoom.id, new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(QChatRoom.chatRoom.answerer.id) - .otherwise(QChatRoom.chatRoom.inquirer.id), + .when(chatRoom.inquirer.id.eq(member.getId())) + .then(chatRoom.answerer.id) + .otherwise(chatRoom.inquirer.id), new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(QChatRoom.chatRoom.answerer.nickname) - .otherwise(QChatRoom.chatRoom.inquirer.nickname), + .when(chatRoom.inquirer.id.eq(member.getId())) + .then(chatRoom.answerer.nickname) + .otherwise(chatRoom.inquirer.nickname), new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(QChatRoom.chatRoom.answerer.jobGroup) - .otherwise(QChatRoom.chatRoom.inquirer.jobGroup), + .when(chatRoom.inquirer.id.eq(member.getId())) + .then(chatRoom.answerer.jobGroup) + .otherwise(chatRoom.inquirer.jobGroup), new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(QChatRoom.chatRoom.answerer.profileImageNo) - .otherwise(QChatRoom.chatRoom.inquirer.profileImageNo) + .when(chatRoom.inquirer.id.eq(member.getId())) + .then(chatRoom.answerer.profileImageNo) + .otherwise(chatRoom.inquirer.profileImageNo) )) - .from(QChatRoom.chatRoom) - .where(QChatRoom.chatRoom.inquirer.id.eq(member.getId()) - .or(QChatRoom.chatRoom.answerer.id.eq(member.getId())) - .and(QChatRoom.chatRoom.status.eq(InquiryStatus.ACCEPTED))) + .from(chatRoom) + .where(chatRoom.inquirer.id.eq(member.getId()) + .or(chatRoom.answerer.id.eq(member.getId()))) .fetch(); boolean hasNext = hasNext(pageable.getPageSize(), content); return new SliceImpl<>(content, pageable, hasNext); } - public Slice getChatProposalsByMember(Member member, Pageable pageable){ - List content = queryFactory - .select(new QChatProposalInfo( - QChatRoom.chatRoom.id, - QChatRoom.chatRoom.status, - new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(true) - .otherwise(false), - new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(QChatRoom.chatRoom.answerer.id) - .otherwise(QChatRoom.chatRoom.inquirer.id), - - new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(QChatRoom.chatRoom.answerer.nickname) - .otherwise(QChatRoom.chatRoom.inquirer.nickname), - new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(QChatRoom.chatRoom.answerer.jobGroup) - .otherwise(QChatRoom.chatRoom.inquirer.jobGroup), - new CaseBuilder() - .when(QChatRoom.chatRoom.inquirer.id.eq(member.getId())) - .then(QChatRoom.chatRoom.answerer.profileImageNo) - .otherwise(QChatRoom.chatRoom.inquirer.profileImageNo) - )) - .from(QChatRoom.chatRoom) - .where(QChatRoom.chatRoom.inquirer.id.eq(member.getId()) - .or(QChatRoom.chatRoom.answerer.id.eq(member.getId())) - .and(QChatRoom.chatRoom.status.in(List.of(InquiryStatus.REJECTED, InquiryStatus.PENDING)))) - .fetch(); - - boolean hasNext = hasNext(pageable.getPageSize(), content); - return new SliceImpl<>(content, pageable, hasNext); - } - - public List getAutoRejectedInquirerIds() { - return queryFactory - .select(QChatRoom.chatRoom.inquirer.id) - .from(QChatRoom.chatRoom) - .where( - QChatRoom.chatRoom.createdAt.loe(LocalDateTime.now().minusWeeks(1)), - QChatRoom.chatRoom.status.eq(InquiryStatus.PENDING) - ) - .fetch(); - } - - public void updateChatRoomStatusRejected() { - queryFactory.update(QChatRoom.chatRoom) - .set(QChatRoom.chatRoom.status, InquiryStatus.REJECTED) - .where( - QChatRoom.chatRoom.createdAt.loe(LocalDateTime.now().minusWeeks(1)), - QChatRoom.chatRoom.status.eq(InquiryStatus.PENDING) - ) - .execute(); - } - private boolean hasNext(int pageSize, List items) { if (items.size() <= pageSize) { return false; From 2ad84728c6a4d2a322344f6a946edf5b65ece9d6 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:44:59 +0900 Subject: [PATCH 24/44] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20->=20=EC=B1=84=ED=8C=85=EC=9A=94=EC=B2=AD=20repository?= =?UTF-8?q?=EB=A1=9C=20=EC=98=AE=EA=B8=B4=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ChatRoomRepositoryTest.java | 68 +------------------ 1 file changed, 3 insertions(+), 65 deletions(-) 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 b78f1791..a703b3e3 100644 --- a/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/repository/ChatRoomRepositoryTest.java @@ -1,9 +1,7 @@ package com.dnd.gongmuin.chat.repository; import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; -import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.Assertions; @@ -11,11 +9,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; -import org.springframework.test.util.ReflectionTestUtils; import com.dnd.gongmuin.chatroom.domain.ChatRoom; -import com.dnd.gongmuin.chatroom.domain.InquiryStatus; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; import com.dnd.gongmuin.common.fixture.ChatRoomFixture; @@ -55,9 +50,9 @@ void getChatRoomsByMember() { Member answerer = memberRepository.save(MemberFixture.member()); QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(questioner)); List chatRooms = chatRoomRepository.saveAll(List.of( - chatRoomRepository.save(ChatRoomFixture.acceptedChatRoom(questionPost, questioner, answerer)), - chatRoomRepository.save(ChatRoomFixture.acceptedChatRoom(questionPost, questioner, target)), - chatRoomRepository.save(ChatRoomFixture.acceptedChatRoom(questionPost, target, answerer)) + chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, questioner, answerer)), + chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, questioner, target)), + chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, target, answerer)) )); //when @@ -73,61 +68,4 @@ void getChatRoomsByMember() { () -> assertThat(chatRoomInfos.get(1).partnerId()).isEqualTo(answerer.getId()) ); } - - @DisplayName("회원의 채팅 요청 목록을 조회할 수 있다.") - @Test - void getChatProposalsByMember() { - //given - Member questioner = memberRepository.save(MemberFixture.member()); - Member target = memberRepository.save(MemberFixture.member()); - Member answerer = memberRepository.save(MemberFixture.member()); - QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(questioner)); - List chatRooms = chatRoomRepository.saveAll(List.of( - chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, questioner, answerer)), - chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, questioner, target)), - chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, target, answerer)) - )); - - //when - List chatProposalInfos = chatRoomRepository.getChatProposalsByMember(target, pageRequest) - .getContent(); - - //then - Assertions.assertAll( - () -> assertThat(chatProposalInfos).hasSize(2), - () -> assertThat(chatProposalInfos.get(0).chatRoomId()).isEqualTo(chatRooms.get(1).getId()), - () -> assertThat(chatProposalInfos.get(0).partnerId()).isEqualTo(questioner.getId()), - () -> assertThat(chatProposalInfos.get(1).chatRoomId()).isEqualTo(chatRooms.get(2).getId()), - () -> assertThat(chatProposalInfos.get(1).partnerId()).isEqualTo(answerer.getId()) - ); - } - - @DisplayName("요청중인 채팅방이 일주일이 지나면, 채팅방 상태를 거절함으로 바꾼다.") - @Test - void updateChatRoomStatusRejected() { - //given - Member questioner = memberRepository.save(MemberFixture.member()); - Member answerer = memberRepository.save(MemberFixture.member()); - QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(questioner)); - - List chatRooms = chatRoomRepository.saveAll(List.of( - chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, questioner, answerer)), - chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, questioner, answerer)) - )); - ReflectionTestUtils.setField(chatRooms.get(0), "createdAt", LocalDateTime.now().minusWeeks(1)); - - //when - chatRoomRepository.updateChatRoomStatusRejected(); - - em.flush(); - em.clear(); - - //then - ChatRoom chatRoom1 = chatRoomRepository.findById(chatRooms.get(0).getId()).orElseThrow(); - ChatRoom chatRoom2 = chatRoomRepository.findById(chatRooms.get(1).getId()).orElseThrow(); - assertAll( - () -> assertThat(chatRoom1.getStatus()).isEqualTo(InquiryStatus.REJECTED), - () -> assertThat(chatRoom2.getStatus()).isEqualTo(InquiryStatus.PENDING) - ); - } } \ No newline at end of file From 8785649705c15a85311ba7062ed76a049a7a77fa Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:45:54 +0900 Subject: [PATCH 25/44] =?UTF-8?q?[test]=20:=20chatRoomFixture=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EB=B0=8F=20=ED=95=84=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnd/gongmuin/chatroom/domain/ChatRoom.java | 3 --- .../gongmuin/common/fixture/ChatRoomFixture.java | 15 --------------- 2 files changed, 18 deletions(-) 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 52f49517..97a6be8c 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/domain/ChatRoom.java @@ -24,8 +24,6 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class ChatRoom extends TimeBaseEntity { - private static final int CHAT_REWARD = 2000; - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "chat_room_id", nullable = false) @@ -51,7 +49,6 @@ private ChatRoom(QuestionPost questionPost, Member inquirer, Member answerer) { this.questionPost = questionPost; this.inquirer = inquirer; this.answerer = answerer; - inquirer.decreaseCredit(CHAT_REWARD); } public static ChatRoom of( diff --git a/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java b/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java index 7b1e9b41..0a73c27f 100644 --- a/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java +++ b/src/test/java/com/dnd/gongmuin/common/fixture/ChatRoomFixture.java @@ -3,7 +3,6 @@ import org.springframework.test.util.ReflectionTestUtils; import com.dnd.gongmuin.chatroom.domain.ChatRoom; -import com.dnd.gongmuin.chatroom.domain.InquiryStatus; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; @@ -25,20 +24,6 @@ public static ChatRoom chatRoom( ); } - public static ChatRoom acceptedChatRoom( - QuestionPost questionPost, - Member inquirer, - Member answerer - ) { - ChatRoom chatRoom = ChatRoom.of( - questionPost, - inquirer, - answerer - ); - ReflectionTestUtils.setField(chatRoom, "status", InquiryStatus.ACCEPTED); - return chatRoom; - } - public static ChatRoom chatRoom( Long id, QuestionPost questionPost, From 11b2a38d9cc4d526838fc382ce388c768395d6e8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:48:50 +0900 Subject: [PATCH 26/44] =?UTF-8?q?[feat]=20:=20chatroom=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=B9=84=EC=A6=88=EB=8B=88?= =?UTF-8?q?=EC=8A=A4=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gongmuin/chatroom/dto/ChatRoomMapper.java | 60 -------- .../dto/response/ChatRoomDetailResponse.java | 1 - .../chatroom/service/ChatRoomService.java | 135 ------------------ 3 files changed, 196 deletions(-) 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 3b24baf0..ffb21152 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java @@ -1,15 +1,10 @@ package com.dnd.gongmuin.chatroom.dto; import com.dnd.gongmuin.chatroom.domain.ChatRoom; -import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomDetailResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; -import com.dnd.gongmuin.chatroom.dto.response.CreateChatRoomResponse; import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; -import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; import com.dnd.gongmuin.question_post.dto.response.MemberInfo; @@ -32,26 +27,6 @@ public static ChatRoom toChatRoom( ); } - public static CreateChatRoomResponse toCreateChatRoomResponse( - ChatRoom chatRoom - ) { - QuestionPost questionPost = chatRoom.getQuestionPost(); - Member answerer = chatRoom.getAnswerer(); - return new CreateChatRoomResponse( - questionPost.getId(), - questionPost.getJobGroup().getLabel(), - questionPost.getTitle(), - new MemberInfo( - answerer.getId(), - answerer.getNickname(), - answerer.getJobGroup().getLabel(), - answerer.getProfileImageNo() - ), - chatRoom.getStatus().getLabel(), - chatRoom.getInquirer().getCredit() - ); - } - public static ChatRoomDetailResponse toChatRoomDetailResponse( ChatRoom chatRoom, Member chatPartner @@ -68,24 +43,10 @@ public static ChatRoomDetailResponse toChatRoomDetailResponse( chatPartner.getJobGroup().getLabel(), chatPartner.getProfileImageNo() ), - chatRoom.getStatus().getLabel(), isInquirer ); } - public static AcceptChatResponse toAcceptChatResponse(ChatRoom chatRoom) { - return new AcceptChatResponse( - chatRoom.getStatus().getLabel(), - chatRoom.getAnswerer().getCredit() - ); - } - - public static RejectChatResponse toRejectChatResponse(ChatRoom chatRoom) { - return new RejectChatResponse( - chatRoom.getStatus().getLabel() - ); - } - public static ChatRoomSimpleResponse toChatRoomSimpleResponse( ChatRoomInfo chatRoomInfo, LatestChatMessage latestChatMessage @@ -103,25 +64,4 @@ public static ChatRoomSimpleResponse toChatRoomSimpleResponse( latestChatMessage.createdAt().toString() ); } - - public static ChatProposalResponse toChatProposalResponse( - ChatProposalInfo chatProposalInfo, - LatestChatMessage latestChatMessage - ) { - return new ChatProposalResponse( - chatProposalInfo.chatRoomId(), - chatProposalInfo.chatStatus(), - chatProposalInfo.isInquirer(), - new MemberInfo( - chatProposalInfo.partnerId(), - chatProposalInfo.partnerNickname(), - chatProposalInfo.partnerJobGroup(), - chatProposalInfo.partnerProfileImageNo() - ), - latestChatMessage.content(), - latestChatMessage.type(), - latestChatMessage.createdAt().toString() - ); - } - } 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 ebbea641..52502c5d 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 @@ -7,7 +7,6 @@ public record ChatRoomDetailResponse( String targetJobGroup, String title, MemberInfo receiverInfo, - String chatStatus, boolean isInquirer ) { } 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 0657708a..e91c7925 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/service/ChatRoomService.java @@ -3,10 +3,8 @@ import java.util.Comparator; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; @@ -15,17 +13,11 @@ import com.dnd.gongmuin.chatroom.domain.ChatRoom; import com.dnd.gongmuin.chatroom.dto.ChatMessageMapper; import com.dnd.gongmuin.chatroom.dto.ChatRoomMapper; -import com.dnd.gongmuin.chatroom.dto.request.CreateChatRoomRequest; -import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomDetailResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; -import com.dnd.gongmuin.chatroom.dto.response.CreateChatRoomResponse; import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; -import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; import com.dnd.gongmuin.chatroom.repository.ChatMessageQueryRepository; import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; @@ -34,16 +26,7 @@ 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.credit_history.domain.CreditType; -import com.dnd.gongmuin.credit_history.service.CreditHistoryService; import com.dnd.gongmuin.member.domain.Member; -import com.dnd.gongmuin.member.exception.MemberErrorCode; -import com.dnd.gongmuin.member.repository.MemberRepository; -import com.dnd.gongmuin.notification.domain.NotificationType; -import com.dnd.gongmuin.notification.dto.NotificationEvent; -import com.dnd.gongmuin.question_post.domain.QuestionPost; -import com.dnd.gongmuin.question_post.exception.QuestionPostErrorCode; -import com.dnd.gongmuin.question_post.repository.QuestionPostRepository; import lombok.RequiredArgsConstructor; @@ -51,20 +34,9 @@ @RequiredArgsConstructor public class ChatRoomService { - private static final int CHAT_REWARD = 2000; private final ChatMessageRepository chatMessageRepository; private final ChatMessageQueryRepository chatMessageQueryRepository; private final ChatRoomRepository chatRoomRepository; - private final MemberRepository memberRepository; - private final QuestionPostRepository questionPostRepository; - private final CreditHistoryService creditHistoryService; - private final ApplicationEventPublisher eventPublisher; - - private static void validateIfAnswerer(Member member, ChatRoom chatRoom) { - if (!Objects.equals(member.getId(), chatRoom.getAnswerer().getId())) { - throw new ValidationException(ChatErrorCode.UNAUTHORIZED_REQUEST); - } - } @Transactional(readOnly = true) public PageResponse getChatMessages(Long chatRoomId, Pageable pageable) { @@ -74,26 +46,6 @@ public PageResponse getChatMessages(Long chatRoomId, Pageab return PageMapper.toPageResponse(responsePage); } - @Transactional - public CreateChatRoomResponse createChatRoom(CreateChatRoomRequest request, Member inquirer) { - QuestionPost questionPost = getQuestionPostById(request.questionPostId()); - Member answerer = getMemberById(request.answererId()); - - ChatRoom chatRoom = chatRoomRepository.save( - ChatRoomMapper.toChatRoom(questionPost, inquirer, answerer) - ); - chatMessageRepository.save( - ChatMessageMapper.toFirstChatMessage(chatRoom) - ); - creditHistoryService.saveChatCreditHistory(CreditType.CHAT_REQUEST, inquirer); - - eventPublisher.publishEvent( - new NotificationEvent(NotificationType.CHAT_REQUEST, chatRoom.getId(), inquirer.getId(), answerer) - ); - - return ChatRoomMapper.toCreateChatRoomResponse(chatRoom); - } - @Transactional(readOnly = true) public PageResponse getChatRoomsByMember(Member member, Pageable pageable) { // 회원 채팅방 정보 가져오기 @@ -118,26 +70,6 @@ public PageResponse getChatRoomsByMember(Member member, return new PageResponse<>(responses, responses.size(), chatRoomInfos.hasNext()); } - @Transactional(readOnly = true) - public PageResponse getChatProposalsByMember(Member member, Pageable pageable) { - Slice chatProposalInfos = chatRoomRepository.getChatProposalsByMember( - member, pageable - ); - - List chatRoomIds = chatProposalInfos.stream() - .map(ChatProposalInfo::chatRoomId) - .toList(); - - List latestChatMessages - = chatMessageQueryRepository.findLatestChatByChatRoomIds(chatRoomIds); - - List responses = getChatProposalResponse(latestChatMessages, - chatProposalInfos); - - return new PageResponse<>(responses, responses.size(), chatProposalInfos.hasNext()); - } - - @Transactional(readOnly = true) public ChatRoomDetailResponse getChatRoomById(Long chatRoomId, Member member) { ChatRoom chatRoom = getChatRoomById(chatRoomId); @@ -145,42 +77,6 @@ public ChatRoomDetailResponse getChatRoomById(Long chatRoomId, Member member) { return ChatRoomMapper.toChatRoomDetailResponse(chatRoom, chatPartner); } - @Transactional - public AcceptChatResponse acceptChat(Long chatRoomId, Member answerer) { - ChatRoom chatRoom = getChatRoomById(chatRoomId); - validateIfAnswerer(answerer, chatRoom); - chatRoom.updateStatusAccepted(); - creditHistoryService.saveChatCreditHistory(CreditType.CHAT_ACCEPT, answerer); - eventPublisher.publishEvent( - new NotificationEvent(NotificationType.CHAT_ACCEPT, chatRoom.getId(), answerer.getId(), - chatRoom.getInquirer()) - ); - - return ChatRoomMapper.toAcceptChatResponse(chatRoom); - } - - @Transactional - public RejectChatResponse rejectChat(Long chatRoomId, Member answerer) { - ChatRoom chatRoom = getChatRoomById(chatRoomId); - validateIfAnswerer(answerer, chatRoom); - chatRoom.updateStatusRejected(); - creditHistoryService.saveChatCreditHistory(CreditType.CHAT_REFUND, chatRoom.getInquirer()); - eventPublisher.publishEvent( - new NotificationEvent(NotificationType.CHAT_REJECT, chatRoom.getId(), answerer.getId(), - chatRoom.getInquirer()) - ); - - return ChatRoomMapper.toRejectChatResponse(chatRoom); - } - - @Transactional - public void rejectChatAuto() { - List rejectedInquirerIds = chatRoomRepository.getAutoRejectedInquirerIds(); - chatRoomRepository.updateChatRoomStatusRejected(); - memberRepository.refundInMemberIds(rejectedInquirerIds, CHAT_REWARD); - creditHistoryService.saveCreditHistoryInMemberIds(rejectedInquirerIds, CreditType.CHAT_REFUND, CHAT_REWARD); - } - private List getChatRoomSimpleResponses(List latestChatMessages, Slice chatRoomInfos) { // -> 순서 보장 x @@ -201,41 +97,11 @@ private List getChatRoomSimpleResponses(List getChatProposalResponse(List latestChatMessages, - Slice chatProposalInfos) { - // -> 순서 보장 x - Map messageMap = latestChatMessages.stream() - .collect(Collectors.toMap(LatestChatMessage::chatRoomId, message -> message)); - - // 최신순 정렬 및 변환 - return chatProposalInfos.stream() - .sorted( - Comparator.comparing( - (ChatProposalInfo info) -> messageMap.get(info.chatRoomId()).createdAt() - ).reversed()) - .map(chatProposalInfo -> { - LatestChatMessage latestMessage = messageMap.get(chatProposalInfo.chatRoomId()); - return ChatRoomMapper.toChatProposalResponse( - chatProposalInfo, latestMessage - ); - }).toList(); - } - private ChatRoom getChatRoomById(Long id) { return chatRoomRepository.findById(id) .orElseThrow(() -> new NotFoundException(ChatErrorCode.NOT_FOUND_CHAT_ROOM)); } - private QuestionPost getQuestionPostById(Long id) { - return questionPostRepository.findById(id) - .orElseThrow(() -> new NotFoundException(QuestionPostErrorCode.NOT_FOUND_QUESTION_POST)); - } - - private Member getMemberById(Long id) { - return memberRepository.findById(id) - .orElseThrow(() -> new NotFoundException(MemberErrorCode.NOT_FOUND_MEMBER)); - } - private Member getChatPartner(Member member, ChatRoom chatRoom) { if (member.isEqualMember(chatRoom.getAnswerer().getId())) { return chatRoom.getInquirer(); @@ -245,4 +111,3 @@ private Member getChatPartner(Member member, ChatRoom chatRoom) { throw new ValidationException(ChatErrorCode.UNAUTHORIZED_CHAT_ROOM); } } - From 183148e26ec548287097c0b87de9ef22d592807c Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:50:02 +0900 Subject: [PATCH 27/44] =?UTF-8?q?[feat]=20:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20dto=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/ChatProposalInfo.java | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalInfo.java diff --git a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalInfo.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalInfo.java deleted file mode 100644 index 277f59a3..00000000 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalInfo.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.dnd.gongmuin.chatroom.dto.response; - -import com.dnd.gongmuin.chatroom.domain.InquiryStatus; -import com.dnd.gongmuin.member.domain.JobGroup; -import com.querydsl.core.annotations.QueryProjection; - -public record ChatProposalInfo( - Long chatRoomId, - String chatStatus, - boolean isInquirer, - Long partnerId, - String partnerNickname, - String partnerJobGroup, - int partnerProfileImageNo -) { - @QueryProjection - public ChatProposalInfo( - Long chatRoomId, - InquiryStatus inquiryStatus, - boolean isInquirer, - Long partnerId, - String partnerNickname, - JobGroup partnerJobGroup, - int partnerProfileImageNo - ) { - this( - chatRoomId, - inquiryStatus.getLabel(), - isInquirer, - partnerId, - partnerNickname, - partnerJobGroup.getLabel(), - partnerProfileImageNo - ); - } -} From 6e9e430125c529447fa4c15e95676b6af3b3faa5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:52:03 +0900 Subject: [PATCH 28/44] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/service/ChatRoomServiceTest.java | 276 ------------------ 1 file changed, 276 deletions(-) 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 c171926b..7b84e5d6 100644 --- a/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/service/ChatRoomServiceTest.java @@ -14,26 +14,16 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.SliceImpl; -import org.springframework.test.util.ReflectionTestUtils; import com.dnd.gongmuin.chatroom.domain.ChatMessage; import com.dnd.gongmuin.chatroom.domain.ChatRoom; -import com.dnd.gongmuin.chatroom.domain.InquiryStatus; -import com.dnd.gongmuin.chatroom.domain.MessageType; -import com.dnd.gongmuin.chatroom.dto.request.CreateChatRoomRequest; -import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalInfo; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomDetailResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomInfo; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; -import com.dnd.gongmuin.chatroom.dto.response.CreateChatRoomResponse; import com.dnd.gongmuin.chatroom.dto.response.LatestChatMessage; -import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; import com.dnd.gongmuin.chatroom.repository.ChatMessageQueryRepository; import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; @@ -44,21 +34,13 @@ import com.dnd.gongmuin.common.fixture.ChatRoomFixture; import com.dnd.gongmuin.common.fixture.MemberFixture; import com.dnd.gongmuin.common.fixture.QuestionPostFixture; -import com.dnd.gongmuin.credit_history.domain.CreditType; -import com.dnd.gongmuin.credit_history.service.CreditHistoryService; import com.dnd.gongmuin.member.domain.Member; -import com.dnd.gongmuin.member.exception.MemberErrorCode; -import com.dnd.gongmuin.member.repository.MemberRepository; -import com.dnd.gongmuin.notification.dto.NotificationEvent; import com.dnd.gongmuin.question_post.domain.QuestionPost; -import com.dnd.gongmuin.question_post.repository.QuestionPostRepository; @DisplayName("[채팅방 서비스 단위 테스트]") @ExtendWith(MockitoExtension.class) class ChatRoomServiceTest { - private static final int CHAT_REWARD = 2000; - private static final String REQUEST_MESSAGE_POSTFIX = "님이 채팅을 요청하셨습니다."; private final PageRequest pageRequest = PageRequest.of(0, 5); @Mock private ChatMessageRepository chatMessageRepository; @@ -69,18 +51,6 @@ class ChatRoomServiceTest { @Mock private ChatRoomRepository chatRoomRepository; - @Mock - private MemberRepository memberRepository; - - @Mock - private QuestionPostRepository questionPostRepository; - - @Mock - private ApplicationEventPublisher eventPublisher; - - @Mock - private CreditHistoryService creditHistoryService; - @InjectMocks private ChatRoomService chatRoomService; @@ -101,99 +71,6 @@ void getChatMessages() { ); } - @DisplayName("[요청자가 채팅방을 생성할 수 있다.]") - @Test - void createChatRoom() { - //given - Member inquirer = MemberFixture.member(1L); - Member answerer = MemberFixture.member(2L); - QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - CreateChatRoomRequest request = new CreateChatRoomRequest( - questionPost.getId(), - answerer.getId() - ); - ChatRoom chatRoom = ChatRoomFixture.chatRoom(1L, questionPost, inquirer, answerer); - - given(questionPostRepository.findById(questionPost.getId())) - .willReturn(Optional.of(questionPost)); - given(memberRepository.findById(answerer.getId())) - .willReturn(Optional.of(answerer)); - given(chatRoomRepository.save(any(ChatRoom.class))) - .willReturn(chatRoom); - given(chatMessageRepository.save(any(ChatMessage.class))) - .willReturn( - ChatMessage.of(inquirer + REQUEST_MESSAGE_POSTFIX, chatRoom.getId(), inquirer.getId(), MessageType.TEXT) - ); - - //when - CreateChatRoomResponse response = chatRoomService.createChatRoom(request, inquirer); - - //then - assertAll( - () -> assertThat(response.questionPostId()).isEqualTo(request.questionPostId()), - () -> assertThat(response.receiverInfo().memberId()).isEqualTo(request.answererId()) - ); - } - - @DisplayName("[요청자가 채팅방을 생성 시 생성 알림이 발행된다.]") - @Test - void createChatRoomWithEventPublish() { - //given - Member inquirer = MemberFixture.member(1L); - Member answerer = MemberFixture.member(2L); - QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - CreateChatRoomRequest request = new CreateChatRoomRequest( - questionPost.getId(), - answerer.getId() - ); - ChatRoom chatRoom = ChatRoomFixture.chatRoom(1L, questionPost, inquirer, answerer); - - given(questionPostRepository.findById(questionPost.getId())) - .willReturn(Optional.of(questionPost)); - given(memberRepository.findById(answerer.getId())) - .willReturn(Optional.of(answerer)); - given(chatRoomRepository.save(any(ChatRoom.class))) - .willReturn(chatRoom); - given(chatMessageRepository.save(any(ChatMessage.class))) - .willReturn( - ChatMessage.of(inquirer + REQUEST_MESSAGE_POSTFIX, chatRoom.getId(), inquirer.getId(), MessageType.TEXT) - ); - - //when - CreateChatRoomResponse response = chatRoomService.createChatRoom(request, inquirer); - - //then - assertAll( - () -> assertThat(response.questionPostId()).isEqualTo(request.questionPostId()), - () -> assertThat(response.receiverInfo().memberId()).isEqualTo(request.answererId()), - () -> verify(eventPublisher, times(1)).publishEvent(any(NotificationEvent.class)) - ); - } - - @DisplayName("[요청자의 크레딧이 2000미만이면 채팅방을 생성할 수 없다.]") - @Test - void createChatRoom_fail() { - //given - Member inquirer = MemberFixture.member(1L); - Member answerer = MemberFixture.member(2L); - ReflectionTestUtils.setField(inquirer, "credit", 1999); - QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - CreateChatRoomRequest request = new CreateChatRoomRequest( - questionPost.getId(), - answerer.getId() - ); - - given(questionPostRepository.findById(questionPost.getId())) - .willReturn(Optional.of(questionPost)); - given(memberRepository.findById(answerer.getId())) - .willReturn(Optional.of(answerer)); - - //when & then - assertThatThrownBy(() -> chatRoomService.createChatRoom(request, inquirer)) - .isInstanceOf(ValidationException.class) - .hasMessageContaining(MemberErrorCode.NOT_ENOUGH_CREDIT.getMessage()); - } - @DisplayName("[회원이 속한 채팅방 목록을 조회할 수 있다.]") @Test void getChatRoomsByMember() { @@ -230,42 +107,6 @@ void getChatRoomsByMember() { ); } - @DisplayName("[회원이 속한 채팅 요청 목록을 조회할 수 있다.]") - @Test - void getChatProposalsByMember() { - //given - Long chatRoomId = 1L; - Member targetMember = MemberFixture.member(1L); - Member partner = MemberFixture.member(2L); - ChatProposalInfo chatProposalInfo = new ChatProposalInfo( - chatRoomId, InquiryStatus.PENDING, true, partner.getId(), - partner.getNickname(), partner.getJobGroup(), partner.getProfileImageNo() - ); - LatestChatMessage latestChatMessage = new LatestChatMessage( - chatRoomId, "와", "텍스트", LocalDateTime.now() - ); - - given(chatRoomRepository.getChatProposalsByMember(targetMember, pageRequest)) - .willReturn(new SliceImpl<>(List.of(chatProposalInfo), pageRequest, false)); - given(chatMessageQueryRepository.findLatestChatByChatRoomIds(List.of(chatRoomId))) - .willReturn(List.of(latestChatMessage)); - - //when - List response = chatRoomService.getChatProposalsByMember( - targetMember, pageRequest).content(); - - //then - assertAll( - () -> assertThat(response).hasSize(1), - () -> assertThat(response.get(0).chatRoomId()) - .isEqualTo(chatRoomId), - () -> assertThat(response.get(0).chatPartner().memberId()) - .isEqualTo(partner.getId()), - () -> assertThat(response.get(0).latestMessage()) - .isEqualTo(latestChatMessage.content()) - ); - } - @DisplayName("[요청자가 채팅방 아이디로 채팅방을 조회할 수 있다.]") @Test void getChatRoomById_Inquirer() { @@ -337,121 +178,4 @@ void getChatRoomById_Unauthorized() { .isInstanceOf(ValidationException.class) .hasMessageContaining(ChatErrorCode.UNAUTHORIZED_CHAT_ROOM.getMessage()); } - - @DisplayName("[답변자가 채팅 요청을 수락할 수 있다.]") - @Test - void acceptChat() { - //given - Long chatRoomId = 1L; - Member inquirer = MemberFixture.member(1L); - Member answerer = MemberFixture.member(2L); - int previousCredit = answerer.getCredit(); - QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatRoom chatRoom = ChatRoomFixture.chatRoom(questionPost, inquirer, answerer); - - given(chatRoomRepository.findById(chatRoomId)) - .willReturn(Optional.of(chatRoom)); - - //when - AcceptChatResponse response = chatRoomService.acceptChat(chatRoomId, answerer); - - //then - assertAll( - () -> assertThat(response.chatStatus()) - .isEqualTo(InquiryStatus.ACCEPTED.getLabel()), - () -> assertThat(response.credit()) - .isEqualTo(previousCredit + CHAT_REWARD) - ); - } - - @DisplayName("[답변자가 채팅 요청을 수락할 때 채팅 수락 알림이 발행된다.]") - @Test - void acceptChatWithEventPublish() { - //given - Long chatRoomId = 1L; - Member inquirer = MemberFixture.member(1L); - Member answerer = MemberFixture.member(2L); - int previousCredit = answerer.getCredit(); - QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatRoom chatRoom = ChatRoomFixture.chatRoom(questionPost, inquirer, answerer); - - given(chatRoomRepository.findById(chatRoomId)) - .willReturn(Optional.of(chatRoom)); - - //when - AcceptChatResponse response = chatRoomService.acceptChat(chatRoomId, answerer); - - //then - assertAll( - () -> assertThat(response.chatStatus()) - .isEqualTo(InquiryStatus.ACCEPTED.getLabel()), - () -> assertThat(response.credit()) - .isEqualTo(previousCredit + CHAT_REWARD), - () -> verify(eventPublisher, times(1)).publishEvent(any(NotificationEvent.class)) - ); - } - - @DisplayName("[답변자가 채팅 요청을 거절할 수 있다.]") - @Test - void rejectChat() { - //given - Long chatRoomId = 1L; - Member inquirer = MemberFixture.member(1L); - Member answerer = MemberFixture.member(2L); - QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatRoom chatRoom = ChatRoomFixture.chatRoom(questionPost, inquirer, answerer); - - given(chatRoomRepository.findById(chatRoomId)) - .willReturn(Optional.of(chatRoom)); - - //when - RejectChatResponse response = chatRoomService.rejectChat(chatRoomId, answerer); - - //then - assertThat(response.chatStatus()) - .isEqualTo(InquiryStatus.REJECTED.getLabel()); - } - - @DisplayName("[답변자가 채팅 요청을 거절할 때 채팅 거절 알림이 발행된다.]") - @Test - void rejectChatWithEventPublish() { - //given - Long chatRoomId = 1L; - Member inquirer = MemberFixture.member(1L); - Member answerer = MemberFixture.member(2L); - QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatRoom chatRoom = ChatRoomFixture.chatRoom(questionPost, inquirer, answerer); - - given(chatRoomRepository.findById(chatRoomId)) - .willReturn(Optional.of(chatRoom)); - - //when - RejectChatResponse response = chatRoomService.rejectChat(chatRoomId, answerer); - - //then - assertAll( - () -> assertThat(response.chatStatus()).isEqualTo(InquiryStatus.REJECTED.getLabel()), - () -> verify(eventPublisher, times(1)).publishEvent(any(NotificationEvent.class)) - ); - } - - @DisplayName("일주일이 지난 요청에 경우 자동으로 거절하고, 요청자에게 크레딧을 반환한다.") - @Test - void rejectChatAuto() { - // given - List rejectedInquirerIds = List.of(1L, 2L); - given(chatRoomRepository.getAutoRejectedInquirerIds()) - .willReturn(rejectedInquirerIds); - - // when - chatRoomService.rejectChatAuto(); - - // then - verify(chatRoomRepository).getAutoRejectedInquirerIds(); - verify(chatRoomRepository).updateChatRoomStatusRejected(); - verify(memberRepository).refundInMemberIds(rejectedInquirerIds, CHAT_REWARD); - verify(creditHistoryService).saveCreditHistoryInMemberIds( - rejectedInquirerIds, CreditType.CHAT_REFUND, CHAT_REWARD - ); - } } \ No newline at end of file From 7bee1b0a8e470436074f43e30e048053913ef0b1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:53:56 +0900 Subject: [PATCH 29/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20API=EC=97=90=20=EC=9E=88=EB=8D=98=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20API=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChatRoomController.java | 51 +------------------ 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/src/main/java/com/dnd/gongmuin/chatroom/controller/ChatRoomController.java b/src/main/java/com/dnd/gongmuin/chatroom/controller/ChatRoomController.java index 585c2af4..79ab0a10 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/controller/ChatRoomController.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/controller/ChatRoomController.java @@ -4,27 +4,18 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; 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.RestController; -import com.dnd.gongmuin.chatroom.dto.request.CreateChatRoomRequest; -import com.dnd.gongmuin.chatroom.dto.response.AcceptChatResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatMessageResponse; -import com.dnd.gongmuin.chatroom.dto.response.ChatProposalResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomDetailResponse; import com.dnd.gongmuin.chatroom.dto.response.ChatRoomSimpleResponse; -import com.dnd.gongmuin.chatroom.dto.response.CreateChatRoomResponse; -import com.dnd.gongmuin.chatroom.dto.response.RejectChatResponse; import com.dnd.gongmuin.chatroom.service.ChatRoomService; import com.dnd.gongmuin.common.dto.PageResponse; import com.dnd.gongmuin.member.domain.Member; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @Tag(name = "채팅방 API") @@ -45,16 +36,6 @@ public ResponseEntity> getChatMessages( return ResponseEntity.ok(response); } - @Operation(summary = "채팅방 생성 API", description = "요청자가 답변자와의 채팅방을 생성한다.") - @PostMapping("/api/chat-rooms") - public ResponseEntity createChatRoom( - @Valid @RequestBody CreateChatRoomRequest request, - @AuthenticationPrincipal Member member - ) { - CreateChatRoomResponse response = chatRoomService.createChatRoom(request, member); - return ResponseEntity.ok(response); - } - @Operation(summary = "채팅방 활성화 목록 조회 API", description = "회원의 채팅방 목록을 조회한다.") @GetMapping("/api/chat-rooms") public ResponseEntity> getChatRoomsByMember( @@ -66,17 +47,6 @@ public ResponseEntity> getChatRoomsByMember return ResponseEntity.ok(response); } - @Operation(summary = "채팅방 요청 목록 조회 API", description = "회원의 채팅방 목록을 조회한다.") - @GetMapping("/api/chat-rooms/proposals") - public ResponseEntity> getChatProposalsByMember( - @AuthenticationPrincipal Member member, - Pageable pageable - ) { - PageResponse response - = chatRoomService.getChatProposalsByMember(member, pageable); - return ResponseEntity.ok(response); - } - @Operation(summary = "채팅방 조회 API", description = "채팅방 아이디로 채팅방을 조회한다.") @GetMapping("/api/chat-rooms/{chatRoomId}") public ResponseEntity createChatRoom( @@ -87,23 +57,4 @@ public ResponseEntity createChatRoom( return ResponseEntity.ok(response); } - @Operation(summary = "채팅 수락 API", description = "채팅방에서 요청자와의 채팅을 수락한다.") - @PatchMapping("/api/chat-rooms/{chatRoomId}/accept") - public ResponseEntity acceptChat( - @PathVariable("chatRoomId") Long chatRoomId, - @AuthenticationPrincipal Member member - ) { - AcceptChatResponse response = chatRoomService.acceptChat(chatRoomId, member); - return ResponseEntity.ok(response); - } - - @Operation(summary = "채팅 거절 API", description = "채팅방에서 요청자와의 채팅을 거절한다.") - @PatchMapping("/api/chat-rooms/{chatRoomId}/reject") - public ResponseEntity rejectChat( - @PathVariable("chatRoomId") Long chatRoomId, - @AuthenticationPrincipal Member member - ) { - RejectChatResponse response = chatRoomService.rejectChat(chatRoomId, member); - return ResponseEntity.ok(response); - } -} +} \ No newline at end of file From bda63f08339a2c00505888dc72d91cf9f5b1ad6f Mon Sep 17 00:00:00 2001 From: hs12 Date: Fri, 15 Nov 2024 22:54:07 +0900 Subject: [PATCH 30/44] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=EB=B0=A9?= =?UTF-8?q?=20API=EC=97=90=20=EC=9E=88=EB=8D=98=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20API=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChatRoomControllerTest.java | 114 +----------------- 1 file changed, 5 insertions(+), 109 deletions(-) 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 bf36f111..2a8bf2eb 100644 --- a/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java +++ b/src/test/java/com/dnd/gongmuin/chat/controller/ChatRoomControllerTest.java @@ -1,6 +1,5 @@ package com.dnd.gongmuin.chat.controller; -import static org.springframework.http.MediaType.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -15,8 +14,6 @@ import com.dnd.gongmuin.chatroom.domain.ChatMessage; import com.dnd.gongmuin.chatroom.domain.ChatRoom; -import com.dnd.gongmuin.chatroom.domain.InquiryStatus; -import com.dnd.gongmuin.chatroom.dto.request.CreateChatRoomRequest; import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; import com.dnd.gongmuin.common.fixture.ChatMessageFixture; @@ -30,11 +27,9 @@ import com.dnd.gongmuin.question_post.domain.QuestionPost; import com.dnd.gongmuin.question_post.repository.QuestionPostRepository; -@DisplayName("[ChatMessage 통합 테스트]") +@DisplayName("[채팅방 통합 테스트]") class ChatRoomControllerTest extends ApiTestSupport { - private static final int CHAT_REWARD = 2000; - @Autowired private ChatMessageRepository chatMessageRepository; @@ -76,28 +71,6 @@ void getChatMessages() throws Exception { .andExpect(jsonPath("$.content[0].isRead").value(chatMessages.get(0).getIsRead())); } - @DisplayName("[채팅방을 생성할 수 있다.]") - @Test - void createChatRoom() throws Exception { - Member answerer = memberRepository.save(MemberFixture.member4()); - QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(loginMember)); - CreateChatRoomRequest request = new CreateChatRoomRequest(questionPost.getId(), answerer.getId()); - - mockMvc.perform(post("/api/chat-rooms") - .cookie(accessToken) - .content(toJson(request)) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.credit").value(loginMember.getCredit() - CHAT_REWARD)) - .andExpect(jsonPath("$.questionPostId").value(questionPost.getId())) - .andExpect(jsonPath("$.targetJobGroup").value(questionPost.getJobGroup().getLabel())) - .andExpect(jsonPath("$.title").value(questionPost.getTitle())) - .andExpect(jsonPath("$.receiverInfo.memberId").value(answerer.getId())) - .andExpect(jsonPath("$.receiverInfo.nickname").value(answerer.getNickname())) - .andExpect(jsonPath("$.receiverInfo.memberJobGroup").value(answerer.getJobGroup().getLabel())) - .andExpect(jsonPath("$.receiverInfo.profileImageNo").value(answerer.getProfileImageNo())); - } - @DisplayName("[회원의 채팅방 목록을 조회할 수 있다.]") @Test void getChatRoomsByMember() throws Exception { @@ -111,13 +84,13 @@ void getChatRoomsByMember() throws Exception { ) ); ChatRoom chatRoom1 = chatRoomRepository.save( - ChatRoomFixture.acceptedChatRoom(questionPosts.get(0), member1, loginMember)); + ChatRoomFixture.chatRoom(questionPosts.get(0), member1, loginMember)); ChatRoom chatRoom2 = chatRoomRepository.save( - ChatRoomFixture.acceptedChatRoom(questionPosts.get(0), member2, loginMember)); + ChatRoomFixture.chatRoom(questionPosts.get(0), member2, loginMember)); ChatRoom chatRoom3 = chatRoomRepository.save( - ChatRoomFixture.acceptedChatRoom(questionPosts.get(1), loginMember, member1)); + ChatRoomFixture.chatRoom(questionPosts.get(1), loginMember, member1)); ChatRoom unrelatedChatroom = chatRoomRepository.save( - ChatRoomFixture.acceptedChatRoom(questionPosts.get(1), member2, member1)); + ChatRoomFixture.chatRoom(questionPosts.get(1), member2, member1)); chatMessageRepository.saveAll( List.of( @@ -156,55 +129,6 @@ void getChatRoomsByMember() throws Exception { .andDo(MockMvcResultHandlers.print()); } - @DisplayName("[회원의 채팅 요청 목록을 조회할 수 있다.]") - @Test - void getChatProposalsByMember() throws Exception { - //given - Member member1 = memberRepository.save(MemberFixture.member4()); - Member member2 = memberRepository.save(MemberFixture.member5()); - List questionPosts = questionPostRepository.saveAll( - List.of( - questionPostRepository.save(QuestionPostFixture.questionPost(member1)), - questionPostRepository.save(QuestionPostFixture.questionPost(member2)) - ) - ); - ChatRoom chatRoom1 = chatRoomRepository.save( - ChatRoomFixture.chatRoom(questionPosts.get(0), member1, loginMember)); - ChatRoom chatRoom2 = chatRoomRepository.save( - ChatRoomFixture.chatRoom(questionPosts.get(1), loginMember, member1)); - ChatRoom unrelatedChatroom = chatRoomRepository.save( - ChatRoomFixture.chatRoom(questionPosts.get(1), member2, member1)); - - chatMessageRepository.saveAll( - List.of( - chatMessageRepository.save( - ChatMessageFixture.chatMessage(chatRoom1.getId(), "11", LocalDateTime.now())), - chatMessageRepository.save( - ChatMessageFixture.chatMessage(chatRoom2.getId(), "21", LocalDateTime.now())), - chatMessageRepository.save( - ChatMessageFixture.chatMessage(unrelatedChatroom.getId(), "31", LocalDateTime.now())) - ) - ); - - // when & then - mockMvc.perform(get("/api/chat-rooms/proposals") - .cookie(accessToken)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.size").value(2)) - .andExpect(jsonPath("$.content[0].chatRoomId").value(chatRoom2.getId())) - .andExpect(jsonPath("$.content[0].latestMessage").value("21")) - .andExpect(jsonPath("$.content[0].chatPartner.memberId").value(member1.getId())) - .andExpect(jsonPath("$.content[0].isInquirer").value(true)) - .andExpect(jsonPath("$.content[0].chatStatus").value(InquiryStatus.PENDING.getLabel())) - - .andExpect(jsonPath("$.content[1].chatRoomId").value(chatRoom1.getId())) - .andExpect(jsonPath("$.content[1].latestMessage").value("11")) - .andExpect(jsonPath("$.content[1].chatPartner.memberId").value(member1.getId())) - .andExpect(jsonPath("$.content[1].isInquirer").value(false)) - .andExpect(jsonPath("$.content[1].chatStatus").value(InquiryStatus.PENDING.getLabel())) - .andDo(MockMvcResultHandlers.print()); - } - @DisplayName("[채팅방 아이디로 채팅방을 상세조회할 수 있다.]") @Test void getChatRoomById() throws Exception { @@ -224,32 +148,4 @@ void getChatRoomById() throws Exception { .andExpect(jsonPath("$.receiverInfo.profileImageNo").value(inquirer.getProfileImageNo())) .andExpect(jsonPath("$.isInquirer").value(false)); } - - @DisplayName("[답변자가 채팅 요청을 수락할 수 있다.]") - @Test - void acceptChatRoom() throws Exception { - Member inquirer = memberRepository.save(MemberFixture.member4()); - QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(inquirer)); - ChatRoom chatRoom = chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, inquirer, loginMember)); - int previousAnswererCredit = chatRoom.getAnswerer().getCredit(); - - mockMvc.perform(patch("/api/chat-rooms/{chatRoomId}/accept", chatRoom.getId()) - .cookie(accessToken)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.chatStatus").value(InquiryStatus.ACCEPTED.getLabel())) - .andExpect(jsonPath("$.credit").value(previousAnswererCredit + CHAT_REWARD)); - } - - @DisplayName("[답변자가 채팅 요청을 거절할 수 있다.]") - @Test - void rejectChatRoom() throws Exception { - Member inquirer = memberRepository.save(MemberFixture.member4()); - QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(inquirer)); - ChatRoom chatRoom = chatRoomRepository.save(ChatRoomFixture.chatRoom(questionPost, inquirer, loginMember)); - - mockMvc.perform(patch("/api/chat-rooms/{chatRoomId}/reject", chatRoom.getId()) - .cookie(accessToken)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.chatStatus").value(InquiryStatus.REJECTED.getLabel())); - } } \ No newline at end of file From fdb99a2a20b353bef7a147a5e00fc2fa99937694 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 12:29:42 +0900 Subject: [PATCH 31/44] =?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 --- .../controller/ChatInquiryController.java | 4 ++-- .../scheduler/ChatInquiryScheduler.java | 1 - .../chat_inquiry/service/ChatInquiryService.java | 3 +-- .../chatroom/dto/response/ChatProposalResponse.java | 13 ------------- .../repository/ChatInquiryRepositoryTest.java | 1 + .../service/ChatInquiryServiceTest.java | 3 +-- 6 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalResponse.java 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 9ff0cdfd..d9dbaa3c 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 @@ -30,7 +30,7 @@ public class ChatInquiryController { @Operation(summary = "채팅 요청 API", description = "답변자 아이디로 채팅 요청을 생성한다.") @GetMapping("/api/chat/inquiries") - public ResponseEntity getChatProposalsByMember( + public ResponseEntity createChatInquiry( CreateChatInquiryRequest request, @AuthenticationPrincipal Member member ) { @@ -41,7 +41,7 @@ public ResponseEntity getChatProposalsByMember( @Operation(summary = "채팅방 요청 목록 조회 API", description = "회원의 채팅방 목록을 조회한다.") @GetMapping("/api/chat/inquires") - public ResponseEntity> getChatProposalsByMember( + public ResponseEntity> getChatInquiresByMember( @AuthenticationPrincipal Member member, Pageable pageable ) { diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/scheduler/ChatInquiryScheduler.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/scheduler/ChatInquiryScheduler.java index 63e9b945..c1eb3213 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/scheduler/ChatInquiryScheduler.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/scheduler/ChatInquiryScheduler.java @@ -5,7 +5,6 @@ import org.springframework.transaction.annotation.Transactional; import com.dnd.gongmuin.chat_inquiry.service.ChatInquiryService; -import com.dnd.gongmuin.chatroom.service.ChatRoomService; import lombok.RequiredArgsConstructor; 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 5dbaa7d9..4d8ea017 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 @@ -15,8 +15,8 @@ import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryResponse; -import com.dnd.gongmuin.chat_inquiry.repository.ChatInquiryRepository; import com.dnd.gongmuin.chat_inquiry.dto.RejectChatResponse; +import com.dnd.gongmuin.chat_inquiry.repository.ChatInquiryRepository; import com.dnd.gongmuin.chatroom.domain.ChatRoom; import com.dnd.gongmuin.chatroom.dto.ChatRoomMapper; import com.dnd.gongmuin.chatroom.exception.ChatErrorCode; @@ -127,7 +127,6 @@ private static void validateIfAnswerer(Member member, ChatInquiry chatInquiry) { } } - private QuestionPost getQuestionPostById(Long id) { return questionPostRepository.findById(id) .orElseThrow(() -> new NotFoundException(QuestionPostErrorCode.NOT_FOUND_QUESTION_POST)); diff --git a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalResponse.java deleted file mode 100644 index 5af289e7..00000000 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/ChatProposalResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dnd.gongmuin.chatroom.dto.response; - -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; - -public record ChatProposalResponse ( - Long chatRoomId, - String chatStatus, - boolean isInquirer, - MemberInfo chatPartner, - String latestMessage, - String messageType, - String messageCreatedAt -){} diff --git a/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java b/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java index b720eee2..522b2d8d 100644 --- a/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java +++ b/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.test.util.ReflectionTestUtils; + import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; 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 e8560591..be8cddd8 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 @@ -43,11 +43,10 @@ @DisplayName("[채팅 요청 서비스 단위 테스트]") @ExtendWith(MockitoExtension.class) -class ChatInquiryServiceTest{ +class ChatInquiryServiceTest { private static final int CHAT_REWARD = 2000; private static final String CHAT_MESSAGE = "와"; - private static final String REQUEST_MESSAGE_POSTFIX = "님이 채팅을 요청하셨습니다."; private final PageRequest pageRequest = PageRequest.of(0, 5); @Mock From a4e2e6e999a287215ab6dabf2ca16c846e787c1e Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:17:13 +0900 Subject: [PATCH 32/44] =?UTF-8?q?[refactor]=20:=20dto=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=20(chatStatus->=20inquiryStatus)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gongmuin/chat_inquiry/dto/AcceptChatResponse.java | 2 +- .../gongmuin/chat_inquiry/dto/ChatInquiryResponse.java | 2 +- .../chat_inquiry/dto/CreateChatInquiryResponse.java | 9 ++++----- .../gongmuin/chat_inquiry/dto/RejectChatResponse.java | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/AcceptChatResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/AcceptChatResponse.java index 2d1d9188..64fa6e01 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/AcceptChatResponse.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/AcceptChatResponse.java @@ -2,7 +2,7 @@ public record AcceptChatResponse( Long createdChatRoomId, - String chatStatus, + String inquiryStatus, int credit ) { } 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 60650583..08219a45 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 @@ -7,7 +7,7 @@ public record ChatInquiryResponse( Long chatInquiryId, String message, - String chatStatus, + String inquiryStatus, boolean isInquirer, Long partnerId, String partnerNickname, 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 96beff32..34433c03 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,12 +1,11 @@ package com.dnd.gongmuin.chat_inquiry.dto; +import com.dnd.gongmuin.question_post.dto.response.MemberInfo; + public record CreateChatInquiryResponse( Long chatInquiryId, String message, - String chatStatus, - Long partnerId, - String partnerNickname, - String partnerJobGroup, - int partnerProfileImageNo + String inquiryStatus, + MemberInfo partnerInfo ) { } diff --git a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/RejectChatResponse.java b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/RejectChatResponse.java index d4310260..750fb01c 100644 --- a/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/RejectChatResponse.java +++ b/src/main/java/com/dnd/gongmuin/chat_inquiry/dto/RejectChatResponse.java @@ -1,6 +1,6 @@ package com.dnd.gongmuin.chat_inquiry.dto; public record RejectChatResponse( - String chatStatus + String inquiryStatus ) { } From 9f409f9af7075d4d0411ec4c3c2ff66dd9eeac95 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:17:28 +0900 Subject: [PATCH 33/44] =?UTF-8?q?[test]=20:=20dto=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChatInquiryControllerTest.java | 8 ++-- .../service/ChatInquiryServiceTest.java | 42 +++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) 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 541886ec..e0a6d399 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 @@ -84,12 +84,12 @@ void getChatInquiresByMember() throws Exception { .andExpect(jsonPath("$.content[0].chatInquiryId").value(chatInquiry2.getId())) // 내림차순 .andExpect(jsonPath("$.content[0].partnerId").value(member2.getId())) .andExpect(jsonPath("$.content[0].isInquirer").value(true)) - .andExpect(jsonPath("$.content[0].chatStatus").value(InquiryStatus.PENDING.getLabel())) + .andExpect(jsonPath("$.content[0].inquiryStatus").value(InquiryStatus.PENDING.getLabel())) .andExpect(jsonPath("$.content[1].chatInquiryId").value(chatInquiry1.getId())) .andExpect(jsonPath("$.content[1].partnerId").value(member1.getId())) .andExpect(jsonPath("$.content[1].isInquirer").value(false)) - .andExpect(jsonPath("$.content[1].chatStatus").value(InquiryStatus.PENDING.getLabel())) + .andExpect(jsonPath("$.content[1].inquiryStatus").value(InquiryStatus.PENDING.getLabel())) .andDo(MockMvcResultHandlers.print()); } @@ -105,7 +105,7 @@ void acceptChatRoom() throws Exception { mockMvc.perform(patch("/api/chat/inquires/{chatInquiryId}/accept", chatInquiry.getId()) .cookie(accessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.chatStatus").value(InquiryStatus.ACCEPTED.getLabel())) + .andExpect(jsonPath("$.inquiryStatus").value(InquiryStatus.ACCEPTED.getLabel())) .andExpect(jsonPath("$.credit").value(previousAnswererCredit + CHAT_REWARD)); } @@ -120,6 +120,6 @@ void rejectChatRoom() throws Exception { mockMvc.perform(patch("/api/chat/inquires/{chatInquiryId}/reject", chatInquiry.getId()) .cookie(accessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.chatStatus").value(InquiryStatus.REJECTED.getLabel())); + .andExpect(jsonPath("$.inquiryStatus").value(InquiryStatus.REJECTED.getLabel())); } } \ No newline at end of file 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 be8cddd8..ae60d1ff 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 @@ -23,6 +23,7 @@ import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; import com.dnd.gongmuin.chat_inquiry.dto.ChatInquiryResponse; import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; +import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryResponse; import com.dnd.gongmuin.chat_inquiry.dto.RejectChatResponse; import com.dnd.gongmuin.chat_inquiry.repository.ChatInquiryRepository; import com.dnd.gongmuin.chatroom.domain.ChatRoom; @@ -70,13 +71,40 @@ class ChatInquiryServiceTest { @InjectMocks private ChatInquiryService chatInquiryService; + @DisplayName("[댓글 작성자에게 채팅을 요청할 수 있다.]") + @Test + void createInquiry() { + //given + Member inquirer = MemberFixture.member(1L); + Member answerer = MemberFixture.member(2L); + QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); + CreateChatInquiryRequest request = new CreateChatInquiryRequest( + questionPost.getId(), + answerer.getId(), + CHAT_MESSAGE + ); + + given(questionPostRepository.findById(questionPost.getId())) + .willReturn(Optional.of(questionPost)); + given(memberRepository.findById(answerer.getId())) + .willReturn(Optional.of(answerer)); + + CreateChatInquiryResponse response = chatInquiryService.createChatInquiry(request, inquirer); + System.out.println("response = " + response); + // //then + // assertAll( + // + // ); + + } + @DisplayName("[요청자의 크레딧이 2000미만이면 채팅을 요청할 수 없다.]") @Test - void createChatRoom_fail() { + void createInquiry_fails() { //given Member inquirer = MemberFixture.member(1L); Member answerer = MemberFixture.member(2L); - ReflectionTestUtils.setField(inquirer, "credit", 1999); + ReflectionTestUtils.setField(inquirer, "credit", CHAT_REWARD - 1); QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); CreateChatInquiryRequest request = new CreateChatInquiryRequest( questionPost.getId(), @@ -97,7 +125,7 @@ void createChatRoom_fail() { @DisplayName("[회원이 속한 채팅 요청 목록을 조회할 수 있다.]") @Test - void getChatProposalsByMember() { + void getChatInquiresByMember() { //given Long chatInquiryId = 1L; Member targetMember = MemberFixture.member(1L); @@ -146,7 +174,7 @@ void acceptChat() { //then assertAll( - () -> assertThat(response.chatStatus()) + () -> assertThat(response.inquiryStatus()) .isEqualTo(InquiryStatus.ACCEPTED.getLabel()), () -> assertThat(response.credit()) .isEqualTo(previousCredit + CHAT_REWARD) @@ -174,7 +202,7 @@ void acceptChatWithEventPublish() { //then assertAll( - () -> assertThat(response.chatStatus()) + () -> assertThat(response.inquiryStatus()) .isEqualTo(InquiryStatus.ACCEPTED.getLabel()), () -> assertThat(response.credit()) .isEqualTo(previousCredit + CHAT_REWARD), @@ -199,7 +227,7 @@ void rejectChat() { RejectChatResponse response = chatInquiryService.rejectChat(chatInquiryId, answerer); //then - assertThat(response.chatStatus()) + assertThat(response.inquiryStatus()) .isEqualTo(InquiryStatus.REJECTED.getLabel()); } @@ -221,7 +249,7 @@ void rejectChatWithEventPublish() { //then assertAll( - () -> assertThat(response.chatStatus()).isEqualTo(InquiryStatus.REJECTED.getLabel()), + () -> assertThat(response.inquiryStatus()).isEqualTo(InquiryStatus.REJECTED.getLabel()), () -> verify(eventPublisher, times(1)).publishEvent(any(NotificationEvent.class)) ); } From 79440f4a18106fa5ce59f5c92d1ef76b9d6eabb6 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:17:58 +0900 Subject: [PATCH 34/44] =?UTF-8?q?[refactor]=20:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20DTO=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/CreateChatRoomResponse.java | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/main/java/com/dnd/gongmuin/chatroom/dto/response/CreateChatRoomResponse.java diff --git a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/CreateChatRoomResponse.java b/src/main/java/com/dnd/gongmuin/chatroom/dto/response/CreateChatRoomResponse.java deleted file mode 100644 index 199ef30d..00000000 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/response/CreateChatRoomResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dnd.gongmuin.chatroom.dto.response; - -import com.dnd.gongmuin.question_post.dto.response.MemberInfo; - -public record CreateChatRoomResponse( - Long questionPostId, - String targetJobGroup, - String title, - MemberInfo receiverInfo, - String chatStatus, - int credit -) { -} From 481563d4ebdecf06b9b314541abe8591de31a409 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:19:37 +0900 Subject: [PATCH 35/44] =?UTF-8?q?[feat]=20:=20dto=20-=20=EC=B1=84=ED=8C=85?= =?UTF-8?q?=20=EC=83=81=EB=8C=80=20=EC=A0=95=EB=B3=B4=20memberInfo=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gongmuin/chat_inquiry/dto/ChatInquiryMapper.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 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 d11c60a4..4a3486ec 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,6 +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 lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -34,10 +35,12 @@ public static CreateChatInquiryResponse toCreateChatInquiryResponse( chatInquiry.getId(), chatInquiry.getMessage(), InquiryStatus.PENDING.getLabel(), - answerer.getId(), - answerer.getNickname(), - answerer.getJobGroup().getLabel(), - answerer.getProfileImageNo() + new MemberInfo( + answerer.getId(), + answerer.getNickname(), + answerer.getJobGroup().getLabel(), + answerer.getProfileImageNo() + ) ); } From 8c1f541707cad1190c64832418fb5837b8e46c78 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:31:28 +0900 Subject: [PATCH 36/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20dto=20-=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=83=81=EB=8C=80=20=EC=A0=95=EB=B3=B4=20memberInf?= =?UTF-8?q?o=20=EA=B0=9D=EC=B2=B4=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_inquiry/dto/ChatInquiryResponse.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 08219a45..4edf4011 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,6 +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.querydsl.core.annotations.QueryProjection; public record ChatInquiryResponse( @@ -9,10 +10,7 @@ public record ChatInquiryResponse( String message, String inquiryStatus, boolean isInquirer, - Long partnerId, - String partnerNickname, - String partnerJobGroup, - int partnerProfileImageNo + MemberInfo partnerInfo ) { @QueryProjection public ChatInquiryResponse( @@ -30,10 +28,12 @@ public ChatInquiryResponse( message, inquiryStatus.getLabel(), isInquirer, - partnerId, - partnerNickname, - partnerJobGroup.getLabel(), - partnerProfileImageNo + new MemberInfo( + partnerId, + partnerNickname, + partnerJobGroup.getLabel(), + partnerProfileImageNo + ) ); } } From 24cb86d1fc05cf2d0efdcb42e488eb34ccd62e04 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:31:44 +0900 Subject: [PATCH 37/44] =?UTF-8?q?[test]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20dto=20-=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=83=81=EB=8C=80=20=EC=A0=95=EB=B3=B4=20memberInf?= =?UTF-8?q?o=20=EA=B0=9D=EC=B2=B4=20=EC=82=AC=EC=9A=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_inquiry/controller/ChatInquiryControllerTest.java | 4 ++-- .../chat_inquiry/repository/ChatInquiryRepositoryTest.java | 4 ++-- .../gongmuin/chat_inquiry/service/ChatInquiryServiceTest.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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 e0a6d399..db12b4d0 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 @@ -82,12 +82,12 @@ void getChatInquiresByMember() throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.size").value(2)) .andExpect(jsonPath("$.content[0].chatInquiryId").value(chatInquiry2.getId())) // 내림차순 - .andExpect(jsonPath("$.content[0].partnerId").value(member2.getId())) + .andExpect(jsonPath("$.content[0].partnerInfo.memberId").value(member2.getId())) .andExpect(jsonPath("$.content[0].isInquirer").value(true)) .andExpect(jsonPath("$.content[0].inquiryStatus").value(InquiryStatus.PENDING.getLabel())) .andExpect(jsonPath("$.content[1].chatInquiryId").value(chatInquiry1.getId())) - .andExpect(jsonPath("$.content[1].partnerId").value(member1.getId())) + .andExpect(jsonPath("$.content[1].partnerInfo.memberId").value(member1.getId())) .andExpect(jsonPath("$.content[1].isInquirer").value(false)) .andExpect(jsonPath("$.content[1].inquiryStatus").value(InquiryStatus.PENDING.getLabel())) .andDo(MockMvcResultHandlers.print()); diff --git a/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java b/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java index 522b2d8d..79ef7307 100644 --- a/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java +++ b/src/test/java/com/dnd/gongmuin/chat_inquiry/repository/ChatInquiryRepositoryTest.java @@ -64,9 +64,9 @@ void getChatInquiresByMember() { Assertions.assertAll( () -> assertThat(responses).hasSize(2), () -> assertThat(responses.get(0).chatInquiryId()).isEqualTo(chatInquiries.get(1).getId()), - () -> assertThat(responses.get(0).partnerId()).isEqualTo(questioner.getId()), + () -> assertThat(responses.get(0).partnerInfo().memberId()).isEqualTo(questioner.getId()), () -> assertThat(responses.get(1).chatInquiryId()).isEqualTo(chatInquiries.get(0).getId()), - () -> assertThat(responses.get(1).partnerId()).isEqualTo(answerer.getId()) + () -> assertThat(responses.get(1).partnerInfo().memberId()).isEqualTo(answerer.getId()) ); } 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 ae60d1ff..eb5fe1bc 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 @@ -146,7 +146,7 @@ void getChatInquiresByMember() { () -> assertThat(response).hasSize(1), () -> assertThat(response.get(0).chatInquiryId()) .isEqualTo(chatInquiryId), - () -> assertThat(response.get(0).partnerId()) + () -> assertThat(response.get(0).partnerInfo().memberId()) .isEqualTo(partner.getId()), () -> assertThat(response.get(0).message()) .isEqualTo(CHAT_MESSAGE) From 293a084cde623b4c82e53ede6aaae5f64a761339 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:42:13 +0900 Subject: [PATCH 38/44] =?UTF-8?q?[refactor]=20:=20=EC=9A=94=EC=B2=AD=20dto?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnd/gongmuin/chat_inquiry/dto/ChatInquiryResponse.java | 4 ++-- .../gongmuin/chat_inquiry/dto/CreateChatInquiryResponse.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 4edf4011..6eaf7fdc 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 @@ -15,7 +15,7 @@ public record ChatInquiryResponse( @QueryProjection public ChatInquiryResponse( Long chatInquiryId, - String message, + String inquiryMessage, InquiryStatus inquiryStatus, boolean isInquirer, Long partnerId, @@ -25,7 +25,7 @@ public ChatInquiryResponse( ) { this( chatInquiryId, - message, + inquiryMessage, inquiryStatus.getLabel(), isInquirer, new MemberInfo( 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 34433c03..6986b83b 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 @@ -4,7 +4,7 @@ public record CreateChatInquiryResponse( Long chatInquiryId, - String message, + String inquiryMessage, String inquiryStatus, MemberInfo partnerInfo ) { From d7dd8738fc6eb1ac3ba74824aebbd442f1d62a17 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:42:40 +0900 Subject: [PATCH 39/44] =?UTF-8?q?[test]=20:=20chatInquiry=20fixture=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/fixture/ChatInquiryFixture.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/com/dnd/gongmuin/common/fixture/ChatInquiryFixture.java b/src/test/java/com/dnd/gongmuin/common/fixture/ChatInquiryFixture.java index 0a96912c..4cd9a170 100644 --- a/src/test/java/com/dnd/gongmuin/common/fixture/ChatInquiryFixture.java +++ b/src/test/java/com/dnd/gongmuin/common/fixture/ChatInquiryFixture.java @@ -1,5 +1,7 @@ package com.dnd.gongmuin.common.fixture; +import org.springframework.test.util.ReflectionTestUtils; + import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; import com.dnd.gongmuin.member.domain.Member; import com.dnd.gongmuin.question_post.domain.QuestionPost; @@ -23,4 +25,21 @@ public static ChatInquiry chatInquiry( message ); } + + public static ChatInquiry chatInquiry( + Long id, + QuestionPost questionPost, + Member inquirer, + Member answerer, + String message + ) { + ChatInquiry chatInquiry = ChatInquiry.of( + questionPost, + inquirer, + answerer, + message + ); + ReflectionTestUtils.setField(chatInquiry, "id", id); + return chatInquiry; + } } From a71487dfb0205a35e8e656fdc7ddef5fb3748595 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 13:43:09 +0900 Subject: [PATCH 40/44] =?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=9D=EC=84=B1=20=EB=B9=84=EC=A6=88?= =?UTF-8?q?=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ChatInquiryServiceTest.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 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 eb5fe1bc..b12c9e26 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 @@ -47,7 +47,7 @@ class ChatInquiryServiceTest { private static final int CHAT_REWARD = 2000; - private static final String CHAT_MESSAGE = "와"; + private static final String INQUIRY_MESSAGE = "채팅을 요청합니다."; private final PageRequest pageRequest = PageRequest.of(0, 5); @Mock @@ -75,27 +75,34 @@ class ChatInquiryServiceTest { @Test void createInquiry() { //given + Long chatInquiryId = 1L; Member inquirer = MemberFixture.member(1L); Member answerer = MemberFixture.member(2L); QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry( + chatInquiryId, questionPost, inquirer, answerer, INQUIRY_MESSAGE + ); CreateChatInquiryRequest request = new CreateChatInquiryRequest( questionPost.getId(), answerer.getId(), - CHAT_MESSAGE + INQUIRY_MESSAGE ); given(questionPostRepository.findById(questionPost.getId())) .willReturn(Optional.of(questionPost)); given(memberRepository.findById(answerer.getId())) .willReturn(Optional.of(answerer)); + given(chatInquiryRepository.save(any(ChatInquiry.class))).willReturn(chatInquiry); CreateChatInquiryResponse response = chatInquiryService.createChatInquiry(request, inquirer); - System.out.println("response = " + response); - // //then - // assertAll( - // - // ); - + assertAll( + () -> assertThat(response.chatInquiryId()) + .isEqualTo(chatInquiryId), + () -> assertThat(response.partnerInfo().memberId()) + .isEqualTo(answerer.getId()), + () -> assertThat(response.inquiryMessage()) + .isEqualTo(INQUIRY_MESSAGE) + ); } @DisplayName("[요청자의 크레딧이 2000미만이면 채팅을 요청할 수 없다.]") @@ -109,7 +116,7 @@ void createInquiry_fails() { CreateChatInquiryRequest request = new CreateChatInquiryRequest( questionPost.getId(), answerer.getId(), - CHAT_MESSAGE + INQUIRY_MESSAGE ); given(questionPostRepository.findById(questionPost.getId())) @@ -131,7 +138,7 @@ void getChatInquiresByMember() { Member targetMember = MemberFixture.member(1L); Member partner = MemberFixture.member(2L); ChatInquiryResponse chatInquiryResponse = new ChatInquiryResponse( - chatInquiryId, CHAT_MESSAGE, InquiryStatus.PENDING, true, partner.getId(), + chatInquiryId, INQUIRY_MESSAGE, InquiryStatus.PENDING, true, partner.getId(), partner.getNickname(), partner.getJobGroup(), partner.getProfileImageNo() ); given(chatInquiryRepository.getChatInquiresByMember(targetMember, pageRequest)) @@ -149,7 +156,7 @@ void getChatInquiresByMember() { () -> assertThat(response.get(0).partnerInfo().memberId()) .isEqualTo(partner.getId()), () -> assertThat(response.get(0).message()) - .isEqualTo(CHAT_MESSAGE) + .isEqualTo(INQUIRY_MESSAGE) ); } @@ -162,7 +169,7 @@ void acceptChat() { Member answerer = MemberFixture.member(2L); int previousCredit = answerer.getCredit(); QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, CHAT_MESSAGE); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, INQUIRY_MESSAGE); ChatRoom chatRoom = ChatRoomFixture.chatRoom(1L, questionPost, inquirer, answerer); given(chatInquiryRepository.findById(chatInquiryId)) .willReturn(Optional.of(chatInquiry)); @@ -190,7 +197,7 @@ void acceptChatWithEventPublish() { Member answerer = MemberFixture.member(2L); int previousCredit = answerer.getCredit(); QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, CHAT_MESSAGE); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, INQUIRY_MESSAGE); ChatRoom chatRoom = ChatRoomFixture.chatRoom(1L, questionPost, inquirer, answerer); given(chatInquiryRepository.findById(chatInquiryId)) .willReturn(Optional.of(chatInquiry)); @@ -218,7 +225,7 @@ void rejectChat() { Member inquirer = MemberFixture.member(1L); Member answerer = MemberFixture.member(2L); QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, CHAT_MESSAGE); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, INQUIRY_MESSAGE); given(chatInquiryRepository.findById(chatInquiryId)) .willReturn(Optional.of(chatInquiry)); @@ -239,7 +246,7 @@ void rejectChatWithEventPublish() { Member inquirer = MemberFixture.member(1L); Member answerer = MemberFixture.member(2L); QuestionPost questionPost = QuestionPostFixture.questionPost(inquirer); - ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, CHAT_MESSAGE); + ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(questionPost, inquirer, answerer, INQUIRY_MESSAGE); given(chatInquiryRepository.findById(chatInquiryId)) .willReturn(Optional.of(chatInquiry)); From 8052b2a346fc14ee802035df1e044a35305220c2 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 14:04:47 +0900 Subject: [PATCH 41/44] =?UTF-8?q?[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20API=20uri=20=EB=B0=8F=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChatInquiryController.java | 11 +++---- .../controller/ChatInquiryControllerTest.java | 29 +++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) 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 d9dbaa3c..ccf6df01 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 @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; @@ -28,8 +29,8 @@ public class ChatInquiryController { private final ChatInquiryService chatInquiryService; - @Operation(summary = "채팅 요청 API", description = "답변자 아이디로 채팅 요청을 생성한다.") - @GetMapping("/api/chat/inquiries") + @Operation(summary = "채팅 요청 생성 API", description = "답변자 아이디로 채팅 요청을 생성한다.") + @PostMapping("/api/chat/inquiries") public ResponseEntity createChatInquiry( CreateChatInquiryRequest request, @AuthenticationPrincipal Member member @@ -40,7 +41,7 @@ public ResponseEntity createChatInquiry( } @Operation(summary = "채팅방 요청 목록 조회 API", description = "회원의 채팅방 목록을 조회한다.") - @GetMapping("/api/chat/inquires") + @GetMapping("/api/chat/inquiries") public ResponseEntity> getChatInquiresByMember( @AuthenticationPrincipal Member member, Pageable pageable @@ -51,7 +52,7 @@ public ResponseEntity> getChatInquiresByMember } @Operation(summary = "채팅 수락 API", description = "채팅방에서 요청자와의 채팅을 수락한다.") - @PatchMapping("/api/chat/inquires/{chatInquiryId}/accept") + @PatchMapping("/api/chat/inquiries/{chatInquiryId}/accept") public ResponseEntity acceptChat( @PathVariable("chatInquiryId") Long chatInquiryId, @AuthenticationPrincipal Member member @@ -61,7 +62,7 @@ public ResponseEntity acceptChat( } @Operation(summary = "채팅 거절 API", description = "채팅방에서 요청자와의 채팅을 거절한다.") - @PatchMapping("/api/chat/inquires/{chatInquiryId}/reject") + @PatchMapping("/api/chat/inquiries/{chatInquiryId}/reject") public ResponseEntity rejectChat( @PathVariable("chatInquiryId") Long chatInquiryId, @AuthenticationPrincipal Member 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 db12b4d0..2a81b802 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 @@ -59,6 +59,29 @@ void teardown() { chatMessageRepository.deleteAll(); } + @DisplayName("[답변자 아이디로 채팅을 요청할 수 있다.]") + @Test + void createChatInquiry() throws Exception { + //given + Member answerer = memberRepository.save(MemberFixture.member5()); + QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(loginMember)); + + //when & then + mockMvc.perform(post("/api/chat/inquiries") + .cookie(accessToken)) + .andExpect(status().isOk()) + // .andExpect(jsonPath("$.content[0].chatInquiryId").value(chatInquiry2.getId())) // 내림차순 + // .andExpect(jsonPath("$.content[0].partnerInfo.memberId").value(member2.getId())) + // .andExpect(jsonPath("$.content[0].isInquirer").value(true)) + // .andExpect(jsonPath("$.content[0].inquiryStatus").value(InquiryStatus.PENDING.getLabel())) + // + // .andExpect(jsonPath("$.content[1].chatInquiryId").value(chatInquiry1.getId())) + // .andExpect(jsonPath("$.content[1].partnerInfo.memberId").value(member1.getId())) + // .andExpect(jsonPath("$.content[1].isInquirer").value(false)) + // .andExpect(jsonPath("$.content[1].inquiryStatus").value(InquiryStatus.PENDING.getLabel())) + .andDo(MockMvcResultHandlers.print()); + } + @DisplayName("[회원의 채팅 요청 목록을 조회할 수 있다.]") @Test void getChatInquiresByMember() throws Exception { @@ -77,7 +100,7 @@ void getChatInquiresByMember() throws Exception { ChatInquiryFixture.chatInquiry(questionPosts.get(1), loginMember, member2, CHAT_MESSAGE)); // when & then - mockMvc.perform(get("/api/chat/inquires") + mockMvc.perform(get("/api/chat/inquiries") .cookie(accessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.size").value(2)) @@ -102,7 +125,7 @@ void acceptChatRoom() throws Exception { ChatInquiryFixture.chatInquiry(questionPost, inquirer, loginMember, CHAT_MESSAGE)); int previousAnswererCredit = loginMember.getCredit(); - mockMvc.perform(patch("/api/chat/inquires/{chatInquiryId}/accept", chatInquiry.getId()) + mockMvc.perform(patch("/api/chat/inquiries/{chatInquiryId}/accept", chatInquiry.getId()) .cookie(accessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.inquiryStatus").value(InquiryStatus.ACCEPTED.getLabel())) @@ -117,7 +140,7 @@ void rejectChatRoom() throws Exception { ChatInquiry chatInquiry = chatInquiryRepository.save( ChatInquiryFixture.chatInquiry(questionPost, inquirer, loginMember, CHAT_MESSAGE)); - mockMvc.perform(patch("/api/chat/inquires/{chatInquiryId}/reject", chatInquiry.getId()) + mockMvc.perform(patch("/api/chat/inquiries/{chatInquiryId}/reject", chatInquiry.getId()) .cookie(accessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.inquiryStatus").value(InquiryStatus.REJECTED.getLabel())); From ee0cf36eb4941e01f82dc8a3f44487441bf7ada5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 14:13:09 +0900 Subject: [PATCH 42/44] =?UTF-8?q?[fix]=20:=20controller=EC=97=90=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD=EB=90=9C=20requestBody=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat_inquiry/controller/ChatInquiryController.java | 4 +++- 1 file changed, 3 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 ccf6df01..4ee2e0e4 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 @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.PatchMapping; 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.RestController; import com.dnd.gongmuin.chat_inquiry.dto.AcceptChatResponse; @@ -20,6 +21,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @Tag(name = "채팅 요청 API") @@ -32,7 +34,7 @@ public class ChatInquiryController { @Operation(summary = "채팅 요청 생성 API", description = "답변자 아이디로 채팅 요청을 생성한다.") @PostMapping("/api/chat/inquiries") public ResponseEntity createChatInquiry( - CreateChatInquiryRequest request, + @Valid @RequestBody CreateChatInquiryRequest request, @AuthenticationPrincipal Member member ) { CreateChatInquiryResponse response From 936c812a9b383e26871d72fd94b16118b6882af8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 14:13:24 +0900 Subject: [PATCH 43/44] =?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=9D=EC=84=B1=20=ED=86=B5=ED=95=A9=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 --- .../controller/ChatInquiryControllerTest.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) 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 2a81b802..8d41caf9 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 @@ -1,5 +1,6 @@ package com.dnd.gongmuin.chat_inquiry.controller; +import static org.springframework.http.MediaType.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -13,6 +14,7 @@ import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry; import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus; +import com.dnd.gongmuin.chat_inquiry.dto.CreateChatInquiryRequest; import com.dnd.gongmuin.chat_inquiry.repository.ChatInquiryRepository; import com.dnd.gongmuin.chatroom.repository.ChatMessageRepository; import com.dnd.gongmuin.chatroom.repository.ChatRoomRepository; @@ -30,7 +32,7 @@ class ChatInquiryControllerTest extends ApiTestSupport { private static final int CHAT_REWARD = 2000; - private static final String CHAT_MESSAGE = "와"; + private static final String INQUIRY_MESSAGE = "와"; @Autowired private ChatMessageRepository chatMessageRepository; @@ -62,23 +64,21 @@ void teardown() { @DisplayName("[답변자 아이디로 채팅을 요청할 수 있다.]") @Test void createChatInquiry() throws Exception { - //given + //given Member answerer = memberRepository.save(MemberFixture.member5()); QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(loginMember)); - - //when & then + CreateChatInquiryRequest request = new CreateChatInquiryRequest( + questionPost.getId(), + answerer.getId(), + INQUIRY_MESSAGE + ); + //when & then mockMvc.perform(post("/api/chat/inquiries") - .cookie(accessToken)) + .cookie(accessToken) + .content(toJson(request)) + .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) - // .andExpect(jsonPath("$.content[0].chatInquiryId").value(chatInquiry2.getId())) // 내림차순 - // .andExpect(jsonPath("$.content[0].partnerInfo.memberId").value(member2.getId())) - // .andExpect(jsonPath("$.content[0].isInquirer").value(true)) - // .andExpect(jsonPath("$.content[0].inquiryStatus").value(InquiryStatus.PENDING.getLabel())) - // - // .andExpect(jsonPath("$.content[1].chatInquiryId").value(chatInquiry1.getId())) - // .andExpect(jsonPath("$.content[1].partnerInfo.memberId").value(member1.getId())) - // .andExpect(jsonPath("$.content[1].isInquirer").value(false)) - // .andExpect(jsonPath("$.content[1].inquiryStatus").value(InquiryStatus.PENDING.getLabel())) + .andExpect(jsonPath("$.inquiryStatus").value(InquiryStatus.PENDING.getLabel())) // 내림차순 .andDo(MockMvcResultHandlers.print()); } @@ -95,9 +95,9 @@ void getChatInquiresByMember() throws Exception { ) ); ChatInquiry chatInquiry1 = chatInquiryRepository.save( - ChatInquiryFixture.chatInquiry(questionPosts.get(0), member1, loginMember, CHAT_MESSAGE)); + ChatInquiryFixture.chatInquiry(questionPosts.get(0), member1, loginMember, INQUIRY_MESSAGE)); ChatInquiry chatInquiry2 = chatInquiryRepository.save( - ChatInquiryFixture.chatInquiry(questionPosts.get(1), loginMember, member2, CHAT_MESSAGE)); + ChatInquiryFixture.chatInquiry(questionPosts.get(1), loginMember, member2, INQUIRY_MESSAGE)); // when & then mockMvc.perform(get("/api/chat/inquiries") @@ -122,7 +122,7 @@ void acceptChatRoom() throws Exception { Member inquirer = memberRepository.save(MemberFixture.member4()); QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(inquirer)); ChatInquiry chatInquiry = chatInquiryRepository.save( - ChatInquiryFixture.chatInquiry(questionPost, inquirer, loginMember, CHAT_MESSAGE)); + ChatInquiryFixture.chatInquiry(questionPost, inquirer, loginMember, INQUIRY_MESSAGE)); int previousAnswererCredit = loginMember.getCredit(); mockMvc.perform(patch("/api/chat/inquiries/{chatInquiryId}/accept", chatInquiry.getId()) @@ -138,7 +138,7 @@ void rejectChatRoom() throws Exception { Member inquirer = memberRepository.save(MemberFixture.member4()); QuestionPost questionPost = questionPostRepository.save(QuestionPostFixture.questionPost(inquirer)); ChatInquiry chatInquiry = chatInquiryRepository.save( - ChatInquiryFixture.chatInquiry(questionPost, inquirer, loginMember, CHAT_MESSAGE)); + ChatInquiryFixture.chatInquiry(questionPost, inquirer, loginMember, INQUIRY_MESSAGE)); mockMvc.perform(patch("/api/chat/inquiries/{chatInquiryId}/reject", chatInquiry.getId()) .cookie(accessToken)) From a6371c5721949ff597fe3bf7b231c844c151cad4 Mon Sep 17 00:00:00 2001 From: hs12 Date: Sat, 16 Nov 2024 14:52:11 +0900 Subject: [PATCH 44/44] =?UTF-8?q?[fix]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20null=EC=9D=BC=20=EB=95=8C=20NPE?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gongmuin/chatroom/dto/ChatRoomMapper.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 ffb21152..7f7eb957 100644 --- a/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java +++ b/src/main/java/com/dnd/gongmuin/chatroom/dto/ChatRoomMapper.java @@ -51,6 +51,16 @@ public static ChatRoomSimpleResponse toChatRoomSimpleResponse( ChatRoomInfo chatRoomInfo, LatestChatMessage latestChatMessage ) { + String content = null; + String type = null; + String createdAt = null; + + if (latestChatMessage != null) { + content = latestChatMessage.content(); + type = latestChatMessage.type(); + createdAt = latestChatMessage.createdAt().toString(); + } + return new ChatRoomSimpleResponse( chatRoomInfo.chatRoomId(), new MemberInfo( @@ -59,9 +69,9 @@ public static ChatRoomSimpleResponse toChatRoomSimpleResponse( chatRoomInfo.partnerJobGroup(), chatRoomInfo.partnerProfileImageNo() ), - latestChatMessage.content(), - latestChatMessage.type(), - latestChatMessage.createdAt().toString() + content, + type, + createdAt ); } }