Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor #156] 채팅 요청 목록 API에서 채팅 파트너 조회 로직 리팩토링 #157

Merged
merged 6 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 chatInquiry만 필요하도록 바꿔서, CaseBuilder()를 확 줄였네요!

))
.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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 수정👍

return chatInquiry;
}
}
Loading