From e28d07d48d18432291cbd400dc901505aff92071 Mon Sep 17 00:00:00 2001 From: sohee <144431880+MisaSohee@users.noreply.github.com> Date: Mon, 9 Dec 2024 00:13:58 +0900 Subject: [PATCH] =?UTF-8?q?MATE-121=20:=20[FEAT]=20=EB=A9=94=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=83=81=EC=84=B8=EC=A1=B0=ED=9A=8C=20api=EC=97=90?= =?UTF-8?q?=20=ED=98=84=EC=9E=AC=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=9D=B8?= =?UTF-8?q?=EC=9B=90=EA=B0=92=20=EC=B6=94=EA=B0=80=20(#111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MATE-121 : [FEAT] 메이트 상세조회 api에 현재 채팅방 인원값 추가 * MATE-121 : [FEAT] 메이트 상세조회 컨트롤러 테스트에 의존성 추가 --- .../mate/dto/response/MatePostDetailResponse.java | 4 +++- .../mate/domain/mate/service/MateService.java | 14 +++++++++++++- .../mate/domain/mate/service/MateServiceTest.java | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/mate/domain/mate/dto/response/MatePostDetailResponse.java b/src/main/java/com/example/mate/domain/mate/dto/response/MatePostDetailResponse.java index b6e8d792..36887881 100644 --- a/src/main/java/com/example/mate/domain/mate/dto/response/MatePostDetailResponse.java +++ b/src/main/java/com/example/mate/domain/mate/dto/response/MatePostDetailResponse.java @@ -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); @@ -57,6 +58,7 @@ public static MatePostDetailResponse from(MatePost post) { .postId(post.getId()) .matchId(post.getMatch().getId()) .authorId(post.getAuthor().getId()) + .currentChatMembers(currentChatMembers) .build(); } diff --git a/src/main/java/com/example/mate/domain/mate/service/MateService.java b/src/main/java/com/example/mate/domain/mate/service/MateService.java index 95b6caa3..b97e9465 100644 --- a/src/main/java/com/example/mate/domain/mate/service/MateService.java +++ b/src/main/java/com/example/mate/domain/mate/service/MateService.java @@ -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; @@ -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) { @@ -115,7 +119,15 @@ public PageResponse 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, diff --git a/src/test/java/com/example/mate/domain/mate/service/MateServiceTest.java b/src/test/java/com/example/mate/domain/mate/service/MateServiceTest.java index 8eb5c642..6e49ed71 100644 --- a/src/test/java/com/example/mate/domain/mate/service/MateServiceTest.java +++ b/src/test/java/com/example/mate/domain/mate/service/MateServiceTest.java @@ -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; @@ -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;