Skip to content

Commit

Permalink
MATE-121 : [FEAT] 메이트 상세조회 api에 현재 채팅방 인원값 추가 (#111)
Browse files Browse the repository at this point in the history
* MATE-121 : [FEAT] 메이트 상세조회 api에 현재 채팅방 인원값 추가

* MATE-121 : [FEAT] 메이트 상세조회 컨트롤러 테스트에 의존성 추가
  • Loading branch information
MisaSohee authored Dec 8, 2024
1 parent cc0136a commit e28d07d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public class MatePostDetailResponse {
private Long postId;
private Long matchId;
private Long authorId;
private Integer currentChatMembers;

public static MatePostDetailResponse from(MatePost post) {
public static MatePostDetailResponse from(MatePost post, Integer currentChatMembers) {
String myTeamName = TeamInfo.getById(post.getTeamId()).shortName;
String rivalTeamName = getRivalTeamName(post);

Expand All @@ -57,6 +58,7 @@ public static MatePostDetailResponse from(MatePost post) {
.postId(post.getId())
.matchId(post.getMatch().getId())
.authorId(post.getAuthor().getId())
.currentChatMembers(currentChatMembers)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.example.mate.domain.mate.entity.Visit;
import com.example.mate.domain.mate.repository.MateRepository;
import com.example.mate.domain.mate.repository.MateReviewRepository;
import com.example.mate.domain.mateChat.repository.MateChatRoomMemberRepository;
import com.example.mate.domain.mateChat.repository.MateChatRoomRepository;
import com.example.mate.domain.member.entity.Member;
import com.example.mate.domain.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -39,6 +41,8 @@ public class MateService {
private final MatchRepository matchRepository;
private final MemberRepository memberRepository;
private final MateReviewRepository mateReviewRepository;
private final MateChatRoomRepository mateChatRoomRepository;
private final MateChatRoomMemberRepository mateChatRoomMemberRepository;
private final FileService fileService;

public MatePostResponse createMatePost(MatePostCreateRequest request, MultipartFile file, Long memberId) {
Expand Down Expand Up @@ -115,7 +119,15 @@ public PageResponse<MatePostSummaryResponse> getMatePagePosts(MatePostSearchRequ
public MatePostDetailResponse getMatePostDetail(Long postId) {
MatePost matePost = findMatePostById(postId);

return MatePostDetailResponse.from(matePost);
Integer currentChatMembers = getCurrentChatMembers(postId);

return MatePostDetailResponse.from(matePost, currentChatMembers);
}

private Integer getCurrentChatMembers(Long postId) {
return mateChatRoomRepository.findByMatePostId(postId)
.map(chatRoom -> mateChatRoomMemberRepository.countByChatRoomIdAndIsActiveTrue(chatRoom.getId()))
.orElse(0);
}

public MatePostResponse updateMatePost(Long memberId, Long postId, MatePostUpdateRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.example.mate.domain.mate.dto.response.MatePostSummaryResponse;
import com.example.mate.domain.mate.entity.*;
import com.example.mate.domain.mate.repository.MateRepository;
import com.example.mate.domain.mateChat.repository.MateChatRoomMemberRepository;
import com.example.mate.domain.mateChat.repository.MateChatRoomRepository;
import com.example.mate.domain.member.entity.Member;
import com.example.mate.domain.member.repository.MemberRepository;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -61,6 +63,12 @@ class MateServiceTest {
@Mock
private FileService fileService;

@Mock
private MateChatRoomRepository chatRoomRepository;

@Mock
private MateChatRoomMemberRepository chatRoomMemberRepository;

private static final Long TEST_MEMBER_ID = 1L;
private static final Long TEST_MATCH_ID = 1L;

Expand Down

0 comments on commit e28d07d

Please sign in to comment.