Skip to content

Commit

Permalink
[FEAT] 매칭 상태에 따라 게시글 상태 결정 (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
injae-348 authored Jul 24, 2024
1 parent 7dd4fbc commit 29236cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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<Matching, Long> {

List<Matching> findByPostId(Long postId);
}
26 changes: 21 additions & 5 deletions src/main/java/econo/buddybridge/post/service/PostService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -103,6 +104,9 @@ public void deletePost(Long postId, Long memberId){

// Post를 사용하여 PostResDto 생성
public PostResDto postToPostRes(Post post) {
List<Matching> matchingList = matchingRepository.findByPostId(post.getId());
PostStatus postStatus = determinePostStatus(matchingList);

return PostResDto.builder()
.id(post.getId())
.author(toMemberResDto(post.getAuthor()))
Expand All @@ -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<Matching> 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();
Expand Down

0 comments on commit 29236cc

Please sign in to comment.