diff --git a/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java b/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java index 08d120b9..5b1ba9b4 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java +++ b/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java @@ -45,8 +45,8 @@ public ApplicationResponse getApplyList(@AuthenticationPrincipal P //내가 참여한 공고 정보 요청 api @Operation(summary = "내가 참여한 공고 정보 API", description = "내가 참여한 공고 정보") @GetMapping("/my-participation-post") - public ApplicationResponse getMyParticipationPostList(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestParam(name = "page", defaultValue = "0") int page, @RequestParam(name = "size", defaultValue = "6") int size){ - return ApplicationResponse.ok(applyService.myParticipationPostListPage(principalDetails.getMember(),page,size)); + public ApplicationResponse getMyParticipationPostList(@AuthenticationPrincipal PrincipalDetails principalDetails, @PageableDefault(size = 6) Pageable pageable){ + return ApplicationResponse.ok(applyService.myParticipationPostListPage(principalDetails.getMember(), pageable)); } //지원서 열람 요청 api @Operation(summary = "지원서 열람 API", description = "내가 모집 중인 팀 페이지에서 지원서 열람 시") diff --git a/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java b/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java index 44377c56..e13d6573 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java +++ b/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java @@ -30,7 +30,7 @@ public interface ApplyRepository extends JpaRepository { countQuery = "SELECT COUNT(DISTINCT a) FROM Apply a WHERE a.member = :member AND a.post.status IN :postStatus AND a.deletedAt IS NULL AND a.isCanceled = false") Page findAllByMemberAndPostStatusInAndDeletedAtIsNullAndIsCanceledFalseOrderByCreatedAtDesc(@Param("member") Member member, @Param("postStatus") List postStatusList, Pageable pageable); - Apply findApplyByMemberAndPost(Member member,Post post); + Optional findApplyByMemberAndPostAndDeletedAtIsNullAndIsCanceledFalse(Member member,Post post); - Optional findApplyByApplyIdAndDeletedAtIsNull(Long applyId); + Optional findApplyByApplyIdAndDeletedAtIsNullAndIsCanceledFalse(Long applyId); } diff --git a/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java b/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java index 9956e31b..b134fa70 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java +++ b/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java @@ -177,21 +177,15 @@ 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) { - Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending()); - List applyList = applyRepository.findApplyByApplyTypeAndMemberAndIsCanceledFalse(ApplyType.PASS,member); - List postIdList = applyList.stream() - .filter(apply -> apply.getPost().getStatus().equals(PostStatus.ACTIVE) || apply.getPost().getStatus().equals(PostStatus.COMPLETE)) - .map(Apply::getApplyId) - .toList(); - Page postPage = postRepository.findAllByPostIdInOrMemberAndDeletedAtIsNull(postIdList, member, pageable); + public ParticipationPageRes myParticipationPostListPage(Member member, Pageable page) { + Pageable pageable = PageRequest.of(page.getPageNumber(), page.getPageSize(), Sort.by("createdAt").descending()); + System.out.println(pageable.getOffset()); + List postStatusList = Arrays.asList(ACTIVE, COMPLETE); + Page postPage = postRepository.findPostsByMemberIdAndPostStatusInOrderByCreatedAtDesc(member.getMemberId(), postStatusList, pageable); List participationLists = postPage.getContent().stream() .map(ParticipationList::of) .collect(Collectors.toList()); - int pageNo = postPage.getNumber(); - int totalPages = postPage.getTotalPages(); - boolean last = postPage.isLast(); - return ParticipationPageRes.of(participationLists, pageNo, size, totalPages, last); + return ParticipationPageRes.of(participationLists, postPage.getNumber(), postPage.getSize(), postPage.getTotalPages(), postPage.isLast()); } private String decisionState(Apply apply) { @@ -281,39 +275,32 @@ public Page getMyApplyList(Member member, Pageable pageable) { } public ApplicationRes getMyApplication(Member member, Long postId){ - Post post = postRepository.findByPostId(postId); - if (post == null) { - throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION); - }else{ - Apply apply = applyRepository.findApplyByMemberAndPost(member, post); - if(apply == null){ - throw new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION); - }else { - //Change List Type - List categoryList = changeCategoryType(post); - List stackNameList; - List applyStackList = null; - if(post.isPostType()){ - stackNameList = changeStackNameType(post); - System.out.println("change stack name"); - List applyStacks = applyStackRepository.findAllByApply(apply); - applyStackList = new ArrayList<>(); - for(ApplyStack applyStack : applyStacks){ - applyStackList.add(applyStack.getStackName().getStackNameType()); - } - }else { - stackNameList= null; - } + Post post = postRepository.findByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - return ApplicationRes.of(apply, categoryList, stackNameList,applyStackList); + Apply apply = applyRepository.findApplyByMemberAndPostAndDeletedAtIsNullAndIsCanceledFalse(member, post).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION)); + + // Change List Type + List categoryList = changeCategoryType(post); + List stackNameList; + List applyStackList = null; + if(post.isPostType()){ + stackNameList = changeStackNameType(post); + List applyStacks = applyStackRepository.findAllByApply(apply); + applyStackList = new ArrayList<>(); + for(ApplyStack applyStack : applyStacks){ + applyStackList.add(applyStack.getStackName().getStackNameType()); } + }else { + stackNameList= null; } + + return ApplicationRes.of(apply, categoryList, stackNameList, applyStackList); } @Transactional public PatchApplyRes cancelApply(Member member, Long applyId) { // Validation: 논리적 삭제 데이터이거나 신청자 본인이 아닌 경우에 대한 유효성 검증 + 공고의 모집 기한 확인 - Apply apply = applyRepository.findApplyByApplyIdAndDeletedAtIsNull(applyId).orElseThrow(() -> new ApplicationException(ErrorCode.ALREADY_DELETE_EXCEPTION)); + Apply apply = applyRepository.findApplyByApplyIdAndDeletedAtIsNullAndIsCanceledFalse(applyId).orElseThrow(() -> new ApplicationException(ErrorCode.ALREADY_DELETE_EXCEPTION)); if (!apply.getMember().getMemberId().equals(member.getMemberId())) { throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); } diff --git a/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java b/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java index 5bc801f9..730b5861 100644 --- a/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java +++ b/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.time.LocalDateTime; @@ -13,7 +14,7 @@ import java.util.Optional; public interface PostRepository extends JpaRepository { - Post findByPostId(Long postId); + Optional findByPostId(Long postId); Optional findWithStackNameAndCategoryUsingFetchJoinByPostId(Long postId); @@ -132,5 +133,26 @@ public interface PostRepository extends JpaRepository { List findAllByMemberAndStatusInAndDeletedAtIsNullOrderByCreatedAtDesc(Member member, List statusList); - Page findAllByPostIdInOrMemberAndDeletedAtIsNull(List postIdList, Member member, Pageable pageable); + @Query(value = "SELECT DISTINCT p " + + "FROM Post p " + + "LEFT JOIN FETCH p.member m " + + "LEFT JOIN FETCH p.categories c " + + "LEFT JOIN Apply a ON p.postId = a.post.postId " + + "WHERE ((a.member.memberId = :memberId " + + "AND a.deletedAt IS NULL " + + "AND a.isCanceled = false " + + "AND a.applyType = 'PASS') OR (p.member.memberId = :memberId)) " + + "AND p.deletedAt IS NULL " + + "AND p.status IN :postStatus " + + "ORDER BY p.createdAt DESC", + countQuery = "SELECT COUNT(DISTINCT p) " + + "FROM Post p " + + "LEFT JOIN Apply a ON p.postId = a.post.postId " + + "WHERE ((a.member.memberId = :memberId " + + "AND a.deletedAt IS NULL " + + "AND a.isCanceled = false " + + "AND a.applyType = 'PASS') OR (p.member.memberId = :memberId)) " + + "AND p.deletedAt IS NULL " + + "AND p.status IN :postStatus") + Page findPostsByMemberIdAndPostStatusInOrderByCreatedAtDesc(@Param("memberId") Long memberId, @Param("postStatus") List postStatusList, Pageable pageable); }