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();