Skip to content

Commit

Permalink
[refactor #156] 채팅 요청 목록 API에서 채팅 파트너 조회 로직 리팩토링 (#157)
Browse files Browse the repository at this point in the history
* [feat] : 채팅 요청에 createdAt 필드 추가

* [feat] : 채팅 요청 테스트 픽스쳐에 createdAt 추가

* [feat] : 채팅 파트너 구하는 로직 DTO에 추가

* [refactor] : 채팅 파트너 구하는 로직 DTO로 이동

* [style] : 코드 리포멧팅

* [test] : createdAt 포함된 testFixture 사용
  • Loading branch information
hyun2371 authored Nov 23, 2024
1 parent e08aedf commit e145d22
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dnd.gongmuin.chat_inquiry.dto;

import com.dnd.gongmuin.chat_inquiry.domain.InquiryStatus;
import com.dnd.gongmuin.member.domain.JobGroup;
import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry;
import com.dnd.gongmuin.member.domain.Member;
import com.dnd.gongmuin.question_post.dto.response.MemberInfo;
import com.querydsl.core.annotations.QueryProjection;

Expand All @@ -10,30 +10,31 @@ public record ChatInquiryResponse(
String inquiryMessage,
String inquiryStatus,
boolean isInquirer,
MemberInfo chatPartner
MemberInfo chatPartner,
String createdAt
) {
@QueryProjection
public ChatInquiryResponse(
Long chatInquiryId,
String inquiryMessage,
InquiryStatus inquiryStatus,
boolean isInquirer,
Long partnerId,
String partnerNickname,
JobGroup partnerJobGroup,
int partnerProfileImageNo
ChatInquiry chatInquiry,
boolean isInquirer
) {
this(
chatInquiryId,
inquiryMessage,
inquiryStatus.getLabel(),
chatInquiry.getId(),
chatInquiry.getMessage(),
chatInquiry.getStatus().getLabel(),
isInquirer,
new MemberInfo(
partnerId,
partnerNickname,
partnerJobGroup.getLabel(),
partnerProfileImageNo
)
createPartnerInfo(isInquirer, chatInquiry),
chatInquiry.getCreatedAt().toString()
);
}

private static MemberInfo createPartnerInfo(boolean isInquirer, ChatInquiry chatInquiry) {
Member partner = isInquirer ? chatInquiry.getAnswerer() : chatInquiry.getInquirer();
return new MemberInfo(
partner.getId(),
partner.getNickname(),
partner.getJobGroup().getLabel(),
partner.getProfileImageNo()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,11 @@ public class ChatInquiryQueryRepositoryImpl implements ChatInquiryQueryRepositor
public Slice<ChatInquiryResponse> getChatInquiresByMember(Member member, Pageable pageable) {
List<ChatInquiryResponse> content = queryFactory
.select(new QChatInquiryResponse(
chatInquiry.id,
chatInquiry.message,
chatInquiry.status,
chatInquiry,
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)
.otherwise(false)
))
.from(chatInquiry)
.where(chatInquiry.inquirer.id.eq(member.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ void getChatInquiresByMember() {
Long chatInquiryId = 1L;
Member targetMember = MemberFixture.member(1L);
Member partner = MemberFixture.member(2L);
ChatInquiryResponse chatInquiryResponse = new ChatInquiryResponse(
chatInquiryId, INQUIRY_MESSAGE, InquiryStatus.PENDING, true, partner.getId(),
partner.getNickname(), partner.getJobGroup(), partner.getProfileImageNo()
ChatInquiry chatInquiry = ChatInquiryFixture.chatInquiry(
1L, QuestionPostFixture.questionPost(targetMember), targetMember, partner, INQUIRY_MESSAGE
);
ChatInquiryResponse chatInquiryResponse = new ChatInquiryResponse(chatInquiry, true);
given(chatInquiryRepository.getChatInquiresByMember(targetMember, pageRequest))
.willReturn(new SliceImpl<>(List.of(chatInquiryResponse), pageRequest, false));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dnd.gongmuin.common.fixture;

import java.time.LocalDateTime;

import org.springframework.test.util.ReflectionTestUtils;

import com.dnd.gongmuin.chat_inquiry.domain.ChatInquiry;
Expand Down Expand Up @@ -40,6 +42,7 @@ public static ChatInquiry chatInquiry(
message
);
ReflectionTestUtils.setField(chatInquiry, "id", id);
ReflectionTestUtils.setField(chatInquiry, "createdAt", LocalDateTime.now());
return chatInquiry;
}
}

0 comments on commit e145d22

Please sign in to comment.