From 29236cc47018c1441301349d48f4b8ca84d48fa9 Mon Sep 17 00:00:00 2001 From: JeongInJae <93825184+injae-348@users.noreply.github.com> Date: Wed, 24 Jul 2024 21:44:26 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EB=A7=A4=EC=B9=AD=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EC=83=81=ED=83=9C=20=EA=B2=B0=EC=A0=95=20(#97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MatchingRepository.java | 8 ++---- .../buddybridge/post/service/PostService.java | 26 +++++++++++++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/econo/buddybridge/matching/repository/MatchingRepository.java b/src/main/java/econo/buddybridge/matching/repository/MatchingRepository.java index 987dae3..7cea379 100644 --- a/src/main/java/econo/buddybridge/matching/repository/MatchingRepository.java +++ b/src/main/java/econo/buddybridge/matching/repository/MatchingRepository.java @@ -1,14 +1,10 @@ package econo.buddybridge.matching.repository; import econo.buddybridge.matching.entity.Matching; -import feign.Param; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import java.time.LocalDateTime; +import java.util.List; public interface MatchingRepository extends JpaRepository { - + List findByPostId(Long postId); } diff --git a/src/main/java/econo/buddybridge/post/service/PostService.java b/src/main/java/econo/buddybridge/post/service/PostService.java index 4e12ba0..bd5ea10 100644 --- a/src/main/java/econo/buddybridge/post/service/PostService.java +++ b/src/main/java/econo/buddybridge/post/service/PostService.java @@ -1,15 +1,15 @@ package econo.buddybridge.post.service; +import econo.buddybridge.matching.entity.Matching; +import econo.buddybridge.matching.entity.MatchingStatus; +import econo.buddybridge.matching.repository.MatchingRepository; import econo.buddybridge.member.dto.MemberResDto; import econo.buddybridge.member.entity.Member; import econo.buddybridge.member.repository.MemberRepository; import econo.buddybridge.post.dto.PostCustomPage; import econo.buddybridge.post.dto.PostReqDto; import econo.buddybridge.post.dto.PostResDto; -import econo.buddybridge.post.entity.Post; -import econo.buddybridge.post.entity.PostType; -import econo.buddybridge.post.entity.Schedule; -import econo.buddybridge.post.entity.ScheduleType; +import econo.buddybridge.post.entity.*; import econo.buddybridge.post.repository.PostRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -30,6 +30,7 @@ public class PostService { private final PostRepository postRepository; private final MemberRepository memberRepository; + private final MatchingRepository matchingRepository; @Transactional(readOnly = true) // 단일 게시글 public PostResDto findPost(Long postId) { @@ -103,6 +104,9 @@ public void deletePost(Long postId, Long memberId){ // Post를 사용하여 PostResDto 생성 public PostResDto postToPostRes(Post post) { + List matchingList = matchingRepository.findByPostId(post.getId()); + PostStatus postStatus = determinePostStatus(matchingList); + return PostResDto.builder() .id(post.getId()) .author(toMemberResDto(post.getAuthor())) @@ -117,11 +121,23 @@ public PostResDto postToPostRes(Post post) { .postType(post.getPostType()) .createdAt(post.getCreatedAt()) .modifiedAt(post.getModifiedAt()) - .postStatus(post.getPostStatus()) + .postStatus(postStatus) .disabilityType(post.getDisabilityType()) .build(); } + // 매칭 상태에 따라 게시글 상태 결정 + public PostStatus determinePostStatus(List matchingList) { + if (matchingList.isEmpty()) { + return PostStatus.RECRUITING; // 모집중 + } + + boolean isCompleted = matchingList.stream() + .anyMatch(matching -> matching.getMatchingStatus() == MatchingStatus.DONE); + + return isCompleted ? PostStatus.FINISHED : PostStatus.RECRUITING; + } + // PostReqDto를 바탕으로 Post생성 public Post postReqToPost(PostReqDto postReqDto, Member member) { LocalDateTime startTime = postReqDto.startTime();