Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 내가 참여한 팀 조회 API 비즈니스 로직 수정 #153

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading