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 9d5c43ba..81908064 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 @@ -9,11 +9,12 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import java.util.List; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/apply") @@ -30,19 +31,19 @@ public ApplicationResponse createApply(@AuthenticationPrincipal PrincipalD //팀 공고 요청 api @Operation(summary = "내가 모집 중인 팀 정보 API", description = "내가 모집 중인 팀 페이지에서 필요한 팀 정보 요청") @GetMapping("/{post_id}") - public ApplicationResponse getApply(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("post_id") Long postId){ + public ApplicationResponse getApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){ return ApplicationResponse.ok(applyService.findApply(principalDetails.getMember(),postId)); } //내가 모집 중인 팀 지원자 정보 요청 api @Operation(summary = "내가 모집 중인 팀 지원자 정보 API", description = "내가 모집 중인 팀 페이지에서 필요한 지원자 정보 요청") @GetMapping("/{post_id}/applylist") - public ApplicationResponse getApplyList(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("post_id") Long postId,@RequestParam(name = "page", defaultValue = "0") int page,@RequestParam(name = "size", defaultValue = "11") int size){ + public ApplicationResponse getApplyList(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestParam(name = "page", defaultValue = "0") int page, @RequestParam(name = "size", defaultValue = "11") int size){ return ApplicationResponse.ok(applyService.applyListPage(principalDetails.getMember(),postId,page,size)); } //내가 참여한 공고 정보 요청 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){ + 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)); } //지원서 열람 요청 api @@ -102,8 +103,8 @@ public ApplicationResponse updatePostPeriod(@AuthenticationPrincipal Princ @Operation(summary = "내가 지원한 팀 리스트 API", description = "현재 지원 중인 상태의 팀 정보 반환") @GetMapping("/my") - public ApplicationResponse> getMyApplyList(@AuthenticationPrincipal PrincipalDetails principalDetails) { - return ApplicationResponse.ok(applyService.getMyApplyList(principalDetails.getMember())); + public ApplicationResponse> getMyApplyList(@AuthenticationPrincipal PrincipalDetails principalDetails, @PageableDefault(size = 6) Pageable pageable) { + return ApplicationResponse.ok(applyService.getMyApplyList(principalDetails.getMember(), pageable)); } @Operation(summary = "지원서 열람 API", description = "해당 공고에 대한 사용자의 지원서 정보 반환") diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationList.java b/src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationList.java index edd215a9..634e48a4 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationList.java +++ b/src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationList.java @@ -8,6 +8,7 @@ @Builder public record ParticipationList( + Long postId, String title, String leaderName, LocalDateTime startDate, @@ -17,6 +18,7 @@ public record ParticipationList( ) { public static ParticipationList of(Post post) { return ParticipationList.builder() + .postId(post.getPostId()) .title(post.getTitle()) .leaderName(post.getMember().getName()) .startDate(post.getStartDate()) 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 40bf1299..69d3158b 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 @@ -23,7 +23,7 @@ public interface ApplyRepository extends JpaRepository { List findApplyByApplyTypeAndMemberAndIsCanceledFalse(ApplyType applyType, Member member); - List findAllByMemberAndDeletedAtIsNullOrderByCreatedAtDesc(Member member); + Page findAllByMemberAndDeletedAtIsNullOrderByCreatedAtDesc(Member member, Pageable pageable); Apply findApplyByMemberAndPost(Member member,Post post); 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 7b158016..0ade8a12 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 @@ -18,12 +18,8 @@ import com.gongjakso.server.domain.post.repository.StackNameRepository; import com.gongjakso.server.global.exception.ApplicationException; import com.gongjakso.server.global.exception.ErrorCode; -import com.gongjakso.server.global.util.email.EmailClient; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; +import org.springframework.data.domain.*; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -48,7 +44,7 @@ public class ApplyService { private final CategoryRepository categoryRepository; private final StackNameRepository stackNameRepository; private final ApplyStackRepository applyStackRepository; - private final EmailClient emailClient; +// private final EmailClient emailClient; @Transactional public void save(Member member, Long postId, ApplyReq req) { @@ -263,15 +259,12 @@ public void updatePostPeriod(Member member,Long postId, PeriodReq req) { } - public List getMyApplyList(Member member) { + public Page getMyApplyList(Member member, Pageable pageable) { // Validation // Business Logic - List applyList = applyRepository.findAllByMemberAndDeletedAtIsNullOrderByCreatedAtDesc(member); - - - // Response - return applyList.stream() + Page applyPage = applyRepository.findAllByMemberAndDeletedAtIsNullOrderByCreatedAtDesc(member, pageable); + List applyList = applyPage.stream() .filter(apply -> apply.getPost().getStatus() == PostStatus.RECRUITING || apply.getPost().getStatus() == PostStatus.EXTENSION || apply.getPost().getStatus() == PostStatus.CANCEL || @@ -284,7 +277,10 @@ public List getMyApplyList(Member member) { return MyPageRes.of(post, apply, categoryList); }) - .collect(Collectors.toList()); + .toList(); + + // Response + return new PageImpl<>(applyList, pageable, applyPage.getTotalElements()); } public ApplicationRes getMyApplication(Member member, Long postId){ diff --git a/src/main/java/com/gongjakso/server/domain/post/service/PostService.java b/src/main/java/com/gongjakso/server/domain/post/service/PostService.java index 7888ecb6..093a2f9f 100644 --- a/src/main/java/com/gongjakso/server/domain/post/service/PostService.java +++ b/src/main/java/com/gongjakso/server/domain/post/service/PostService.java @@ -315,9 +315,9 @@ public PostScrapRes scrapPost(Member member, Long postId) { post.setScrapCount(post.getScrapCount() + 1); } } - postScrapRepository.save(postScrap); - postRepository.save(post); - return PostScrapRes.of(postScrap, post.getScrapCount()); + PostScrap savePostScrap = postScrapRepository.save(postScrap); + Post savePost = postRepository.save(post); + return PostScrapRes.of(savePostScrap, savePost.getScrapCount()); } @Transactional @@ -379,7 +379,7 @@ public Page getMyScrapProject(Member member, Pageable page){ Page scrapPageList = postScrapRepository.findAllByMemberAndPostPostTypeTrueAndPostDeletedAtIsNullAndScrapStatusTrueOrderByPostScrapIdDesc(member, pageable); - List filteredProjects = scrapPageList.stream() + List myScrapProjects = scrapPageList.stream() .map(scrap -> { Post post = scrap.getPost(); post.getCategories().size(); @@ -389,7 +389,7 @@ public Page getMyScrapProject(Member member, Pageable page){ .collect(Collectors.toList()); // 리스트로 수집 // 필터링된 리스트를 페이지로 반환 - return new PageImpl<>(filteredProjects, pageable, scrapPageList.getTotalElements()); + return new PageImpl<>( myScrapProjects, pageable, myScrapProjects.size()); } @Transactional @@ -398,7 +398,7 @@ public Page getMyScrapContest(Member member, Pageable page){ Page scrapPageList = postScrapRepository.findAllByMemberAndPostPostTypeFalseAndPostDeletedAtIsNullAndScrapStatusTrueOrderByPostScrapIdDesc(member, pageable); - List filteredContests = scrapPageList.stream() + List myScrapContests = scrapPageList.stream() .map(scrap -> { Post post = scrap.getPost(); post.getCategories().size(); @@ -408,9 +408,10 @@ public Page getMyScrapContest(Member member, Pageable page){ .collect(Collectors.toList()); // 리스트로 수집 // 필터링된 리스트를 페이지로 반환 - return new PageImpl<>(filteredContests, pageable, scrapPageList.getTotalElements()); + return new PageImpl<>(myScrapContests, pageable, myScrapContests.size()); } + @Transactional public PostSimpleRes completePost(Member member, Long postId) { // Validation: Post 논리적 삭제 및 사용자의 권한 여부 확인