Skip to content

Commit

Permalink
[#128] fix: 내가 참여한 팀 조회 API 비즈니스 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dl-00-e8 committed May 19, 2024
1 parent e4721cb commit 5d3a19a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.gongjakso.server.domain.apply.dto;

import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.enumerate.CategoryType;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import lombok.Builder;

import java.time.LocalDateTime;

@Builder
public record ParticipationList(
String title,
CategoryType recruit_part,
String leaderName,
LocalDateTime startDate,
LocalDateTime finishDate,
PostStatus postStatus,
Boolean postType
) {
public static ParticipationList of(Post post,CategoryType recruit_part) {
return new ParticipationList(post.getTitle(), recruit_part,post.getMember().getName(),post.getStartDate(),post.getFinishDate(),post.getStatus(), post.isPostType());
public static ParticipationList of(Post post) {
return ParticipationList.builder()
.title(post.getTitle())
.leaderName(post.getMember().getName())
.startDate(post.getStartDate())
.finishDate(post.getFinishDate())
.postStatus(post.getStatus())
.postType(post.isPostType())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface ApplyRepository extends JpaRepository<Apply,Long> {

Page<Apply> findAllByPost(Post post, Pageable pageable);

Page<Apply> findApplyByApplyTypeAndMemberAndIsCanceledFalse(ApplyType applyType, Member member, Pageable pageable);
List<Apply> findApplyByApplyTypeAndMemberAndIsCanceledFalse(ApplyType applyType, Member member);

List<Apply> findAllByMemberAndDeletedAtIsNullOrderByCreatedAtDesc(Member member);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,21 @@ public ApplyPageRes applyListPage(Member member, long postId, int page, int size
return ApplyPageRes.of(applyLists, pageNo, size, totalPages, last);
}

public ParticipationPageRes myParticipationPostListPage(Member member,int page, int size) {
public ParticipationPageRes myParticipationPostListPage(Member member, int page, int size) {
Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending());
Page<Apply> participationPage = applyRepository.findApplyByApplyTypeAndMemberAndIsCanceledFalse(ApplyType.PASS,member,pageable);
List<ParticipationList> participationLists = participationPage.getContent().stream()
List<Apply> applyList = applyRepository.findApplyByApplyTypeAndMemberAndIsCanceledFalse(ApplyType.PASS,member);
List<Long> postIdList = applyList.stream()
.filter(apply -> apply.getPost().getStatus().equals(PostStatus.ACTIVE) || apply.getPost().getStatus().equals(PostStatus.COMPLETE))
.map(apply -> ParticipationList.of(apply.getPost(), CategoryType.valueOf(apply.getRecruit_part())))
.map(Apply::getApplyId)
.toList();
Page<Post> postPage = postRepository.findAllByPostIdInOrMember(postIdList, member, pageable);
List<ParticipationList> participationLists = postPage.getContent().stream()
.filter(post -> post.getDeletedAt() == null)
.map(ParticipationList::of)
.collect(Collectors.toList());
int pageNo = participationPage.getNumber();
int totalPages = participationPage.getTotalPages();
boolean last = participationPage.isLast();
int pageNo = postPage.getNumber();
int totalPages = postPage.getTotalPages();
boolean last = postPage.isLast();
return ParticipationPageRes.of(participationLists, pageNo, size, totalPages, last);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
(@Param("searchWord") String searchWord, @Param("currentTimestamp") LocalDateTime currentTimestamp, @Param("status") PostStatus status, @Param("meetingCity") String meetingCity, @Param("meetingTown") String meetingTown, @Param("stackNameType") String stackNameType,Pageable pageable);

List<Post> findAllByMemberAndStatusAndDeletedAtIsNullOrderByCreatedAtDesc(Member member, PostStatus status);

Page<Post> findAllByPostIdInOrMember(List<Long> postIdList, Member member, Pageable pageable);
}

0 comments on commit 5d3a19a

Please sign in to comment.