From 92c8352528c388c2326b8d21e4cbd7ff7b8bd622 Mon Sep 17 00:00:00 2001 From: dl-00-e8 Date: Thu, 15 Aug 2024 12:53:21 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[#173]=20refactor:=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20API=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apply/controller/ApplyController.java | 121 ----- .../domain/apply/dto/ApplicationRes.java | 42 -- .../server/domain/apply/dto/ApplyList.java | 21 - .../server/domain/apply/dto/ApplyPageRes.java | 16 - .../server/domain/apply/dto/ApplyReq.java | 36 -- .../server/domain/apply/dto/ApplyRes.java | 22 - .../server/domain/apply/dto/CategoryRes.java | 15 - .../server/domain/apply/dto/MyPageRes.java | 50 -- .../domain/apply/dto/ParticipationList.java | 30 -- .../apply/dto/ParticipationPageRes.java | 15 - .../domain/apply/dto/PatchApplyRes.java | 36 -- .../server/domain/apply/dto/PeriodReq.java | 8 - .../server/domain/apply/entity/Apply.java | 59 --- .../domain/apply/entity/ApplyStack.java | 32 -- .../domain/apply/enumerate/ApplyType.java | 5 - .../domain/apply/enumerate/PostType.java | 5 - .../domain/apply/enumerate/StackType.java | 0 .../apply/repository/ApplyRepository.java | 36 -- .../repository/ApplyStackRepository.java | 11 - .../domain/apply/service/ApplyService.java | 319 ------------ .../post/controller/CalendarController.java | 24 - .../post/controller/PostController.java | 113 ----- .../server/domain/post/dto/CalendarRes.java | 11 - .../server/domain/post/dto/CategoryReq.java | 16 - .../server/domain/post/dto/CategoryRes.java | 14 - .../server/domain/post/dto/GetContestRes.java | 99 ---- .../domain/post/dto/GetPostRelation.java | 14 - .../server/domain/post/dto/GetProjectRes.java | 109 ---- .../server/domain/post/dto/MyPageRes.java | 46 -- .../server/domain/post/dto/PostDeleteRes.java | 28 -- .../server/domain/post/dto/PostDetailRes.java | 180 ------- .../server/domain/post/dto/PostModifyReq.java | 96 ---- .../server/domain/post/dto/PostReq.java | 107 ---- .../server/domain/post/dto/PostRes.java | 154 ------ .../server/domain/post/dto/PostScrapRes.java | 40 -- .../server/domain/post/dto/PostSimpleRes.java | 28 -- .../server/domain/post/dto/ScrapPost.java | 32 -- .../server/domain/post/dto/StackNameReq.java | 11 - .../server/domain/post/dto/StackNameRes.java | 12 - .../server/domain/post/entity/Category.java | 38 -- .../server/domain/post/entity/Post.java | 175 ------- .../server/domain/post/entity/PostScrap.java | 45 -- .../server/domain/post/entity/StackName.java | 33 -- .../domain/post/enumerate/CategoryType.java | 19 - .../domain/post/enumerate/MeetingMethod.java | 5 - .../domain/post/enumerate/PostStatus.java | 18 - .../domain/post/enumerate/StackNameType.java | 31 -- .../post/projection/ContestProjection.java | 34 -- .../post/projection/ProjectProjection.java | 38 -- .../post/repository/CategoryRepository.java | 13 - .../post/repository/PostRepository.java | 261 ---------- .../post/repository/PostScrapRepository.java | 20 - .../post/repository/StackNameRepository.java | 12 - .../domain/post/service/CalendarService.java | 43 -- .../domain/post/service/PostService.java | 473 ------------------ 55 files changed, 3271 deletions(-) delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/ApplicationRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/ApplyList.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/ApplyPageRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/ApplyReq.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/ApplyRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/CategoryRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/MyPageRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationList.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationPageRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/PatchApplyRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/dto/PeriodReq.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/entity/Apply.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/entity/ApplyStack.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/enumerate/ApplyType.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/enumerate/PostType.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/enumerate/StackType.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/repository/ApplyStackRepository.java delete mode 100644 src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/controller/CalendarController.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/controller/PostController.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/CalendarRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/CategoryReq.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/CategoryRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/GetContestRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/GetPostRelation.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/GetProjectRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/MyPageRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/PostDetailRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/PostModifyReq.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/PostScrapRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/PostSimpleRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/ScrapPost.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/StackNameReq.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/dto/StackNameRes.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/entity/Category.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/entity/Post.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/entity/PostScrap.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/entity/StackName.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/enumerate/CategoryType.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/enumerate/MeetingMethod.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/enumerate/PostStatus.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/enumerate/StackNameType.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/projection/ContestProjection.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/projection/ProjectProjection.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/repository/CategoryRepository.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/repository/PostScrapRepository.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/repository/StackNameRepository.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/service/CalendarService.java delete mode 100644 src/main/java/com/gongjakso/server/domain/post/service/PostService.java 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 deleted file mode 100644 index 3127eb39..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.gongjakso.server.domain.apply.controller; - -import com.gongjakso.server.domain.apply.dto.*; -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import com.gongjakso.server.domain.apply.service.ApplyService; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import com.gongjakso.server.global.common.ApplicationResponse; -import com.gongjakso.server.global.security.PrincipalDetails; -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.*; - -@RequiredArgsConstructor -@RestController -@RequestMapping("/api/v1/apply") -@Tag(name = "Apply", description = "팀 빌딩 관련 API") -public class ApplyController { - private final ApplyService applyService; - //지원 요청 api - @Operation(summary = "공고 지원 API", description = "팀 지원하기 모달창에서 지원 요청") - @PostMapping("/{post_id}") - public ApplicationResponse createApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestBody ApplyReq req){ - applyService.save(principalDetails.getMember(),postId,req); - return ApplicationResponse.created(); - } - //팀 공고 요청 api - @Operation(summary = "내가 모집 중인 팀 정보 API", description = "내가 모집 중인 팀 페이지에서 필요한 팀 정보 요청") - @GetMapping("/{post_id}") - 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){ - 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, @PageableDefault(size = 6) Pageable pageable){ - return ApplicationResponse.ok(applyService.myParticipationPostListPage(principalDetails.getMember(), pageable)); - } - //지원서 열람 요청 api - @Operation(summary = "지원서 열람 API", description = "내가 모집 중인 팀 페이지에서 지원서 열람 시") - @PatchMapping("/{apply_id}/open") - public ApplicationResponse updateIsOpenStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){ - applyService.updateState(principalDetails.getMember(),applyId, ApplyType.OPEN_APPLY); - return ApplicationResponse.ok(); - } - //지원서 지원 요청 api - @Operation(summary = "합류하기 API", description = "합류하기 버튼 클릭 시") - @PatchMapping("/{apply_id}/recruit") - public ApplicationResponse updateIsRecruitStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){ - applyService.updateState(principalDetails.getMember(),applyId,ApplyType.PASS); - return ApplicationResponse.ok(); - } - //지원서 미선발 요청 api - @Operation(summary = "미선발 API", description = "미선발 버튼 클릭 시") - @PatchMapping("/{apply_id}/not-recruit") - public ApplicationResponse updateNotRecruitStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){ - applyService.updateState(principalDetails.getMember(),applyId,ApplyType.NOT_PASS); - return ApplicationResponse.ok(); - } - // 특정 지원자 지원서 가져오는 api - @Operation(summary = "지원서 API", description = "내가 모집 중인 팀 페이지에서 지원자 지원서 요청") - @GetMapping("/{post_id}/{apply_id}/application") - public ApplicationResponse findApplication(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId,@PathVariable("post_id") Long postId){ - return ApplicationResponse.ok(applyService.findApplication(principalDetails.getMember(),applyId,postId)); - } - //공고 카테고리 요청 api - @Operation(summary = "지원시 뜨는 공고 정보 API", description = "팀 지원하기 모달 창에서 카테고리들(지원 분야) 요청") - @GetMapping("/{post_id}/category") - public ApplicationResponse getCategory(@PathVariable("post_id") Long postId){ - return ApplicationResponse.ok(applyService.findPostCategory(postId)); - } - //공고 마감 요청 api - @Operation(summary = "공고 마감 API", description = "내가 모집 중인 팀 페이지에서 공고 마감 버튼 클릭시") - @PatchMapping("/{post_id}/close") - public ApplicationResponse updatePostStatusToClose(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){ - applyService.updatePostState(principalDetails.getMember(),postId, PostStatus.ACTIVE); - return ApplicationResponse.ok(); - } - //공고 취소 요청 api - @Operation(summary = "공고 취소 API", description = "내가 모집 중인 팀 페이지에서 공고 취소 버튼 클릭시") - @PatchMapping("/{post_id}/cancel") - public ApplicationResponse updatePostStatusToCancel(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){ - applyService.updatePostState(principalDetails.getMember(),postId, PostStatus.CLOSE); - return ApplicationResponse.ok(); - } - //공고 기간 연장 요청 api - @Operation(summary = "공고 연장 API", description = "내가 모집 중인 팀 페이지에서 공고 연장 버튼 클릭시") - @PatchMapping("/{post_id}/extension") - public ApplicationResponse updatePostPeriod(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestBody PeriodReq req){ - applyService.updatePostPeriod(principalDetails.getMember(),postId,req); - return ApplicationResponse.ok(); - } - - @Operation(summary = "내가 지원한 팀 리스트 API", description = "현재 지원 중인 상태의 팀 정보 반환") - @GetMapping("/my") - public ApplicationResponse> getMyApplyList(@AuthenticationPrincipal PrincipalDetails principalDetails, @PageableDefault(size = 6) Pageable pageable) { - return ApplicationResponse.ok(applyService.getMyApplyList(principalDetails.getMember(), pageable)); - } - - @Operation(summary = "지원서 열람 API", description = "해당 공고에 대한 사용자의 지원서 정보 반환") - @GetMapping("/my/{post_id}") - public ApplicationResponse getMyApplication(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){ - return ApplicationResponse.ok(applyService.getMyApplication(principalDetails.getMember(), postId)); - } - - @Operation(summary = "지원 취소 API", description = "해당 공고에 대한 지원을 취소한다.") - @PatchMapping("/cancel/{apply_id}") - public ApplicationResponse cancelApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("apply_id") Long applyId){ - return ApplicationResponse.ok(applyService.cancelApply(principalDetails.getMember(), applyId)); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplicationRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/ApplicationRes.java deleted file mode 100644 index 473f34b3..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplicationRes.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.gongjakso.server.domain.apply.entity.Apply; -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import jakarta.validation.constraints.Null; -import lombok.Builder; - -import java.util.List; - -@Builder -public record ApplicationRes( - Long applyId, - ApplyType applyType, - String memberName, - String major, - String phone, - String application, - String recruitPart, - List category, - @JsonInclude(JsonInclude.Include.NON_NULL) - List postStack, - @Null - @JsonInclude(JsonInclude.Include.NON_NULL) - List applyStack - -) { - public static ApplicationRes of(Apply apply, List category, List stackName, List applyStack) { - return ApplicationRes.builder() - .applyId(apply.getApplyId()) - .applyType(apply.getApplyType()) - .memberName(apply.getMember().getName()) - .major(apply.getMember().getMajor()) - .phone(apply.getMember().getPhone()) - .application(apply.getApplication()) - .recruitPart(apply.getRecruit_part()) - .category(category) - .postStack(stackName) - .applyStack(applyStack) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyList.java b/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyList.java deleted file mode 100644 index b2cff608..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyList.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import com.gongjakso.server.domain.apply.entity.Apply; -import lombok.Builder; - -@Builder -public record ApplyList( - Long apply_id, - String name, - String state, - Boolean is_canceled -) { - public static ApplyList of(Apply apply,String state){ - return ApplyList.builder() - .apply_id(apply.getApplyId()) - .name(apply.getMember().getName()) - .state(state) - .is_canceled(apply.getIsCanceled()) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyPageRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyPageRes.java deleted file mode 100644 index 84174e67..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyPageRes.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import java.util.List; - -public record ApplyPageRes( - List applyLists, - int pageNo, - int pageSize, - int totalPages, - boolean last -) { - - public static ApplyPageRes of(List applyLists, int pageNo, int pageSize, int totalPages,boolean last) { - return new ApplyPageRes(applyLists, pageNo, pageSize, totalPages, last); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyReq.java b/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyReq.java deleted file mode 100644 index 2813b898..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyReq.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.gongjakso.server.domain.apply.entity.Apply; -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import com.gongjakso.server.domain.apply.enumerate.PostType; -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.entity.Post; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Null; -import jakarta.validation.constraints.Size; - -import java.util.List; - -@JsonInclude(JsonInclude.Include.NON_NULL) -public record ApplyReq( - @Size(max = 500,message = "지원서 최대 글자 수 500을 넘었습니다.") - String application, - @NotNull(message = "지원 파트를 정해야합니다.") - String recruit_part, - String type, - String applyType, - @Null - List stack -) { - public Apply toEntity(Member member, Post post) { - return Apply.builder() - .member(member) - .post(post) - .application(application) - .recruit_part(recruit_part) - .type(PostType.valueOf(type)) - .applyType(ApplyType.NONE) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyRes.java deleted file mode 100644 index cbafd05b..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/ApplyRes.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.gongjakso.server.domain.post.entity.Post; - -import java.time.LocalDateTime; -import java.util.List; -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public record ApplyRes( - String title, - LocalDateTime startDate, - LocalDateTime endDate, - Long total_person, - int current_person, - Long max_person, - Boolean postType, - List category -) { - public static ApplyRes of(Post post, int current_person, List category){ - return new ApplyRes(post.getTitle(),post.getStartDate(),post.getEndDate(),(post.getMaxPerson()+1),current_person,post.getMaxPerson(),post.isPostType(), category); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/CategoryRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/CategoryRes.java deleted file mode 100644 index c51b3d9d..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/CategoryRes.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; - -import java.util.List; -public record CategoryRes( - List category, - @JsonInclude(JsonInclude.Include.NON_NULL) - List stack -) { - public static CategoryRes of(List category, - List stack){ - return new CategoryRes(category,stack); - } -} \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/MyPageRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/MyPageRes.java deleted file mode 100644 index 26fd2886..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/MyPageRes.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.gongjakso.server.domain.apply.entity.Apply; -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import lombok.Builder; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.List; - -@Builder -@JsonInclude(JsonInclude.Include.NON_NULL) -public record MyPageRes( - Long postId, - Long memberId, - String memberName, - String title, - String contents, - PostStatus status, - ApplyType applyType, - LocalDateTime startDate, - LocalDateTime endDate, - Long daysRemaining, - boolean postType, - List categoryList, - Long scrapCount - -) { - public static MyPageRes of(Post post, Apply apply, List categoryList) { - return MyPageRes.builder() - .postId(post.getPostId()) - .memberId(post.getMember().getMemberId()) - .memberName(post.getMember().getName()) - .title(post.getTitle()) - .contents(post.getContents()) - .status(post.getStatus()) - .applyType(apply.getApplyType()) - .startDate(post.getStartDate()) - .endDate(post.getEndDate()) - .daysRemaining(post.getFinishDate().isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), post.getFinishDate())) - .postType(post.isPostType()) - .categoryList(categoryList) - .scrapCount(post.getScrapCount()) - .build(); - } -} - 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 deleted file mode 100644 index 634e48a4..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationList.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import lombok.Builder; - -import java.time.LocalDateTime; - -@Builder -public record ParticipationList( - Long postId, - String title, - String leaderName, - LocalDateTime startDate, - LocalDateTime finishDate, - PostStatus postStatus, - Boolean postType -) { - public static ParticipationList of(Post post) { - return ParticipationList.builder() - .postId(post.getPostId()) - .title(post.getTitle()) - .leaderName(post.getMember().getName()) - .startDate(post.getStartDate()) - .finishDate(post.getFinishDate()) - .postStatus(post.getStatus()) - .postType(post.isPostType()) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationPageRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationPageRes.java deleted file mode 100644 index 7806c762..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/ParticipationPageRes.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import java.util.List; - -public record ParticipationPageRes( - List participationLists, - int pageNo, - int pageSize, - int totalPages, - boolean last -) { - public static ParticipationPageRes of(List participationLists, int pageNo, int pageSize, int totalPages,boolean last) { - return new ParticipationPageRes(participationLists, pageNo, pageSize, totalPages, last); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/PatchApplyRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/PatchApplyRes.java deleted file mode 100644 index 9d799e06..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/PatchApplyRes.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.gongjakso.server.domain.apply.entity.Apply; -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import com.gongjakso.server.domain.apply.enumerate.PostType; -import com.gongjakso.server.domain.member.entity.Member; -import lombok.Builder; - -@Builder -@JsonInclude(JsonInclude.Include.NON_NULL) -public record PatchApplyRes( - Long applyId, - Long memberId, - String memberName, - Long postId, - String application, - String recruitPart, - PostType type, - ApplyType applyType, - Boolean isCanceled -) { - - public static PatchApplyRes of(Apply apply, Member member) { - return PatchApplyRes.builder() - .applyId(apply.getApplyId()) - .memberId(apply.getMember().getMemberId()) - .memberName(member.getName()) - .postId(apply.getPost().getPostId()) - .application(apply.getApplication()) - .applyType(apply.getApplyType()) - .recruitPart(apply.getRecruit_part()) - .isCanceled(apply.getIsCanceled()) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/PeriodReq.java b/src/main/java/com/gongjakso/server/domain/apply/dto/PeriodReq.java deleted file mode 100644 index fd320b5b..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/PeriodReq.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.gongjakso.server.domain.apply.dto; - -import java.time.LocalDate; - -public record PeriodReq( - LocalDate finishDate -) { -} \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/apply/entity/Apply.java b/src/main/java/com/gongjakso/server/domain/apply/entity/Apply.java deleted file mode 100644 index e0cc6bc0..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/entity/Apply.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.gongjakso.server.domain.apply.entity; - -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import com.gongjakso.server.domain.apply.enumerate.PostType; -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.global.common.BaseTimeEntity; -import jakarta.persistence.*; -import lombok.*; - -@Getter -@Setter -@Entity -@Table(name = "apply") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Apply extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "apply_id",nullable = false,columnDefinition = "bigint") - private Long applyId; - - @ManyToOne(targetEntity = Member.class, fetch = FetchType.LAZY) - @JoinColumn(name = "member_id") - private Member member; - - @ManyToOne(targetEntity = Post.class, fetch = FetchType.LAZY) - @JoinColumn(name = "post_id") - private Post post; - - @Column(name = "application",nullable = false,columnDefinition = "varchar(500)") - private String application; - - @Column(name = "recruit_part",nullable = false,columnDefinition = "varchar(50)") - private String recruit_part; - - @Enumerated(EnumType.STRING) - private PostType type; - - @Enumerated(EnumType.STRING) - private ApplyType applyType; - - @Column(name = "is_canceled", nullable = false) - private Boolean isCanceled; - - public void updateIsCanceled(Boolean isCanceled) { - this.isCanceled = isCanceled; - } - - @Builder - public Apply(Member member,Post post,String application,String recruit_part,PostType type, ApplyType applyType){ - this.member=member; - this.post=post; - this.application=application; - this.recruit_part=recruit_part; - this.type=type; - this.applyType=applyType; - this.isCanceled= Boolean.FALSE; - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/entity/ApplyStack.java b/src/main/java/com/gongjakso/server/domain/apply/entity/ApplyStack.java deleted file mode 100644 index 6f110ab7..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/entity/ApplyStack.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.gongjakso.server.domain.apply.entity; - -import com.gongjakso.server.domain.post.entity.StackName; -import jakarta.persistence.*; -import lombok.*; - -@Getter -@Setter -@Entity -@Table(name = "applyStack") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class ApplyStack{ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "applyStack_id",nullable = false,columnDefinition = "bigint") - private Long applyStackId; - - @ManyToOne - @JoinColumn(name = "apply_id") - private Apply apply; - - @ManyToOne - @JoinColumn(name = "stack_id") - private StackName stackName; - - @Builder - public ApplyStack(Long applyStackId,Apply apply,StackName stackName){ - this.applyStackId=applyStackId; - this.apply=apply; - this.stackName=stackName; - } -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/enumerate/ApplyType.java b/src/main/java/com/gongjakso/server/domain/apply/enumerate/ApplyType.java deleted file mode 100644 index cb6a90dd..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/enumerate/ApplyType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.gongjakso.server.domain.apply.enumerate; - -public enum ApplyType { - NONE,OPEN_APPLY,NOT_PASS,PASS -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/enumerate/PostType.java b/src/main/java/com/gongjakso/server/domain/apply/enumerate/PostType.java deleted file mode 100644 index f459bd18..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/enumerate/PostType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.gongjakso.server.domain.apply.enumerate; - -public enum PostType { - PROJECT,CONTEST; -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/enumerate/StackType.java b/src/main/java/com/gongjakso/server/domain/apply/enumerate/StackType.java deleted file mode 100644 index e69de29b..00000000 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 deleted file mode 100644 index e13d6573..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.gongjakso.server.domain.apply.repository; - -import com.gongjakso.server.domain.apply.entity.Apply; -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -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.util.List; -import java.util.Optional; - -public interface ApplyRepository extends JpaRepository { - - long countApplyWithStackNameUsingFetchJoinByPost(Post post); - - long countApplyWithStackNameUsingFetchJoinByPostAndApplyType(Post post,ApplyType applyType); - - boolean existsApplyByMemberAndPostAndIsCanceledIsFalse(Member member, Post post); - - Page findAllByPost(Post post, Pageable pageable); - - List findApplyByApplyTypeAndMemberAndIsCanceledFalse(ApplyType applyType, Member member); - - @Query(value = "SELECT a FROM Apply a JOIN FETCH a.post p JOIN FETCH p.categories WHERE a.member = :member AND a.post.status IN :postStatus AND a.deletedAt IS NULL AND a.isCanceled = false ORDER BY a.createdAt DESC", - 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); - - Optional findApplyByMemberAndPostAndDeletedAtIsNullAndIsCanceledFalse(Member member,Post post); - - Optional findApplyByApplyIdAndDeletedAtIsNullAndIsCanceledFalse(Long applyId); -} diff --git a/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyStackRepository.java b/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyStackRepository.java deleted file mode 100644 index a27dfb84..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyStackRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.gongjakso.server.domain.apply.repository; - -import com.gongjakso.server.domain.apply.entity.Apply; -import com.gongjakso.server.domain.apply.entity.ApplyStack; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface ApplyStackRepository extends JpaRepository { - List findAllByApply(Apply apply); -} 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 deleted file mode 100644 index 0394cae1..00000000 --- a/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java +++ /dev/null @@ -1,319 +0,0 @@ -package com.gongjakso.server.domain.apply.service; - -import com.gongjakso.server.domain.apply.dto.*; -import com.gongjakso.server.domain.apply.entity.Apply; -import com.gongjakso.server.domain.apply.entity.ApplyStack; -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import com.gongjakso.server.domain.apply.repository.ApplyRepository; -import com.gongjakso.server.domain.apply.repository.ApplyStackRepository; -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.StackName; -import com.gongjakso.server.domain.post.enumerate.CategoryType; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import com.gongjakso.server.domain.post.enumerate.StackNameType; -import com.gongjakso.server.domain.post.repository.CategoryRepository; -import com.gongjakso.server.domain.post.repository.PostRepository; -import com.gongjakso.server.domain.post.repository.StackNameRepository; -import com.gongjakso.server.global.exception.ApplicationException; -import com.gongjakso.server.global.exception.ErrorCode; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.*; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import static com.gongjakso.server.domain.post.enumerate.PostStatus.*; -import static com.gongjakso.server.global.exception.ErrorCode.INVALID_VALUE_EXCEPTION; - - -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class ApplyService { - - private final ApplyRepository applyRepository; - private final PostRepository postRepository; - private final CategoryRepository categoryRepository; - private final StackNameRepository stackNameRepository; - private final ApplyStackRepository applyStackRepository; -// private final EmailClient emailClient; - - @Transactional - public void save(Member member, Long postId, ApplyReq req) { - // Validation - Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - //Check reapply - if (applyRepository.existsApplyByMemberAndPostAndIsCanceledIsFalse(member, post)) { - throw new ApplicationException(ErrorCode.ALREADY_APPLY_EXCEPTION); - } - //Check Post Date - if ((!(post.getStatus() == RECRUITING))&&(!(post.getStatus() == EXTENSION))) { - throw new ApplicationException(ErrorCode.NOT_APPLY_EXCEPTION); - } - - Apply apply = req.toEntity(member, post); - applyRepository.save(apply); - if(post.isPostType()){ - for(String stackNameType : req.stack()){ - //StackNameType인지 판단 - if (!StackNameType.isValid(stackNameType)){ - throw new ApplicationException(INVALID_VALUE_EXCEPTION); - } - StackName stackName = stackNameRepository.findStackNameByPostAndStackNameType(post,stackNameType); - ApplyStack applyStack = ApplyStack.builder().apply(apply).stackName(stackName).build(); - applyStackRepository.save(applyStack); - } - } - } - - public ApplyRes findApply(Member member,Long postId) { - //Get Post - Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - if (!Objects.equals(post.getMember().getMemberId(), member.getMemberId())) { - throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); - } - - //Change List Type - List categoryList = changeCategoryType(post); - - int current_person = (int) applyRepository.countApplyWithStackNameUsingFetchJoinByPostAndApplyType(post,ApplyType.PASS); - return ApplyRes.of(post, current_person, categoryList); - } - - public CategoryRes findPostCategory(Long postId) { - Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - - //Change List Type - List categoryList = changeCategoryType(post); - List stackNameList; - if(post.isPostType()){ - stackNameList = changeStackNameType(post); - }else { - stackNameList= null; - } - - return CategoryRes.of(categoryList, stackNameList); - - } - - public ApplicationRes findApplication(Member member, Long apply_id, Long postId) { - Apply apply = applyRepository.findById(apply_id).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION)); - Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - - //Check leader - if (!Objects.equals(post.getMember().getMemberId(), member.getMemberId())) { - throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); - } - - //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; - } - - return ApplicationRes.of(apply, categoryList, stackNameList, applyStackList); - } - - @Transactional - public List changeCategoryType(Post post){ - List categoryList = categoryRepository.findCategoryByPost(post); - if (categoryList == null) { - throw new ApplicationException(ErrorCode.NOT_FOUND_CATEGORY_EXCEPTION); - } - - List stringTypelist = new ArrayList<>(); - for (Category category : categoryList) { - stringTypelist.add(String.valueOf(category.getCategoryType())); - } - - return stringTypelist; - } - - @Transactional - public List changeStackNameType(Post post){ - List stackNameList = stackNameRepository.findStackNameByPost(post); - List stringTypelist = new ArrayList<>(); - for (StackName stackName : stackNameList) { - stringTypelist.add(String.valueOf(stackName.getStackNameType())); - } - - return stringTypelist; - } - - public ApplyPageRes applyListPage(Member member, long postId, int page, int size) { - Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - if(!post.getMember().getMemberId().equals(member.getMemberId())) { - throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); - } - - Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending()); - Page applyPage = applyRepository.findAllByPost(post, pageable); - List applyLists = applyPage.getContent().stream() - .map(apply -> ApplyList.of(apply, decisionState(apply))) - .collect(Collectors.toList()); - int pageNo = applyPage.getNumber(); - int totalPages = applyPage.getTotalPages(); - boolean last = applyPage.isLast(); - - return ApplyPageRes.of(applyLists, pageNo, size, totalPages, last); - } - - 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()); - return ParticipationPageRes.of(participationLists, postPage.getNumber(), postPage.getSize(), postPage.getTotalPages(), postPage.isLast()); - } - - private String decisionState(Apply apply) { - if (apply.getApplyType().equals(ApplyType.OPEN_APPLY)) { - return "열람 완료"; - } else if (apply.getApplyType().equals(ApplyType.NOT_PASS)) { - return "미선발"; - } else if (apply.getApplyType().equals(ApplyType.PASS)) { - return "합류 완료"; - } - return "미열람"; - } - - @Transactional - public void updateState(Member member,Long apply_id, ApplyType applyType) { - Apply apply = applyRepository.findById(apply_id).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION)); - //Check ApplyType - if (apply.getApplyType().equals(ApplyType.NOT_PASS) || apply.getApplyType().equals(ApplyType.PASS)) { - throw new ApplicationException(ErrorCode.ALREADY_DECISION_EXCEPION); - } - - apply.setApplyType(applyType); - if (applyType.equals(ApplyType.PASS)) { - Post post = apply.getPost(); - //Check leader - if (!Objects.equals(post.getMember().getMemberId(), member.getMemberId())) { - throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); - } - Category category = categoryRepository.findCategoryByPostAndCategoryType(post, CategoryType.valueOf(apply.getRecruit_part())); - if (category.getSize() <= 0) { - throw new ApplicationException(ErrorCode.OVER_APPLY_EXCEPTION); - } else { - category.setSize(category.getSize() - 1); - } - } - } - - @Transactional - public void updatePostState(Member member,Long postId, PostStatus postStatus) { - Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - //Check leader - if (!Objects.equals(post.getMember().getMemberId(), member.getMemberId())) { - throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); - } - //CHECK POST STATUS - if ((!(post.getStatus() == RECRUITING))&&(!(post.getStatus() == EXTENSION))) { - throw new ApplicationException(ErrorCode.NOT_RECRUITING_EXCEPION); - } - - post.setStatus(postStatus); - } - - @Transactional - public void updatePostPeriod(Member member,Long postId, PeriodReq req) { - Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - if (!Objects.equals(post.getMember().getMemberId(), member.getMemberId())) { - throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); - } - //Check Post Status - if ((!(post.getStatus() == RECRUITING))&&(!(post.getStatus() == EXTENSION))) { - throw new ApplicationException(ErrorCode.NOT_RECRUITING_EXCEPION); - } - post.setStatus(EXTENSION); - post.setFinishDate(req.finishDate().atStartOfDay()); - } - - - public Page getMyApplyList(Member member, Pageable pageable) { - // Validation - - // Business Logic - List postStatusList = Arrays.asList(RECRUITING, EXTENSION, CANCEL, CLOSE); - Page applyPage = applyRepository.findAllByMemberAndPostStatusInAndDeletedAtIsNullAndIsCanceledFalseOrderByCreatedAtDesc(member, postStatusList, pageable); - List applyList = applyPage.stream() - .map(apply -> { - Post post = apply.getPost(); - List categoryList = post.getCategories().stream() - .map(category -> category.getCategoryType().toString()) - .toList(); - - return MyPageRes.of(post, apply, categoryList); - }) - .toList(); - - // Response - return new PageImpl<>(applyList, pageable, applyPage.getTotalElements()); - } - - public ApplicationRes getMyApplication(Member member, Long postId){ - Post post = postRepository.findByPostId(postId).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - - 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.findApplyByApplyIdAndDeletedAtIsNullAndIsCanceledFalse(applyId).orElseThrow(() -> new ApplicationException(ErrorCode.ALREADY_DELETE_EXCEPTION)); - if (!apply.getMember().getMemberId().equals(member.getMemberId())) { - throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); - } - Post post = postRepository.findByPostIdAndDeletedAtIsNull(apply.getPost().getPostId()).orElseThrow(() -> new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION)); - if(post.getFinishDate().isBefore(LocalDateTime.now())) { - throw new ApplicationException(ErrorCode.ALREADY_FINISH_EXCEPTION); - } - // Business Logic: isCanceled 칼럼을 TRUE로 변경하고, 공고 게시자에세 이메일을 전송한다. - apply.updateIsCanceled(Boolean.TRUE); - Apply saveApply = applyRepository.save(apply); - // TODO: 이메일 발송 로직을 실시간성이 아닌 일괄배치 또는 비동기로 변환 필요 (성능 문제) - // emailClient.sendOneEmail(post.getMember().getEmail()); - - // Response - return PatchApplyRes.of(saveApply, member); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/controller/CalendarController.java b/src/main/java/com/gongjakso/server/domain/post/controller/CalendarController.java deleted file mode 100644 index 24195991..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/controller/CalendarController.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.gongjakso.server.domain.post.controller; - -import com.gongjakso.server.domain.post.dto.CalendarRes; -import com.gongjakso.server.domain.post.service.CalendarService; -import com.gongjakso.server.global.common.ApplicationResponse; -import com.gongjakso.server.global.security.PrincipalDetails; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequestMapping("/api/v1/calendar") -@RequiredArgsConstructor -@Tag(name = "Calendar", description = "캘린더 관련 API") -public class CalendarController { - private final CalendarService calendarService; - @Operation(summary = "캘린더 정보 API", description = "자신이 스크랩한 공고 정보 요청") - @GetMapping("") - public ApplicationResponse addApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestParam(name = "year", defaultValue = "2024") int year, @RequestParam(name = "month", defaultValue = "4") int month){ - return ApplicationResponse.ok(calendarService.findScrapPost(principalDetails.getMember(),year,month)); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java b/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java deleted file mode 100644 index b64f6382..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/controller/PostController.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.gongjakso.server.domain.post.controller; - -import com.gongjakso.server.domain.post.dto.*; -import com.gongjakso.server.domain.post.service.PostService; -import com.gongjakso.server.global.common.ApplicationResponse; -import com.gongjakso.server.global.security.PrincipalDetails; -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; - -@RestController -@RequestMapping("/api/v1/post") -@RequiredArgsConstructor -@Tag(name = "Post", description = "공고 관련 API") -public class PostController { - - private final PostService postService; - - @Operation(summary = "공모전/프로젝트 공고 생성 API", description = "팀빌딩 페이지에서 정보 입력 후 공고 생성") - @PostMapping("") - public ApplicationResponse create(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestBody PostReq req) { - return ApplicationResponse.ok(postService.create(principalDetails.getMember(), req)); - } - - @Operation(summary = "사용자 별 상세 조회 API", description = "사용자별로 공고 상세 조회 다르게 반환") - @GetMapping("/{id}") - public ApplicationResponse read(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long postId) { - return ApplicationResponse.ok(postService.read(principalDetails, postId)); - } - - @Operation(summary = "공모전/프로젝트 공고 수정 API", description = "팀빌딩 페이지에서 정보 입력 후 공고 수정") - @PutMapping("/{id}") - public ApplicationResponse modify(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id, @RequestBody PostModifyReq req) { - return ApplicationResponse.ok(postService.modify(principalDetails.getMember(), id, req)); - } - - @Operation(summary = "공모전/프로젝트 공고 삭제 API", description = "내가 모집 중인 팀 페이지에서 공고 삭제") - @PatchMapping("/{id}") - public ApplicationResponse delete(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id){ - return ApplicationResponse.ok(postService.delete(principalDetails.getMember(), id)); - } - - @Operation(summary = "공모전 공고 목록 조회 및 페이지네이션 API", description = "공모전 공고 페이지에서 공고 목록 조회") - @GetMapping("/contest") - public ApplicationResponse> contestList(@PageableDefault(size = 6) Pageable pageable, - @RequestParam(value = "searchWord", required = false) String searchWord, - @RequestParam(value = "category", required = false) String category, - @RequestParam(value = "meetingCity", required = false) String meetingCity, - @RequestParam(value = "meetingTown", required = false) String meetingTown, - @RequestParam(value = "sort", required = false) String sort) { - return ApplicationResponse.ok(postService.getContestsByFilter(sort, meetingCity, meetingTown, category, searchWord, pageable)); - } - - @Operation(summary = "프로젝트 공고 목록 조회 및 페이지네이션 API", description = "프로젝트 공고 페이지에서 공고 목록 조회") - @GetMapping("/project") - public ApplicationResponse> projectList(@PageableDefault(size = 6) Pageable pageable, - @RequestParam(value = "searchWord", required = false) String searchWord, - @RequestParam(value = "stackName", required = false) String stackName, - @RequestParam(value = "meetingCity", required = false) String meetingCity, - @RequestParam(value = "meetingTown", required = false) String meetingTown, - @RequestParam(value = "sort", required = false) String sort) { - return ApplicationResponse.ok(postService.getProjectsByFilter(sort, meetingCity, meetingTown, stackName, searchWord, pageable)); - } - - @Operation(summary = "프로젝트 공고 스크랩 기능", description = "프로젝트 공고 스크랩") - @PostMapping("/{id}") - public ApplicationResponse scrapPost(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id) { - return ApplicationResponse.ok(postService.scrapPost(principalDetails.getMember(), id)); - } - - @Operation(summary = "프로젝트 공고 스크랩 조회 기능", description = "프로젝트 공고 스크랩 조회") - @GetMapping("/scrap/{id}") - public ApplicationResponse scrapGet(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("id") Long id) { - return ApplicationResponse.ok(postService.scrapGet(principalDetails.getMember(), id)); - } - - @Operation(summary = "내가 모집 중인 팀 조회 API", description = "프로젝트/공모전 별 각 한 개씩 묶어서 리스트 형태로 반환") - @GetMapping("/my") - public ApplicationResponse> getMyPostList(@AuthenticationPrincipal PrincipalDetails principalDetails) { - return ApplicationResponse.ok(postService.getMyPostList(principalDetails.getMember())); - } - - @Operation(summary = "공고와 관련된 유저인지를 확인하는 API", description = "팀장이거나, 신청자인 경우를 확인해서 결과로 반환") - @GetMapping("/check/{post_id}") - public ApplicationResponse checkPostRelation(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId) { - return ApplicationResponse.ok(postService.checkPostRelation(principalDetails.getMember(), postId)); - } - - @Operation(summary = "내가 스크랩한 프로젝트 공고 조회 API", description = "스크랩한 프로젝트 공고 페이지로 반환") - @GetMapping("/project/myScrap") - public ApplicationResponse> MyScrapProjectList(@PageableDefault(size = 6) Pageable pageable,@AuthenticationPrincipal PrincipalDetails principalDetails){ - return ApplicationResponse.ok(postService.getMyScrapProject(principalDetails.getMember(), pageable)); - } - - @Operation(summary = "내가 스크랩한 공모전 공고 조회 API", description = "스크랩한 공모전 공고 페이지로 반환") - @GetMapping("/contest/myScrap") - public ApplicationResponse> MyScrapContestList(@PageableDefault(size = 6) Pageable pageable,@AuthenticationPrincipal PrincipalDetails principalDetails){ - return ApplicationResponse.ok(postService.getMyScrapContest(principalDetails.getMember(), pageable)); - } - - @Operation(summary = "활동 종료 API", description = "팀장이 활동 중인 프로젝트 공고를 활동 종료할 때 사용하는 API로, 활동 종료된 공고의 정보가 반환") - @PatchMapping("/complete/{post_id}") - public ApplicationResponse completePost(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId) { - return ApplicationResponse.ok(postService.completePost(principalDetails.getMember(), postId)); - } -} \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/CalendarRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/CalendarRes.java deleted file mode 100644 index 80e66a51..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/CalendarRes.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import java.util.List; - -public record CalendarRes( - List scrapPosts -) { - public static CalendarRes of(List scrapPosts){ - return new CalendarRes(scrapPosts); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/CategoryReq.java b/src/main/java/com/gongjakso/server/domain/post/dto/CategoryReq.java deleted file mode 100644 index 1a64f107..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/CategoryReq.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -public record CategoryReq ( - @Schema( - description = "공고 카테고리(역할)를 (PLAN | DESIGN | FE | BE | ETC | LATER)의 ENUM으로 관리", - allowableValues = {"PLAN","DESIGN","FE","BE","ETC","LATER"} - ) - String categoryType, - - @Schema( - description = "공고 카테고리(역할)의 인원수를 size로 관리", - defaultValue = "0" - ) - Integer size -){} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/CategoryRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/CategoryRes.java deleted file mode 100644 index 0a99e012..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/CategoryRes.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.enumerate.CategoryType; -import lombok.Builder; - -@Builder -public record CategoryRes( - Long categoryId, - - CategoryType categoryType, - - Integer size -) { -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/GetContestRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/GetContestRes.java deleted file mode 100644 index bd2e8d30..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/GetContestRes.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import com.gongjakso.server.domain.post.projection.ContestProjection; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.List; - -@Builder -public record GetContestRes ( - @Schema( - description = "post가 생성된 순서를 관리하며 숫자가 높을수록 최신 공고임" - ) - Long postId, - - @Schema( - description = "post의 제목을 관리" - ) - String title, - - @Schema( - description = "post를 생성한 사용자의 이름" - ) - String name, //팀장명 - - @Schema( - description = "post의 상태를 (RECRUITING | CANCEL | CLOSE | ACTIVE | COMPLETE) ENUM으로 관리", - defaultValue = "RECRUITING", - allowableValues = {"RECRUITING", "CANCEL", "CLOSE", "ACTIVE", "COMPLETE"} - ) - PostStatus status, - - @Schema( - description = "공모전/프로젝트 활동 시작 날짜 관리" - ) - LocalDateTime startDate, - - @Schema( - description = "공모전/프로젝트 활동 마감 날짜 관리" - ) - LocalDateTime endDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜 관리" - ) - LocalDateTime finishDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜를 디데이로 관리" - ) - long daysRemaining, - - @Schema( - description = "공고 카테고리(역할)를 (PLAN | DESIGN | FE | BE | ETC | LATER)의 ENUM으로 관리하는 테이블" - ) - List categories, - - @Schema( - description = "공고 스크랩 수, 스크랩 수가 높을수록 인기순 우선순위", - defaultValue = "0" - ) - long scrapCount -){ public static GetContestRes of(Post post){ - return GetContestRes.builder() - .postId(post.getPostId()) - .title(post.getTitle()) - .name(post.getMember().getName()) - .status(post.getStatus()) - .startDate(post.getStartDate()) - .endDate(post.getEndDate()) - .daysRemaining(post.getFinishDate().isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), post.getFinishDate())) - .categories(post.getCategories().stream().map(category -> CategoryRes.builder() - .categoryId(category.getCategoryId()) - .categoryType(category.getCategoryType()) - .size(category.getSize()) - .build()).toList()) - .scrapCount(post.getScrapCount()) - .build(); - } - - public static GetContestRes of(ContestProjection contestProjection, List categoryResList) { - return GetContestRes.builder() - .postId(contestProjection.getPostId()) - .title(contestProjection.getTitle()) - .name(contestProjection.getMemberName()) - .status(contestProjection.getStatus()) - .startDate(contestProjection.getStartDate()) - .endDate(contestProjection.getEndDate()) - .finishDate(contestProjection.getFinishDate()) - .daysRemaining(contestProjection.getDaysRemaining()) - .categories(categoryResList) - .scrapCount(contestProjection.getScrapCount()) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/GetPostRelation.java b/src/main/java/com/gongjakso/server/domain/post/dto/GetPostRelation.java deleted file mode 100644 index 9556b5c1..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/GetPostRelation.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import lombok.Builder; - -@Builder -public record GetPostRelation( - String role -) { - public static GetPostRelation of(String role) { - return GetPostRelation.builder() - .role(role) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/GetProjectRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/GetProjectRes.java deleted file mode 100644 index 8e5710b4..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/GetProjectRes.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import com.gongjakso.server.domain.post.projection.ProjectProjection; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.List; - -@Builder -public record GetProjectRes ( - @Schema( - description = "post가 생성된 순서를 관리하며 숫자가 높을수록 최신 공고임" - ) - Long postId, - - @Schema( - description = "post의 제목을 관리" - ) - String title, - - @Schema( - description = "post를 생성한 사용자의 이름" - ) - String name, //팀장명 - - @Schema( - description = "post의 상태를 (RECRUITING | CANCEL | CLOSE | ACTIVE | COMPLETE) ENUM으로 관리", - defaultValue = "RECRUITING", - allowableValues = {"RECRUITING", "CANCEL", "CLOSE", "ACTIVE", "COMPLETE"} - ) - PostStatus status, - - @Schema( - description = "공모전/프로젝트 활동 시작 날짜 관리" - ) - LocalDateTime startDate, - - @Schema( - description = "공모전/프로젝트 활동 마감 날짜 관리" - ) - LocalDateTime endDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜 관리" - ) - LocalDateTime finishDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜를 디데이로 관리" - ) - long daysRemaining, - - @Schema( - description = "공고 카테고리(역할)를 (PLAN | DESIGN | FE | BE | ETC | LATER)의 ENUM으로 관리하는 테이블" - ) - List categories, - - @Schema( - description = "사용 기술스택을 (REACT | TYPESCRIPT | JAVASCRIPT | NEXTJS | NODEJS | JAVA | SPRING | KOTLIN | SWIFT | FLUTTER | FIGMA | ETC)의 ENUM으로 관리하는 테이블" - ) - List stackNames, - - @Schema( - description = "공고 스크랩 수, 스크랩 수가 높을수록 인기순 우선순위", - defaultValue = "0" - ) - long scrapCount -){ - public static GetProjectRes of(Post post){ - return GetProjectRes.builder() - .postId(post.getPostId()) - .title(post.getTitle()) - .name(post.getMember().getName()) - .status(post.getStatus()) - .startDate(post.getStartDate()) - .endDate(post.getEndDate()) - .daysRemaining(post.getFinishDate().isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), post.getFinishDate())) - .categories(post.getCategories().stream().map(category -> CategoryRes.builder() - .categoryType(category.getCategoryType()) - .size(category.getSize()) - .build()).toList()) - .stackNames(post.getStackNames().stream().map(stackName -> StackNameRes.builder() - .stackNameId(stackName.getStackNameId()) - .stackNameType(stackName.getStackNameType()) - .build()).toList()) - .scrapCount(post.getScrapCount()) - .build(); - } - - public static GetProjectRes of(ProjectProjection projectProjection, List categoryResList, List stackNameList) { - return GetProjectRes.builder() - .postId(projectProjection.getPostId()) - .title(projectProjection.getTitle()) - .name(projectProjection.getMemberName()) - .status(projectProjection.getStatus()) - .startDate(projectProjection.getStartDate()) - .endDate(projectProjection.getEndDate()) - .finishDate(projectProjection.getFinishDate()) - .daysRemaining(projectProjection.getDaysRemaining()) - .categories(categoryResList) - .stackNames(stackNameList) - .scrapCount(projectProjection.getScrapCount()) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/MyPageRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/MyPageRes.java deleted file mode 100644 index 33758ec6..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/MyPageRes.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import lombok.Builder; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.List; - -@Builder -@JsonInclude(JsonInclude.Include.NON_NULL) -public record MyPageRes( - Long postId, - Long memberId, - String memberName, - String title, - String contents, - PostStatus status, - LocalDateTime startDate, - LocalDateTime endDate, - Long daysRemaining, - boolean postType, - List categoryList, - Long scrapCount - -) { - public static MyPageRes of(Post post, Member member, List categoryList) { - return MyPageRes.builder() - .postId(post.getPostId()) - .memberId(member.getMemberId()) - .memberName(member.getName()) - .title(post.getTitle()) - .contents(post.getContents()) - .status(post.getStatus()) - .startDate(post.getStartDate()) - .endDate(post.getEndDate()) - .daysRemaining(post.getFinishDate().isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), post.getFinishDate())) - .postType(post.isPostType()) - .categoryList(categoryList) - .scrapCount(post.getScrapCount()) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java deleted file mode 100644 index cefe91d9..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostDeleteRes.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.entity.Post; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -@Builder -public record PostDeleteRes( - - @Schema( - description = "post가 생성된 순서를 관리하며 숫자가 높을수록 최신 공고임" - ) - Long postId, - - @Schema( - description = "member를 식별하는 pk값" - ) - Long memberId -){ - public static PostDeleteRes of(Post post, Member member){ - return PostDeleteRes.builder() - .postId(post.getPostId()) - .memberId(member.getMemberId()) - .build(); - } - -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostDetailRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostDetailRes.java deleted file mode 100644 index 4cb31954..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostDetailRes.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.StackName; -import com.gongjakso.server.domain.post.enumerate.MeetingMethod; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.List; - -@Builder -@JsonInclude(JsonInclude.Include.NON_NULL) -public record PostDetailRes( - @Schema( - description = "post가 생성된 순서를 관리하며 숫자가 높을수록 최신 공고임" - ) - Long postId, - - @Schema( - description = "member를 식별하는 pk값" - ) - Long memberId, - - @Schema( - description = "post를 생성한 사용자의 이름" - ) - String memberName, - - @Schema( - description = "post의 제목을 관리" - ) - String title, - - @Schema( - description = "post의 내용을 관리" - ) - String contents, - - @Schema( - description = "공모전 공고에서 공모전의 출처를 관리" - ) - String urlLink, - - @Schema( - description = "post의 상태를 (RECRUITING | CANCEL | CLOSE | ACTIVE | COMPLETE) ENUM으로 관리", - defaultValue = "RECRUITING", - allowableValues = {"RECRUITING", "CANCEL", "CLOSE", "ACTIVE", "COMPLETE"} - ) - PostStatus status, - - @Schema( - description = "공모전/프로젝트 활동 시작 날짜 관리" - ) - LocalDateTime startDate, - - @Schema( - description = "공모전/프로젝트 활동 마감 날짜 관리" - ) - LocalDateTime endDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜 관리" - ) - LocalDateTime finishDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜를 디데이로 관리" - ) - Long daysRemaining, - - @Schema( - description = "공모전/프로젝트 모집하려는 최대 인원 관리", - defaultValue = "0" - ) - Long maxPerson, - - @Schema( - description = "공모전/프로젝트 모집된 현황 인원 관리", - defaultValue = "0" - ) - int currentPerson, - - @Schema( - description = "사용 기술스택을 (REACT | TYPESCRIPT | JAVASCRIPT | NEXTJS | NODEJS | JAVA | SPRING | KOTLIN | SWIFT | FLUTTER | FIGMA | ETC)의 ENUM으로 관리하는 테이블" - ) - List stackNames, - - @Schema( - description = "공고 카테고리(역할)를 (PLAN | DESIGN | FE | BE | ETC | LATER)의 ENUM으로 관리하는 테이블" - ) - List categories, - - @Schema( - description = "회의 방식을 (OFFLINE, ONLINE, BOTH) 로 관리", - allowableValues = {"OFFLINE", "ONLINE", "BOTH"} - ) - MeetingMethod meetingMethod, - - @Schema( - description = "회의 장소를 행정구역단위로 관리" - ) - String meetingCity, - - @Schema( - description = "회의 장소를 행정구역단위로 관리" - ) - String meetingTown, - - @Schema( - description = "Q&A 방법 관리" - ) - boolean questionMethod, - - @Schema( - description = "Q&A Link 관리" - ) - String questionLink, - - @Schema( - description = "공고 타입을 0(contest), 1(project)으로 관리" - ) - boolean postType, - - @Schema( - description = "공고 생성 시간을 관리" - ) - LocalDateTime createdAt, - - @Schema( - description = "공고 스크랩 수, 스크랩 수가 높을수록 인기순 우선순위", - defaultValue = "0" - ) - Long scrapCount, - - @Schema( - description = "접근한 사용자의 memberId" - ) - Long currentId, - @Schema( - description = "조회수 반환 관리", - defaultValue = "0" - ) - Long postView -) { - - public static PostDetailRes of(Post post, int currentPerson, Long currentId) { - return PostDetailRes.builder() - .postId(post.getPostId()) - .memberId(post.getMember().getMemberId()) - .memberName(post.getMember().getName()) - .title(post.getTitle()) - .contents(post.getContents()) - .urlLink(post.getContestLink()) - .status(post.getStatus()) - .startDate(post.getStartDate()) - .endDate(post.getEndDate()) - .finishDate(post.getFinishDate()) - .daysRemaining(post.getFinishDate().isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), post.getFinishDate())) - .maxPerson(post.getMaxPerson()) - .currentPerson(currentPerson) - .stackNames(post.getStackNames()) - .categories(post.getCategories()) - .meetingMethod(post.getMeetingMethod()) - .meetingCity(post.getMeetingCity()) - .meetingTown(post.getMeetingTown()) - .questionMethod(post.isQuestionMethod()) - .questionLink(post.getQuestionLink()) - .postType(post.isPostType()) - .createdAt(post.getCreatedAt()) - .scrapCount(post.getScrapCount()) - .currentId(currentId) - .postView(post.getPostView()) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostModifyReq.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostModifyReq.java deleted file mode 100644 index d4d4a5de..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostModifyReq.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.StackName; -import com.gongjakso.server.domain.post.enumerate.MeetingMethod; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import io.swagger.v3.oas.annotations.media.Schema; - -import java.time.LocalDateTime; -import java.util.List; - -public record PostModifyReq ( - @Schema( - description = "post의 제목을 관리" - ) - String title, - - @Schema( - description = "post의 내용을 관리" - ) - String contents, - - @Schema( - description = "공모전 공고에서 공모전의 출처를 관리" - ) - String contestLink, - - @Schema( - description = "post의 상태를 (RECRUITING | CANCEL | CLOSE | ACTIVE | COMPLETE) ENUM으로 관리", - defaultValue = "RECRUITING", - allowableValues = {"RECRUITING", "CANCEL", "CLOSE", "ACTIVE", "COMPLETE"} - ) - PostStatus status, - - @Schema( - description = "공모전/프로젝트 활동 시작 날짜 관리" - ) - LocalDateTime startDate, - - @Schema( - description = "공모전/프로젝트 활동 마감 날짜 관리" - ) - LocalDateTime endDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜 관리" - ) - LocalDateTime finishDate, - - @Schema( - description = "공모전/프로젝트 모집하려는 최대 인원 관리", - defaultValue = "0" - ) - Long maxPerson, - - @Schema( - description = "사용 기술스택을 (REACT | TYPESCRIPT | JAVASCRIPT | NEXTJS | NODEJS | JAVA | SPRING | KOTLIN | SWIFT | FLUTTER | FIGMA | ETC)의 ENUM으로 관리하는 테이블" - ) - List stackNames, - - @Schema( - description = "공고 카테고리(역할)를 (PLAN | DESIGN | FE | BE | ETC | LATER)의 ENUM으로 관리하는 테이블" - ) - List categories, - @Schema( - description = "회의 방식을 (OFFLINE, ONLINE, BOTH) 로 관리", - allowableValues = {"OFFLINE", "ONLINE", "BOTH"} - ) - MeetingMethod meetingMethod, - - @Schema( - description = "회의 장소를 행정구역단위로 관리" - ) - String meetingCity, - - @Schema( - description = "회의 장소를 행정구역단위로 관리" - ) - String meetingTown, - - @Schema( - description = "Q&A 방법 관리" - ) - boolean questionMethod, - - @Schema( - description = "Q&A Link 관리" - ) - String questionLink, - - @Schema( - description = "공고 타입을 0(contest), 1(project)으로 관리" - ) - boolean postType -){ -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java deleted file mode 100644 index a0f53c7e..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostReq.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.StackName; -import com.gongjakso.server.domain.post.enumerate.MeetingMethod; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -import java.time.LocalDateTime; -import java.util.List; - -public record PostReq ( - @Schema( - description = "post의 제목을 관리" - ) - String title, - - @Schema( - description = "post의 내용을 관리" - ) - String contents, - - @Schema( - description = "공모전 공고에서 공모전의 출처를 관리" - ) - String contestLink, - - @Schema( - description = "공모전/프로젝트 활동 시작 날짜 관리" - ) - LocalDateTime startDate, - - @Schema( - description = "공모전/프로젝트 활동 마감 날짜 관리" - ) - LocalDateTime endDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜 관리" - ) - LocalDateTime finishDate, - @Schema( - description = "공모전/프로젝트 모집하려는 최대 인원 관리", - defaultValue = "0" - ) - Long maxPerson, - - @Schema( - description = "사용 기술스택을 (REACT | TYPESCRIPT | JAVASCRIPT | NEXTJS | NODEJS | JAVA | SPRING | KOTLIN | SWIFT | FLUTTER | FIGMA | ETC)의 ENUM으로 관리하는 테이블" - ) - List stackNames, - - @Schema( - description = "공고 카테고리(역할)를 (PLAN | DESIGN | FE | BE | ETC | LATER)의 ENUM으로 관리하는 테이블" - ) - List categories, - @Schema( - description = "회의 방식을 (OFFLINE, ONLINE, BOTH) 로 관리", - allowableValues = {"OFFLINE", "ONLINE", "BOTH"} - ) - MeetingMethod meetingMethod, - - @Schema( - description = "회의 장소를 행정구역단위로 관리" - ) - String meetingCity, - - @Schema( - description = "회의 장소를 행정구역단위로 관리" - ) - String meetingTown, - - @Schema( - description = "Q&A 방법 관리" - ) - boolean questionMethod, - - @Schema( - description = "Q&A Link 관리" - ) - String questionLink, - - @Schema( - description = "공고 타입을 0(contest), 1(project)으로 관리" - ) - boolean postType -){ - @Builder - public Post from(){ - return Post.builder() - .title(this.title) - .contents(this.contents) - .contestLink(this.contestLink) - .startDate(this.startDate) - .endDate(this.endDate) - .finishDate(this.finishDate) - .maxPerson(this.maxPerson) - .meetingMethod(this.meetingMethod) - .meetingCity(this.meetingCity) - .meetingTown(this.meetingTown) - .questionMethod(this.questionMethod) - .questionLink(this.questionLink) - .postType(this.postType) - .build(); - } -} \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java deleted file mode 100644 index 4180ab14..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostRes.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.StackName; -import com.gongjakso.server.domain.post.enumerate.MeetingMethod; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -import java.time.LocalDateTime; -import java.util.List; - -@Builder -public record PostRes( - @Schema( - description = "post가 생성된 순서를 관리하며 숫자가 높을수록 최신 공고임" - ) - Long postId, - - @Schema( - description = "member를 식별하는 pk값" - ) - Long memberId, - - @Schema( - description = "post의 제목을 관리" - ) - String title, - - @Schema( - description = "post의 내용을 관리" - ) - String contents, - - @Schema( - description = "공모전 공고에서 공모전의 출처를 관리" - ) - String contestLink, - - @Schema( - description = "post의 상태를 (RECRUITING | CANCEL | CLOSE | ACTIVE | COMPLETE) ENUM으로 관리", - defaultValue = "RECRUITING", - allowableValues = {"RECRUITING", "CANCEL", "CLOSE", "ACTIVE", "COMPLETE"} - ) - PostStatus status, - - @Schema( - description = "공모전/프로젝트 활동 시작 날짜 관리" - ) - LocalDateTime startDate, - - @Schema( - description = "공모전/프로젝트 활동 마감 날짜 관리" - ) - LocalDateTime endDate, - - @Schema( - description = "공모전/프로젝트 모집 마감 날짜 관리" - ) - LocalDateTime finishDate, - - @Schema( - description = "공모전/프로젝트 모집하려는 최대 인원 관리", - defaultValue = "0" - ) - Long maxPerson, - - @Schema( - description = "사용 기술스택을 (REACT | TYPESCRIPT | JAVASCRIPT | NEXTJS | NODEJS | JAVA | SPRING | KOTLIN | SWIFT | FLUTTER | FIGMA | ETC)의 ENUM으로 관리하는 테이블" - ) - List stackNames, - - @Schema( - description = "공고 카테고리(역할)를 (PLAN | DESIGN | FE | BE | ETC | LATER)의 ENUM으로 관리하는 테이블" - ) - List categories, - - @Schema( - description = "회의 방식을 (OFFLINE, ONLINE, BOTH) 로 관리", - allowableValues = {"OFFLINE", "ONLINE", "BOTH"} - ) - MeetingMethod meetingMethod, - - @Schema( - description = "회의 장소를 행정구역단위로 관리" - ) - String meetingCity, - - @Schema( - description = "회의 장소를 행정구역단위로 관리" - ) - String meetingTown, - - @Schema( - description = "Q&A 방법 관리" - ) - boolean questionMethod, - - @Schema( - description = "Q&A Link 관리" - ) - String questionLink, - - @Schema( - description = "공고 타입을 0(contest), 1(project)으로 관리" - ) - boolean postType, - - @Schema( - description = "공고 생성 날짜 관리" - ) - LocalDateTime createdAt, - - @Schema( - description = "공고 마지막 수정 날짜 관리" - ) - LocalDateTime modifiedAt, - - @Schema( - description = "공고 논리적 삭제 관리" - ) - LocalDateTime deletedAt) -{ - public static PostRes of(Post post) { - return PostRes.builder() - .postId(post.getPostId()) - .memberId(post.getMember().getMemberId()) - .title(post.getTitle()) - .contents(post.getContents()) - .contestLink(post.getContestLink()) - .status(post.getStatus()) - .startDate(post.getStartDate()) - .endDate(post.getEndDate()) - .finishDate(post.getFinishDate()) - .maxPerson(post.getMaxPerson()) - .stackNames(post.getStackNames()) - .categories(post.getCategories()) - .meetingMethod(post.getMeetingMethod()) - .meetingCity(post.getMeetingCity()) - .meetingTown(post.getMeetingTown()) - .questionMethod(post.isQuestionMethod()) - .questionLink(post.getQuestionLink()) - .postType(post.isPostType()) - .createdAt(post.getCreatedAt()) - .modifiedAt(post.getModifiedAt()) - .deletedAt(post.getDeletedAt()) - .build(); - } - - public boolean isPostType() { - return postType; - } -} \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostScrapRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostScrapRes.java deleted file mode 100644 index a15929ef..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostScrapRes.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.entity.PostScrap; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -@Builder -public record PostScrapRes( - - @Schema( - description = "post가 생성된 순서를 관리하며 숫자가 높을수록 최신 공고임" - ) - Long postId, - - @Schema( - description = "member를 식별하는 pk값" - ) - Long memberId, - - @Schema( - description = "사용자가 공고를 스크랩 했는지 boolean값으로 판단", - defaultValue = "0" - ) - Boolean scrapStatus, - - @Schema( - description = "해당 공고의 스크랩 총 수 반환", - defaultValue = "0" - ) - long scrapCount -) { - public static PostScrapRes of(PostScrap postScrap, long scrapCount){ - return PostScrapRes.builder() - .postId(postScrap.getPost().getPostId()) - .memberId(postScrap.getMember().getMemberId()) - .scrapStatus(postScrap.getScrapStatus()) - .scrapCount(scrapCount) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/PostSimpleRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/PostSimpleRes.java deleted file mode 100644 index 6e2dad5d..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/PostSimpleRes.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import lombok.Builder; - -import java.time.LocalDateTime; - -@Builder -public record PostSimpleRes( - String title, - String leaderName, - LocalDateTime startDate, - LocalDateTime finishDate, - PostStatus postStatus, - Boolean postType -) { - public static PostSimpleRes of(Post post) { - return PostSimpleRes.builder() - .title(post.getTitle()) - .leaderName(post.getMember().getName()) - .startDate(post.getStartDate()) - .finishDate(post.getFinishDate()) - .postStatus(post.getStatus()) - .postType(post.isPostType()) - .build(); - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/ScrapPost.java b/src/main/java/com/gongjakso/server/domain/post/dto/ScrapPost.java deleted file mode 100644 index d9dcebc5..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/ScrapPost.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import com.gongjakso.server.domain.post.entity.Post; -import io.swagger.v3.oas.annotations.media.Schema; - -import java.time.LocalDateTime; - -public record ScrapPost( - @Schema( - description = "post가 생성된 순서를 관리하며 숫자가 높을수록 최신 공고임" - ) - long postId, - - @Schema( - description = "post의 제목을 관리" - ) - String title, - - @Schema( - description = "공모전/프로젝트 공고 마감 날짜 관리" - ) - LocalDateTime finishDate, - - @Schema( - description = "공고 타입을 0(contest), 1(project)으로 관리" - ) - Boolean postType -) { - public static ScrapPost of(Post post){ - return new ScrapPost(post.getPostId(),post.getTitle(),post.getFinishDate(),post.isPostType()); - } -} \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/StackNameReq.java b/src/main/java/com/gongjakso/server/domain/post/dto/StackNameReq.java deleted file mode 100644 index 847a50d0..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/StackNameReq.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import io.swagger.v3.oas.annotations.media.Schema; - -public record StackNameReq ( - @Schema( - description = "사용 기술스택을 (REACT | TYPESCRIPT | JAVASCRIPT | NEXTJS | NODEJS | JAVA | SPRING | KOTLIN | SWIFT | FLUTTER | FIGMA | ETC)의 ENUM으로 관리", - allowableValues = {"REACT","TYPESCRIPT","JAVASCRIPT","NEXTJS","NODEJS","JAVA","SPRING","KOTLIN","SWIFT","FLUTTER","FIGMA","ETC"} - ) - String stackNameType -){} diff --git a/src/main/java/com/gongjakso/server/domain/post/dto/StackNameRes.java b/src/main/java/com/gongjakso/server/domain/post/dto/StackNameRes.java deleted file mode 100644 index d64dfb80..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/dto/StackNameRes.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.gongjakso.server.domain.post.dto; - -import lombok.Builder; - -@Builder -public record StackNameRes( - Long stackNameId, - - String stackNameType -) { - -} diff --git a/src/main/java/com/gongjakso/server/domain/post/entity/Category.java b/src/main/java/com/gongjakso/server/domain/post/entity/Category.java deleted file mode 100644 index 229a2536..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/entity/Category.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.gongjakso.server.domain.post.entity; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.gongjakso.server.domain.post.enumerate.CategoryType; -import jakarta.persistence.*; -import lombok.*; - -@Getter -@Setter -@Entity -@Table(name = "category") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Category { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "category_id", nullable = false, columnDefinition = "bigint") - private Long categoryId; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "post_id", nullable = false, columnDefinition = "bigint") - @JsonIgnore - private Post post; - - @Column(name = "category_type", nullable = false, columnDefinition = "varchar(100)") - @Enumerated(EnumType.STRING) - private CategoryType categoryType; - - @Column(name = "size", nullable = false, columnDefinition = "int") - private Integer size; - - @Builder - public Category(Post post, String categoryType, Integer size) { - this.post = post; - this.categoryType = CategoryType.valueOf(categoryType); - this.size = size; - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/entity/Post.java b/src/main/java/com/gongjakso/server/domain/post/entity/Post.java deleted file mode 100644 index c2092807..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/entity/Post.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.gongjakso.server.domain.post.entity; - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.dto.PostModifyReq; -import com.gongjakso.server.domain.post.enumerate.MeetingMethod; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import com.gongjakso.server.global.common.BaseTimeEntity; -import jakarta.persistence.*; -import lombok.*; -import org.hibernate.annotations.SQLDelete; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.List; - -@Getter -@Setter -@Entity -@Table(name = "post") -@SQLDelete(sql="UPDATE post SET deleted_at = NOW() where post_id=?") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Post extends BaseTimeEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "post_id", nullable = false, columnDefinition = "bigint") - private Long postId; - - @ManyToOne(targetEntity = Member.class, fetch = FetchType.EAGER) - @JoinColumn(name = "member_id") - private Member member; - - @Column(name = "title", nullable = false, columnDefinition = "varchar(40)") - private String title; - - @Column(name = "contents", nullable = false, columnDefinition = "varchar(500)") - private String contents; - - @Column(name = "status", columnDefinition = "varchar(255)") - @Enumerated(EnumType.STRING) - private PostStatus status; - - @Column(name = "start_date", nullable = false, columnDefinition = "timestamp") - private LocalDateTime startDate; - - @Column(name = "end_date", nullable = false, columnDefinition = "timestamp") - private LocalDateTime endDate; - - @Column(name = "finish_date", nullable = false, columnDefinition = "timestamp") - private LocalDateTime finishDate; - - @Column(name = "max_person", nullable = false, columnDefinition = "bigint") - private Long maxPerson; - - @OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - private List stackNames = new ArrayList<>(); - - @OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) - private List categories = new ArrayList<>(); - - @Column(name = "meeting_method", columnDefinition = "varchar(10)") - @Enumerated(EnumType.STRING) - private MeetingMethod meetingMethod; - - @Column(name = "meeting_city", columnDefinition = "varchar(100)") - private String meetingCity; - - @Column(name = "meeting_town", columnDefinition = "varchar(100)") - private String meetingTown; - - @Column(name = "constest_link", columnDefinition = "varchar(100)") - private String contestLink; - - @Column(name = "question_method", nullable = false, columnDefinition = "tinyint") - private boolean questionMethod; - - @Column(name = "question_link", nullable = false, columnDefinition = "text") - private String questionLink; - - @Column(name = "post_type", nullable = false, columnDefinition = "tinyint") - private boolean postType; - - @Column(name = "days_remaining", nullable = false, columnDefinition = "bigint") - private long daysRemaining; - - @Column(name="scrap_count", nullable = false, columnDefinition = "bigint") - private long scrapCount; - - @Column(name="post_view", nullable = false, columnDefinition = "bigint default 0") - private Long postView; - - public long getDaysRemaining(){ - return finishDate.isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), finishDate); - } - - @Builder - public Post(String title, Member member, String contents, String contestLink, LocalDateTime startDate, - LocalDateTime endDate, LocalDateTime finishDate, Long maxPerson, MeetingMethod meetingMethod, - String meetingCity, String meetingTown, boolean questionMethod, String questionLink, boolean postType, - List stackNames, List categories) { - this.title = title; - this.member = member; - this.contents = contents; - this.contestLink = contestLink; - this.status = PostStatus.RECRUITING; - this.startDate = startDate; - this.finishDate = finishDate; - this.endDate = endDate; - this.maxPerson = maxPerson; - this.meetingMethod = meetingMethod; - this.meetingCity = meetingCity; - this.meetingTown = meetingTown; - this.questionMethod = questionMethod; - this.questionLink = questionLink; - this.postType = postType; - this.daysRemaining = finishDate.isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), finishDate); - this.stackNames = stackNames; - this.categories = categories; - this.postView = 0L; - } - - public void modify(PostModifyReq req) { - this.title = req.title(); - this.contents = req.contents(); - this.contestLink = req.contestLink(); - this.status = (this.finishDate.isEqual(req.finishDate())) ? req.status() : PostStatus.EXTENSION; - this.startDate = req.startDate(); - this.endDate = req.endDate(); - this.finishDate = req.finishDate(); - this.maxPerson = req.maxPerson(); - this.meetingMethod = req.meetingMethod(); - this.meetingCity = req.meetingCity(); - this.meetingTown = req.meetingTown(); - this.questionMethod = req.questionMethod(); - this.questionLink = req.questionLink(); - this.postType = req.postType(); - this.daysRemaining = finishDate.isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), finishDate); - } - - public void updatePostView(Long postView) { - this.postView = postView + 1; - } - - public void updateStatus(PostStatus status) { - this.status = status; - } - - @Builder - public Post(Long id, String title, Member member, String contents, String contestLink, LocalDateTime startDate, - LocalDateTime endDate, LocalDateTime finishDate, Long maxPerson, MeetingMethod meetingMethod, - String meetingCity, String meetingTown, boolean questionMethod, String questionLink, boolean postType, - List stackNames, List categories) { - this.postId = id; - this.title = title; - this.member = member; - this.contents = contents; - this.contestLink = contestLink; - this.status = PostStatus.RECRUITING; - this.startDate = startDate; - this.finishDate = finishDate; - this.endDate = endDate; - this.maxPerson = maxPerson; - this.meetingMethod = meetingMethod; - this.meetingCity = meetingCity; - this.meetingTown = meetingTown; - this.questionMethod = questionMethod; - this.questionLink = questionLink; - this.postType = postType; - this.daysRemaining = finishDate.isBefore(LocalDateTime.now()) ? -1 : ChronoUnit.DAYS.between(LocalDateTime.now(), finishDate); - this.stackNames = stackNames; - this.categories = categories; - this.postView = 0L; - } -} \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/post/entity/PostScrap.java b/src/main/java/com/gongjakso/server/domain/post/entity/PostScrap.java deleted file mode 100644 index c9c4ec55..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/entity/PostScrap.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.gongjakso.server.domain.post.entity; - -import com.gongjakso.server.domain.member.entity.Member; -import jakarta.persistence.*; -import lombok.*; - -@Entity -@Getter -@Setter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class PostScrap{ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long postScrapId; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="postId") - private Post post; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="memberId") - private Member member; - - @Column(name="scrap_status", columnDefinition = "tinyint" ) - private boolean scrapStatus; - - @Builder - public PostScrap(Post post, Member member, Boolean scrapStatus){ - this.post = post; - this.member = member; - this.scrapStatus = scrapStatus; - } - - @Builder - public PostScrap(long postScrapId, Post post, Member member, Boolean scrapStatus){ - this.postScrapId = postScrapId; - this.post = post; - this.member = member; - this.scrapStatus = scrapStatus; - } - - public Boolean getScrapStatus(){ - return scrapStatus; - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/entity/StackName.java b/src/main/java/com/gongjakso/server/domain/post/entity/StackName.java deleted file mode 100644 index bb46b658..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/entity/StackName.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.gongjakso.server.domain.post.entity; -import com.fasterxml.jackson.annotation.JsonIgnore; -import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Entity -@Table(name = "stack_name") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class StackName { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "stack_name_id", nullable = false, columnDefinition = "bigint") - private Long stackNameId; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "post_id", nullable = false, columnDefinition = "bigint") - @JsonIgnore - private Post post; - - @Column(name = "stack_name_type", nullable = false, columnDefinition = "varchar(20)") - private String stackNameType; - - @Builder - public StackName(Post post, String stackNameType) { - this.post = post; - this.stackNameType = stackNameType; - } -} diff --git a/src/main/java/com/gongjakso/server/domain/post/enumerate/CategoryType.java b/src/main/java/com/gongjakso/server/domain/post/enumerate/CategoryType.java deleted file mode 100644 index 22d17f0e..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/enumerate/CategoryType.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.gongjakso.server.domain.post.enumerate; - -public enum CategoryType { - PLAN,DESIGN,FE,BE,ETC; - @Override - public String toString() { - return name(); - } - - public static boolean isValid(String category) { - for (CategoryType type : CategoryType.values()) { - if (type.name().equals(category)) { - return true; - } - } - return false; - } - -} diff --git a/src/main/java/com/gongjakso/server/domain/post/enumerate/MeetingMethod.java b/src/main/java/com/gongjakso/server/domain/post/enumerate/MeetingMethod.java deleted file mode 100644 index fa0c8ec9..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/enumerate/MeetingMethod.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.gongjakso.server.domain.post.enumerate; - -public enum MeetingMethod { - OFFLINE, ONLINE, BOTH -} \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/post/enumerate/PostStatus.java b/src/main/java/com/gongjakso/server/domain/post/enumerate/PostStatus.java deleted file mode 100644 index fc20ec47..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/enumerate/PostStatus.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.gongjakso.server.domain.post.enumerate; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum PostStatus { - - RECRUITING("모집 중"), - CANCEL("모집 취소"), - CLOSE("모집 마감"), - ACTIVE("활동 중"), - COMPLETE("활동 완료"), - EXTENSION("모집 연장"); - - private final String status; -} diff --git a/src/main/java/com/gongjakso/server/domain/post/enumerate/StackNameType.java b/src/main/java/com/gongjakso/server/domain/post/enumerate/StackNameType.java deleted file mode 100644 index 51defe9e..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/enumerate/StackNameType.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.gongjakso.server.domain.post.enumerate; - -public enum StackNameType { - REACT, - TYPESCRIPT, - JAVASCRIPT, - NEXTJS, - NODEJS, - JAVA, - SPRING, - KOTLIN, - SWIFT, - FLUTTER, - FIGMA, - ETC; - - @Override - public String toString() { - return name(); - } - - public static boolean isValid(String stackName) { - for (StackNameType type : StackNameType.values()) { - if (type.name().equals(stackName)) { - return true; - } - } - return false; - } - -} diff --git a/src/main/java/com/gongjakso/server/domain/post/projection/ContestProjection.java b/src/main/java/com/gongjakso/server/domain/post/projection/ContestProjection.java deleted file mode 100644 index 2f8d72fa..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/projection/ContestProjection.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.gongjakso.server.domain.post.projection; - -import com.gongjakso.server.domain.post.enumerate.CategoryType; -import com.gongjakso.server.domain.post.enumerate.PostStatus; - -import java.time.LocalDateTime; - -public interface ContestProjection { - Long getPostId(); - - String getTitle(); - - Long getMemberId(); - - String getMemberName(); - - PostStatus getStatus(); - - LocalDateTime getStartDate(); - - LocalDateTime getEndDate(); - - LocalDateTime getFinishDate(); - - long getDaysRemaining(); - - Long getCategoryId(); - - CategoryType getCategoryType(); - - Integer getCategorySize(); - - long getScrapCount(); -} diff --git a/src/main/java/com/gongjakso/server/domain/post/projection/ProjectProjection.java b/src/main/java/com/gongjakso/server/domain/post/projection/ProjectProjection.java deleted file mode 100644 index 610f6eac..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/projection/ProjectProjection.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.gongjakso.server.domain.post.projection; - -import com.gongjakso.server.domain.post.enumerate.CategoryType; -import com.gongjakso.server.domain.post.enumerate.PostStatus; - -import java.time.LocalDateTime; - -public interface ProjectProjection { - Long getPostId(); - - String getTitle(); - - Long getMemberId(); - - String getMemberName(); - - PostStatus getStatus(); - - LocalDateTime getStartDate(); - - LocalDateTime getEndDate(); - - LocalDateTime getFinishDate(); - - long getDaysRemaining(); - - Long getCategoryId(); - - CategoryType getCategoryType(); - - Integer getCategorySize(); - - Long getStackNameId(); - - String getStackNameType(); - - long getScrapCount(); -} diff --git a/src/main/java/com/gongjakso/server/domain/post/repository/CategoryRepository.java b/src/main/java/com/gongjakso/server/domain/post/repository/CategoryRepository.java deleted file mode 100644 index 0f88f4f0..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/repository/CategoryRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.gongjakso.server.domain.post.repository; - -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.CategoryType; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface CategoryRepository extends JpaRepository { - List findCategoryByPost(Post post); - Category findCategoryByPostAndCategoryType(Post post, CategoryType categoryType); -} 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 deleted file mode 100644 index e71cc246..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/repository/PostRepository.java +++ /dev/null @@ -1,261 +0,0 @@ -package com.gongjakso.server.domain.post.repository; - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import com.gongjakso.server.domain.post.projection.ContestProjection; -import com.gongjakso.server.domain.post.projection.ProjectProjection; -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; -import java.util.List; -import java.util.Optional; - -public interface PostRepository extends JpaRepository { - Optional findByPostId(Long postId); - - Optional findWithStackNameAndCategoryUsingFetchJoinByPostId(Long postId); - - Optional findByPostIdAndDeletedAtIsNull(Long postId); - List findAllByFinishDateBetweenAndPostIdIn(LocalDateTime finishDate, LocalDateTime finishDate2, List postIdList); - /* - 내가 모집 중인 공모전 공고 개수 - */ - Long countByMemberAndPostTypeFalseAndDeletedAtIsNullAndFinishDateAfterAndStatus - (Member member, LocalDateTime currentTimestamp, PostStatus status); - - /* - 내가 모집 중인 프로젝트 공고 개수 - */ - Long countByMemberAndPostTypeTrueAndDeletedAtIsNullAndFinishDateAfterAndStatus - (Member member, LocalDateTime currentTimestamp, PostStatus status); - - /* - 전체 공모전 공고 목록 조회 최신순 - */ - @Query(value = """ - select p.post_id - from post p - left join member m on p.member_id = m.member_id - left join category c on p.post_id = c.post_id - where p.post_type = false - and p.deleted_at is null - and p.finish_date > :currentTimestamp - and p.status in (:status) - and ( - case - when :searchWord is not null and :searchWord != '' then match(p.title, p.contents) against(:searchWord in natural language mode) - else true - end - ) - and ( - case - when :meetingCity is not null and :meetingCity != '' then p.meeting_city = :meetingCity - else true - end - ) - and ( - case - when :meetingTown is not null and :meetingTown != '' then p.meeting_town = :meetingTown - else true - end - ) - group by p.post_id - """, - countQuery = """ - SELECT COUNT(*) - FROM post p - LEFT JOIN member m ON p.member_id = m.member_id - LEFT JOIN category c ON p.post_id = c.post_id - WHERE p.post_type = false - AND p.deleted_at IS NULL - AND p.finish_date > :currentTimestamp - AND p.status IN (:status) - AND ( - CASE - WHEN :searchWord IS NOT NULL AND :searchWord != '' THEN MATCH(p.title, p.contents) AGAINST(:searchWord IN natural language mode) - ELSE 1=1 - END - ) - AND ( - CASE - WHEN :meetingCity IS NOT NULL AND :meetingCity != '' THEN p.meeting_city = :meetingCity - ELSE 1=1 - END - ) - AND ( - CASE - WHEN :meetingTown IS NOT NULL AND :meetingTown != '' THEN p.meeting_town = :meetingTown - ELSE 1=1 - END - ) - group by p.post_id - """, - nativeQuery = true) - Page findContestPaginationByFilter(@Param("searchWord") String searchWord, - @Param("currentTimestamp") LocalDateTime currentTimestamp, - @Param("status") List status, - @Param("meetingCity") String meetingCity, - @Param("meetingTown") String meetingTown, - Pageable pageable); - - @Query(value = """ - select p.post_id as postId, p.title as title, m.member_id as memberId, m.name as memberName, p.status as status, p.start_date as startDate, p.end_date as endDate, p.finish_date as finishDate, p.days_remaining as daysRemaining, c.category_id as categoryId, c.category_type as categoryType, c.size as categorySize, p.scrap_count as scrapCount - from post p - left join member m on p.member_id = m.member_id - left join category c on p.post_id = c.post_id - where p.post_id in (:postIdList) - order by p.created_at desc - """, nativeQuery = true - ) - List findContestProjectionListByPostIdListAndCreatedAtDesc(@Param("postIdList") List postIdList); - - @Query(value = """ - select p.post_id as postId, p.title as title, m.member_id as memberId, m.name as memberName, p.status as status, p.start_date as startDate, p.end_date as endDate, p.finish_date as finishDate, p.days_remaining as daysRemaining, c.category_id as categoryId, c.category_type as categoryType, c.size as categorySize, p.scrap_count as scrapCount - from post p - left join member m on p.member_id = m.member_id - left join category c on p.post_id = c.post_id - where p.post_id in (:postIdList) - order by p.scrap_count desc - """, nativeQuery = true - ) - List findContestProjectionListByPostIdListAndScrapCountAtDesc(@Param("postIdList") List postIdList); - - /* - 전체 프로젝트 공고 목록 조회 최신순 - */ - @Query(value = """ - select p.post_id - from post p - left join member m on p.member_id = m.member_id - left join category c on p.post_id = c.post_id - left join stack_name sn on p.post_id = sn.post_id - WHERE p.post_type = true - AND p.deleted_at IS NULL - AND p.finish_date > :currentTimestamp - AND p.status IN (:status) - and ( - case - when :searchWord is not null and :searchWord != '' then match(p.title, p.contents) against(:searchWord in natural language mode) - else true - end - ) - and ( - case - when :meetingCity is not null and :meetingCity != '' then p.meeting_city = :meetingCity - else true - end - ) - and ( - case - when :meetingTown is not null and :meetingTown != '' then p.meeting_town = :meetingTown - else true - end - ) - and ( - case - when :stackName is not null and :stackName != '' then sn.stack_name_type = :stackName - else true - end - ) - group by p.post_id - """, - countQuery = """ - select count(*) - FROM post p - left join member m on p.member_id = m.member_id - left join category c on p.post_id = c.post_id - left join stack_name sn on p.post_id = sn.post_id - WHERE p.post_type = true - AND p.deleted_at IS NULL - AND p.finish_date > :currentTimestamp - AND p.status IN (:status) - and ( - case - when :searchWord is not null and :searchWord != '' then match(p.title, p.contents) against(:searchWord in natural language mode) - else 1=1 - end - ) - and ( - case - when :meetingCity is not null and :meetingCity != '' then p.meeting_city = :meetingCity - else 1=1 - end - ) - and ( - case - when :meetingTown is not null and :meetingTown != '' then p.meeting_town = :meetingTown - else 1=1 - end - ) - and ( - case - when :stackName is not null and :stackName != '' then sn.stack_name_type = :stackName - else 1=1 - end - ) - group by p.post_id - """, - nativeQuery = true) - Page findProjectPaginationByFilter( - @Param("searchWord") String searchWord, - @Param("currentTimestamp") LocalDateTime currentTimestamp, - @Param("status") List status, - @Param("meetingCity") String meetingCity, - @Param("meetingTown") String meetingTown, - @Param("stackName") String stackName, - Pageable pageable - ); - - @Query(value = """ - select p.post_id as postId, p.title as title, m.member_id as memberId, m.name as memberName, p.status as status, p.start_date as startDate, p.end_date as endDate, p.finish_date as finishDate, p.days_remaining as daysRemaining, c.category_id as categoryId, c.category_type as categoryType, c.size as categorySize, sn.stack_name_id as stackNameId, sn.stack_name_type as stackNameType, p.scrap_count as scrapCount - from post p - left join member m on p.member_id = m.member_id - left join category c on p.post_id = c.post_id - left join stack_name sn on p.post_id = sn.post_id - where p.post_id in (:postIdList) - order by p.created_at desc - """, nativeQuery = true) - List findProjectProjectionListByPostIdListAndCreatedAtDesc(@Param("postIdList") List postIdList); - - @Query(value = """ - select p.post_id as postId, p.title as title, m.member_id as memberId, m.name as memberName, p.status as status, p.start_date as startDate, p.end_date as endDate, p.finish_date as finishDate, p.days_remaining as daysRemaining, c.category_id as categoryId, c.category_type as categoryType, c.size as categorySize, sn.stack_name_id as stackNameId, sn.stack_name_type as stackNameType, p.scrap_count as scrapCount - from post p - left join member m on p.member_id = m.member_id - left join category c on p.post_id = c.post_id - left join stack_name sn on p.post_id = sn.post_id - where p.post_id in (:postIdList) - order by p.scrap_count desc - """, nativeQuery = true) - List findProjectProjectionListByPostIdListAndScrapCountDesc(@Param("postIdList") List postIdList); - - - List findAllByMemberAndStatusInAndDeletedAtIsNullOrderByCreatedAtDesc(Member member, List statusList); - - @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); -} diff --git a/src/main/java/com/gongjakso/server/domain/post/repository/PostScrapRepository.java b/src/main/java/com/gongjakso/server/domain/post/repository/PostScrapRepository.java deleted file mode 100644 index aae0932f..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/repository/PostScrapRepository.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gongjakso.server.domain.post.repository; - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.PostScrap; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface PostScrapRepository extends JpaRepository { - PostScrap findByPostAndMember(Post post, Member member); - List findByMemberAndScrapStatus(Member member,boolean scrapStatus); - - Page findAllByMemberAndPostPostTypeTrueAndPostDeletedAtIsNullAndScrapStatusTrueOrderByPostScrapIdDesc(Member member, Pageable pageable); - - Page findAllByMemberAndPostPostTypeFalseAndPostDeletedAtIsNullAndScrapStatusTrueOrderByPostScrapIdDesc(Member member, Pageable pageable); - -} diff --git a/src/main/java/com/gongjakso/server/domain/post/repository/StackNameRepository.java b/src/main/java/com/gongjakso/server/domain/post/repository/StackNameRepository.java deleted file mode 100644 index e16b6809..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/repository/StackNameRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.gongjakso.server.domain.post.repository; - -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.StackName; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface StackNameRepository extends JpaRepository { - List findStackNameByPost(Post post); - StackName findStackNameByPostAndStackNameType(Post post, String stackNameType); -} diff --git a/src/main/java/com/gongjakso/server/domain/post/service/CalendarService.java b/src/main/java/com/gongjakso/server/domain/post/service/CalendarService.java deleted file mode 100644 index cc26cdb4..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/service/CalendarService.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.gongjakso.server.domain.post.service; - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.dto.CalendarRes; -import com.gongjakso.server.domain.post.dto.ScrapPost; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.PostScrap; -import com.gongjakso.server.domain.post.repository.PostRepository; -import com.gongjakso.server.domain.post.repository.PostScrapRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.List; -import java.util.stream.Collectors; - -@Service -@Transactional -@RequiredArgsConstructor -public class CalendarService { - private final PostScrapRepository postScrapRepository; - private final PostRepository postRepository; - public CalendarRes findScrapPost(Member member, int year, int month){ - List postScraps = postScrapRepository.findByMemberAndScrapStatus(member,true); - List postIdList = postScraps.stream().map(postScrap -> postScrap.getPost().getPostId()).toList(); - List posts = postRepository.findAllByFinishDateBetweenAndPostIdIn(getFirstDayOfMonth(year,month),getLastDayOfMonth(year,month), postIdList); - List scrapPosts = posts.stream().map(ScrapPost::of) - .collect(Collectors.toList()); - return CalendarRes.of(scrapPosts); - } - public static LocalDateTime getFirstDayOfMonth(int year, int month) { - LocalDate firstDayOfMonth = LocalDate.of(year, month, 1); - return LocalDateTime.of(firstDayOfMonth, LocalTime.MIN); - } - - public static LocalDateTime getLastDayOfMonth(int year, int month) { - LocalDate lastDayOfMonth = LocalDate.of(year, month, 1).plusMonths(1).minusDays(1); - return LocalDateTime.of(lastDayOfMonth, LocalTime.MAX); - } -} 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 deleted file mode 100644 index 9b8dcc3b..00000000 --- a/src/main/java/com/gongjakso/server/domain/post/service/PostService.java +++ /dev/null @@ -1,473 +0,0 @@ -package com.gongjakso.server.domain.post.service; - -import com.gongjakso.server.domain.apply.enumerate.ApplyType; -import com.gongjakso.server.domain.apply.repository.ApplyRepository; -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.dto.*; -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.PostScrap; -import com.gongjakso.server.domain.post.entity.StackName; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import com.gongjakso.server.domain.post.enumerate.StackNameType; -import com.gongjakso.server.domain.post.projection.ContestProjection; -import com.gongjakso.server.domain.post.projection.ProjectProjection; -import com.gongjakso.server.domain.post.repository.PostRepository; -import com.gongjakso.server.domain.post.repository.PostScrapRepository; -import com.gongjakso.server.global.exception.ApplicationException; -import com.gongjakso.server.global.security.PrincipalDetails; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.*; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; -import java.util.*; -import java.util.stream.Collectors; - -import static com.gongjakso.server.domain.post.enumerate.PostStatus.EXTENSION; -import static com.gongjakso.server.domain.post.enumerate.PostStatus.RECRUITING; -import static com.gongjakso.server.global.exception.ErrorCode.*; - - -@Slf4j -@Service -@RequiredArgsConstructor -public class PostService { - - private final PostRepository postRepository; - private final PostScrapRepository postScrapRepository; - private final ApplyRepository applyRepository; - - @Transactional - public PostRes create(Member member, PostReq req) { - // Validation - 공고/프로젝트별 1개의 모집 공고만 활성화되어 있는지 유효성 검사 - if (!req.postType() && postRepository.countByMemberAndPostTypeFalseAndDeletedAtIsNullAndFinishDateAfterAndStatus(member, LocalDateTime.now(), RECRUITING) > 0) { //공모전 공고 모집 개수 제한 - throw new ApplicationException(NOT_POST_EXCEPTION); - } - if (req.postType() && postRepository.countByMemberAndPostTypeTrueAndDeletedAtIsNullAndFinishDateAfterAndStatus(member, LocalDateTime.now(), RECRUITING) > 0) { //프로젝트 공고 모집 개수 제한 - throw new ApplicationException(NOT_POST_EXCEPTION); - } - if (req.maxPerson() != req.categories().stream().mapToInt(Category::getSize).sum()) { - throw new ApplicationException(ILLEGAL_POST_EXCEPTION); - } - - // Business Logic - Post entity = Post.builder() - .title(req.title()) - .member(member) - .contents(req.contents()) - .contestLink(req.contestLink()) - .startDate(req.startDate()) - .endDate(req.endDate()) - .finishDate(req.finishDate()) - .maxPerson(req.maxPerson()) - .meetingMethod(req.meetingMethod()) - .meetingCity(req.meetingCity()) - .meetingTown(req.meetingTown()) - .questionMethod(req.questionMethod()) - .questionLink(req.questionLink()) - .postType(req.postType()) - .stackNames(new ArrayList<>()) - .categories(new ArrayList<>()) - .build(); - - List stackNames = req.stackNames().stream() - .map(stackNameReq -> new StackName(entity, stackNameReq.getStackNameType())) - .toList(); - entity.getStackNames().addAll(stackNames); - - List categories = req.categories().stream() - .map(categoryReq -> new Category(entity, categoryReq.getCategoryType().toString(), categoryReq.getSize())) - .toList(); - entity.getCategories().addAll(categories); - Post savePost = postRepository.save(entity); - - // Response - return PostRes.of(savePost); - } - - @Transactional - public Optional read(PrincipalDetails principalDetails, Long postId) { - Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId).orElseThrow(() -> new ApplicationException(NOT_FOUND_POST_EXCEPTION)); - int current_person = (int) applyRepository.countApplyWithStackNameUsingFetchJoinByPostAndApplyType(post, ApplyType.PASS); - - post.updatePostView(post.getPostView()); - - post.getCategories().size(); - post.getStackNames().size(); - - if(principalDetails == null) { - return Optional.of(PostDetailRes.of(post, current_person,null)); - }else{ - return Optional.of(PostDetailRes.of(post, current_person, principalDetails.getMember().getMemberId())); - } - } - - - @Transactional - public PostRes modify(Member member, Long id, PostModifyReq req) { - // Validation - 공고 존재 여부 및 공고 게시자 여부 확인 - Post entity = postRepository.findByPostIdAndDeletedAtIsNull(id) - .orElseThrow(() -> new ApplicationException(NOT_FOUND_POST_EXCEPTION)); - if(!member.getMemberId().equals(entity.getMember().getMemberId())){ - throw new ApplicationException(UNAUTHORIZED_EXCEPTION); - } - if (req.maxPerson() != req.categories().stream().mapToInt(Category::getSize).sum()) { - throw new ApplicationException(ILLEGAL_POST_EXCEPTION); - } - - // Business Logic - entity.modify(req); - - entity.getStackNames().clear(); - entity.getCategories().clear(); - List updatedStackNames = req.stackNames().stream() - .map(stackNameReq -> new StackName(entity, stackNameReq.getStackNameType())) - .toList(); - entity.getStackNames().addAll(updatedStackNames); - - List categories = req.categories().stream() - .map(categoryReq -> new Category(entity, categoryReq.getCategoryType().toString(), categoryReq.getSize())) - .toList(); - entity.getCategories().addAll(categories); - - // Response - return PostRes.of(entity); - } - - @Transactional - public PostDeleteRes delete(Member member, Long id) { - Post entity = postRepository.findByPostIdAndDeletedAtIsNull(id) - .orElseThrow(() -> new ApplicationException(NOT_FOUND_POST_EXCEPTION)); - - if(!member.getMemberId().equals(entity.getMember().getMemberId())){ - throw new ApplicationException(UNAUTHORIZED_EXCEPTION); - } - - postRepository.delete(entity); - return PostDeleteRes.of(entity, member); - } - - /** - * 공모전/프로젝트 공고 목록 조회 및 페이지네이션 API - * @param sort 최신순, 인기순(스크랩 수가 높은 순) 정렬 - * @param meetingCity 오프라인 회의일 경우, 만나는 지역 구분 1 (도/광역시/특별시) - 별도의 입력이 없을 경우 전체로 들어옴 - * @param meetingTown 오프라인 회의일 경우, 만나는 지역 구분 2 (시/군/구) - 별도의 입력이 없을 경우 전체로 들어옴 - * @param category 공모전 종류 - 현재는 필터 적용 안 되어 있지만, 추후 추가될 예정 - * @param searchWord 검색어 - * @param page 페이지네이션에 필요한 오프셋, 사이즈 정보를 담은 Pageable 객체 - * @return Page 공모전 공고 목록 - */ - @Transactional(readOnly = true) - public Page getContestsByFilter(String sort, String meetingCity, String meetingTown, String category, String searchWord, Pageable page) { - // Business Logic - List statusList = Arrays.asList(PostStatus.RECRUITING.toString(), PostStatus.EXTENSION.toString()); // 공고가 모집/연장 상태인 경우만 조회되도록 하기 위한 상태값 설정 - String search = (searchWord != null && !searchWord.isEmpty()) ? searchWord.toLowerCase() : searchWord; - Sort sortCondition = switch (sort) { - case "createdAt" -> Sort.by("created_at").descending(); - case "scrapCount" -> Sort.by("scrap_count").descending(); - default -> throw new IllegalStateException("Unexpected value: " + sort); - }; - - page = PageRequest.of(page.getPageNumber(), page.getPageSize(), sortCondition); - Page postIdPage = postRepository.findContestPaginationByFilter( - search, - LocalDateTime.now(), - statusList, - meetingCity, - meetingTown, - page - ); - - List contestProjectionList = switch (sort) { - case "createdAt" -> postRepository.findContestProjectionListByPostIdListAndCreatedAtDesc(postIdPage.getContent()); - case "scrapCount" -> postRepository.findContestProjectionListByPostIdListAndScrapCountAtDesc(postIdPage.getContent()); - default -> throw new IllegalStateException("Unexpected value: " + sort); - }; - - // PostId 기준으로 그룹화 - Map> groupedByPostId = contestProjectionList.stream() - .collect(Collectors.groupingBy(ContestProjection::getPostId, LinkedHashMap::new, Collectors.toList())); - - // PostId 기준으로 그룹화된 맵을 사용하여 GetContestRes 객체 리스트 생성 - List contestResList = groupedByPostId.entrySet().stream() - .map(entry -> { - Long postId = entry.getKey(); - List contestProjections = entry.getValue(); - - // CategoryRes 리스트 구성 - List categoryResList = contestProjections.stream() - .filter(contestProjection -> contestProjection.getCategoryId() != null && contestProjection.getCategoryType() != null && contestProjection.getCategorySize() != null) - .map(contestProjection -> CategoryRes.builder() - .categoryId(contestProjection.getCategoryId()) - .categoryType(contestProjection.getCategoryType()) - .size(contestProjection.getCategorySize()) - .build()) - .collect(Collectors.toList()); - - // GetContestRes 객체 생성 - ContestProjection firstProjection = contestProjections.get(0); // 여기서도 첫 번째 객체를 가져올 수 있습니다. - return GetContestRes.builder() - .postId(postId) - .title(firstProjection.getTitle()) - .name(firstProjection.getMemberName()) - .status(firstProjection.getStatus()) - .startDate(firstProjection.getStartDate()) - .endDate(firstProjection.getEndDate()) - .finishDate(firstProjection.getFinishDate()) - .daysRemaining(firstProjection.getDaysRemaining()) - .categories(categoryResList) - .scrapCount(firstProjection.getScrapCount()) - .build(); - }) - .collect(Collectors.toList()); - - // Response - return new PageImpl<>(contestResList, postIdPage.getPageable(), postIdPage.getTotalPages()); - } - - /** - * 프로젝트 공고 목록 조회 및 페이지네이션 API - * @param sort 최신순, 인기순(스크랩 수가 높은 순) 정렬 - * @param meetingCity 도/광역시/특별시 - 별도의 입력이 없을 경우 전체로 들어옴 - * @param meetingTown 시/군/구 - 별도의 입력이 없을 경우 전체로 들어옴 - * @param stackName 기술 스택 - * @param searchWord 검색어 - * @param page 페이지네이션에 필요한 오프셋, 사이즈 정보를 담은 Pageable 객체 - * @return Page 프로젝트 공고 목록 - */ - @Transactional(readOnly = true) - public Page getProjectsByFilter(String sort, String meetingCity, String meetingTown, String stackName, String searchWord, Pageable page) { - // Validation - if(stackName != null && !stackName.isBlank() && !StackNameType.isValid(stackName)) { - throw new ApplicationException(INVALID_VALUE_EXCEPTION); - } - - // Business Logic - List statusList = Arrays.asList(PostStatus.RECRUITING.toString(), PostStatus.EXTENSION.toString()); // 공고가 모집/연장 상태인 경우만 조회되도록 하기 위한 상태값 설정 - String search = (searchWord != null && !searchWord.isEmpty()) ? searchWord.toLowerCase() : searchWord; - Sort sortCondition = switch (sort) { - case "createdAt" -> Sort.by("created_at").descending(); - case "scrapCount" -> Sort.by("scrap_count").descending(); - default -> throw new IllegalStateException("Unexpected value: " + sort); - }; - - System.out.println(searchWord); - - page = PageRequest.of(page.getPageNumber(), page.getPageSize(), sortCondition); - Page postIdPage = postRepository.findProjectPaginationByFilter( - search, - LocalDateTime.now(), - statusList, - meetingCity, - meetingTown, - stackName, - page - ); - - List projectProjectionList = switch (sort) { - case "createdAt" -> postRepository.findProjectProjectionListByPostIdListAndCreatedAtDesc(postIdPage.getContent()); - case "scrapCount" -> postRepository.findProjectProjectionListByPostIdListAndScrapCountDesc(postIdPage.getContent()); - default -> throw new IllegalStateException("Unexpected value: " + sort); - }; - - // PostId 기준으로 그룹화 - Map> groupedByPostId = projectProjectionList.stream() - .collect(Collectors.groupingBy(ProjectProjection::getPostId, LinkedHashMap::new, Collectors.toList())); - - List projectResList = groupedByPostId.entrySet().stream() - .map(entry -> { - Long postId = entry.getKey(); - List projections = entry.getValue(); - - // CategoryRes 리스트 구성 (중복 제거) - Set categoryResSet = projections.stream() - .filter(contestProjection -> contestProjection.getCategoryId() != null - && contestProjection.getCategoryType() != null - && contestProjection.getCategorySize() != null) - .map(category -> CategoryRes.builder() - .categoryId(category.getCategoryId()) - .categoryType(category.getCategoryType()) - .size(category.getCategorySize()) - .build()) - .collect(Collectors.toSet()); // Set으로 수집하여 중복 제거 - - // StackName 리스트 구성 (중복 제거) - Set stackNameSet = projections.stream() - .filter(stack -> stack != null - && stack.getStackNameId() != null - && stack.getStackNameType() != null) - .map(stack -> StackNameRes.builder() - .stackNameId(stack.getStackNameId()) - .stackNameType(stack.getStackNameType()) - .build()) - .collect(Collectors.toSet()); // Set으로 수집하여 중복 제거 - - // GetProjectRes 객체 생성 - ProjectProjection firstProjection = projections.get(0); - return GetProjectRes.builder() - .postId(postId) - .title(firstProjection.getTitle()) - .name(firstProjection.getMemberName()) - .status(firstProjection.getStatus()) - .startDate(firstProjection.getStartDate()) - .endDate(firstProjection.getEndDate()) - .finishDate(firstProjection.getFinishDate()) - .daysRemaining(firstProjection.getDaysRemaining()) - .categories(new ArrayList<>(categoryResSet)) // Set을 List로 변환 - .stackNames(new ArrayList<>(stackNameSet)) // Set을 List로 변환 - .scrapCount(firstProjection.getScrapCount()) - .build(); - }) - .collect(Collectors.toList()); - - // Response - return new PageImpl<>(projectResList, postIdPage.getPageable(), postIdPage.getTotalPages()); - } - - /* - 공고 스크랩 기능 - */ - @Transactional - public PostScrapRes scrapPost(Member member, Long postId) { - Post post = postRepository.findByPostIdAndDeletedAtIsNull(postId) - .orElseThrow(() -> new ApplicationException(NOT_FOUND_POST_EXCEPTION)); - if (member.getMemberId() == null) { - throw new ApplicationException(UNAUTHORIZED_EXCEPTION); - } - - PostScrap postScrap = postScrapRepository.findByPostAndMember(post, member); - - if (postScrap == null) { //첫 스크랩 - postScrap = PostScrap.builder() - .post(post) - .member(member) - .scrapStatus(true) - .build(); - post.setScrapCount(post.getScrapCount() + 1); - } else { // 스크랩 한 적 있는 경우 - if (postScrap.getScrapStatus()) { //스크랩한 상태면 취소 - postScrap.setScrapStatus(false); - if (post.getScrapCount() > 0) post.setScrapCount(post.getScrapCount() - 1); - else throw new ApplicationException(INVALID_VALUE_EXCEPTION); - } else { //스크랩 안 한 경우 - postScrap.setScrapStatus(true); - post.setScrapCount(post.getScrapCount() + 1); - } - } - postScrapRepository.save(postScrap); - postRepository.save(post); - return PostScrapRes.of(postScrap, post.getScrapCount()); - } - - @Transactional - public PostScrapRes scrapGet(Member member, Long postId){ - Post post = postRepository.findByPostIdAndDeletedAtIsNull(postId) - .orElseThrow(() -> new ApplicationException(NOT_FOUND_POST_EXCEPTION)); - if (member.getMemberId() == null) { - throw new ApplicationException(UNAUTHORIZED_EXCEPTION); - } - if(postScrapRepository.findByPostAndMember(post, member)==null){ //post, member 정보는 존재하되, scrap한적이 없는 경우 default false값 반환 - return new PostScrapRes(post.getPostId(), member.getMemberId(), false, post.getScrapCount()); - } - PostScrap postScrap = postScrapRepository.findByPostAndMember(post, member); - return PostScrapRes.of(postScrap, post.getScrapCount()); - } - - @Transactional - public List getMyPostList(Member member) { - // Validation - - // Business Logic - List statusList = Arrays.asList(RECRUITING, EXTENSION); - List postList = postRepository.findAllByMemberAndStatusInAndDeletedAtIsNullOrderByCreatedAtDesc(member, statusList); - - // Return - return postList.stream() - .map(post -> { - List categoryList = post.getCategories().stream() - .map(category -> category.getCategoryType().toString()) - .toList(); - - return MyPageRes.of(post, member, categoryList); - }) - .collect(Collectors.toList()); - } - - @Transactional - public GetPostRelation checkPostRelation(Member member, Long postId) { - // Validation - Post post = postRepository.findByPostIdAndDeletedAtIsNull(postId).orElseThrow(() -> new ApplicationException(ALREADY_DELETE_EXCEPTION)); - - // Business Logic - String role = "GENERAL"; - if(post.getMember().getMemberId().equals(member.getMemberId())){ - role = "LEADER"; - } - else { - if(applyRepository.existsApplyByMemberAndPostAndIsCanceledIsFalse(member, post)) { - role = "APPLICANT"; - } - } - - // Return - return GetPostRelation.of(role); - } - - @Transactional - public Page getMyScrapProject(Member member, Pageable page){ - Pageable pageable = PageRequest.of(page.getPageNumber(), page.getPageSize()); - - Page scrapPageList = postScrapRepository.findAllByMemberAndPostPostTypeTrueAndPostDeletedAtIsNullAndScrapStatusTrueOrderByPostScrapIdDesc(member, pageable); - - List myScrapProjects = scrapPageList.stream() - .map(scrap -> { - Post post = scrap.getPost(); - post.getCategories().size(); - post.getStackNames().size(); - return GetProjectRes.of(post); - }) - .collect(Collectors.toList()); // 리스트로 수집 - - // 필터링된 리스트를 페이지로 반환 - return new PageImpl<>( myScrapProjects, pageable, myScrapProjects.size()); - } - - @Transactional - public Page getMyScrapContest(Member member, Pageable page){ - Pageable pageable = PageRequest.of(page.getPageNumber(), page.getPageSize()); - - Page scrapPageList = postScrapRepository.findAllByMemberAndPostPostTypeFalseAndPostDeletedAtIsNullAndScrapStatusTrueOrderByPostScrapIdDesc(member, pageable); - - List myScrapContests = scrapPageList.stream() - .map(scrap -> { - Post post = scrap.getPost(); - post.getCategories().size(); - post.getStackNames().size(); - return GetContestRes.of(post); - }) - .collect(Collectors.toList()); // 리스트로 수집 - - // 필터링된 리스트를 페이지로 반환 - return new PageImpl<>(myScrapContests, pageable, myScrapContests.size()); - } - - - @Transactional - public PostSimpleRes completePost(Member member, Long postId) { - // Validation: Post 논리적 삭제 및 사용자의 권한 여부 확인 - Post post = postRepository.findByPostIdAndDeletedAtIsNull(postId).orElseThrow(() -> new ApplicationException(NOT_FOUND_POST_EXCEPTION)); - if(!post.getMember().getMemberId().equals(member.getMemberId())){ - throw new ApplicationException(UNAUTHORIZED_EXCEPTION); - } - - // Business Logic - post.updateStatus(PostStatus.COMPLETE); - Post savePost = postRepository.save(post); - - // Response - return PostSimpleRes.of(savePost); - } -} \ No newline at end of file From 87e2454db95839fad5e0f978351a5fbc31bed2f7 Mon Sep 17 00:00:00 2001 From: dl-00-e8 Date: Thu, 15 Aug 2024 13:11:01 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[#173]=20refactor:=20prod=20yml=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=ED=95=98=EC=97=AC=20=EA=B4=80=EB=A6=AC=ED=95=98?= =?UTF-8?q?=EA=B8=B0=EC=97=90=20gitignore=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3640dd54..858efd81 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,7 @@ docker-compose.yml monitoring-docker-compose.yml prometheus.yml **/application.yml +**/application-prod.yml __default__.tmpl grafana.db \ No newline at end of file From 40d44b877bb941f7221b40c6a35da49c19bb8968 Mon Sep 17 00:00:00 2001 From: dl-00-e8 Date: Thu, 15 Aug 2024 13:11:10 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[#173]=20refactor:=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/main/resources/.gitkeep diff --git a/src/main/resources/.gitkeep b/src/main/resources/.gitkeep deleted file mode 100644 index e69de29b..00000000 From 2194fce5ace523ee7927afb991c6c7974d36e838 Mon Sep 17 00:00:00 2001 From: dl-00-e8 Date: Thu, 15 Aug 2024 13:11:21 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[#173]=20refactor:=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=20=EB=A1=9C=EA=B7=B8=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gongjakso/server/ServerApplication.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gongjakso/server/ServerApplication.java b/src/main/java/com/gongjakso/server/ServerApplication.java index 5b432b68..6d871d31 100644 --- a/src/main/java/com/gongjakso/server/ServerApplication.java +++ b/src/main/java/com/gongjakso/server/ServerApplication.java @@ -1,24 +1,19 @@ package com.gongjakso.server; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.web.config.PageableHandlerMethodArgumentResolverCustomizer; +@Slf4j @EnableJpaAuditing @SpringBootApplication public class ServerApplication { public static void main(String[] args) { SpringApplication.run(ServerApplication.class, args); - System.out.println("Gongjakso Server is running"); - } - - @Bean - public PageableHandlerMethodArgumentResolverCustomizer customize() { - return p -> { - p.setOneIndexedParameters(true); // 1부터 시작 - }; + log.info("Gongjakso Server is running"); } } From f237cc73f1affab0f50214cf1f5bb71214ebbb6d Mon Sep 17 00:00:00 2001 From: dl-00-e8 Date: Thu, 15 Aug 2024 13:33:38 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[#173]=20refactor:=20=EB=AF=B8=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PaginationControllerTest.java | 68 --- .../domain/post/domain/ScrapDomainTest.java | 55 --- .../post/service/PaginationServiceTest.java | 388 ------------------ .../domain/post/service/PostServiceTest.java | 38 -- .../domain/post/util/PostScrapUtilTest.java | 43 -- .../server/domain/post/util/PostUtilTest.java | 93 ----- 6 files changed, 685 deletions(-) delete mode 100644 src/test/java/com/gongjakso/server/domain/post/controller/PaginationControllerTest.java delete mode 100644 src/test/java/com/gongjakso/server/domain/post/domain/ScrapDomainTest.java delete mode 100644 src/test/java/com/gongjakso/server/domain/post/service/PaginationServiceTest.java delete mode 100644 src/test/java/com/gongjakso/server/domain/post/service/PostServiceTest.java delete mode 100644 src/test/java/com/gongjakso/server/domain/post/util/PostScrapUtilTest.java delete mode 100644 src/test/java/com/gongjakso/server/domain/post/util/PostUtilTest.java diff --git a/src/test/java/com/gongjakso/server/domain/post/controller/PaginationControllerTest.java b/src/test/java/com/gongjakso/server/domain/post/controller/PaginationControllerTest.java deleted file mode 100644 index 19406783..00000000 --- a/src/test/java/com/gongjakso/server/domain/post/controller/PaginationControllerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.gongjakso.server.domain.post.controller; - -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; - -@AutoConfigureMockMvc -@ExtendWith(MockitoExtension.class) -public class PaginationControllerTest { -/* - MockMvc mockMvc; - - private ObjectMapper objectMapper = new ObjectMapper(); - - @MockBean - private PostService postService; - - @MockBean - private PostRepository postRepository; - - @MockBean - private MemberRepository memberRepository; - - @MockBean - private ApplyService applyService; - - @MockBean - private TokenProvider tokenProvider; - - @MockBean - private RedisClient redisClient; - - @MockBean - private JwtFilter jwtFilter; - - private Member member; - private PrincipalDetails principalDetails; - - @BeforeEach - void setUp() { - member = MemberUtilTest.buildMemberAndId(1L); - principalDetails = new PrincipalDetails(member); - UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( - principalDetails, null, principalDetails.getAuthorities()); - SecurityContextHolder.getContext().setAuthentication(authentication); - } - - @Test - @DisplayName("공고 스크랩 저장 및 취소 기능") - void scrapPost() throws Exception { - //given - Post post = PostUtilTest.builderPost(1L, member); - PostScrapRes postScrapRes = PostScrapUtilTest.ScrapPostRes(post.getPostId(), member.getMemberId(), true); - given(postService.scrapPost(any(Member.class), anyLong())).willReturn(postScrapRes); - String resJson = objectMapper.writeValueAsString(postScrapRes); - - mockMvc.perform(post("/api/v1/post/{id}", post.getPostId()) - .contentType(MediaType.APPLICATION_JSON) - .principal((Principal) principalDetails)) - .andExpect(status().isOk()) - .andExpect(content().json(resJson)) - .andDo(print()); - - verify(postService).scrapPost(any(Member.class), any(Long.class)); - } - - */ -} diff --git a/src/test/java/com/gongjakso/server/domain/post/domain/ScrapDomainTest.java b/src/test/java/com/gongjakso/server/domain/post/domain/ScrapDomainTest.java deleted file mode 100644 index 6814e51a..00000000 --- a/src/test/java/com/gongjakso/server/domain/post/domain/ScrapDomainTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.gongjakso.server.domain.post.domain; - - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.member.util.MemberUtilTest; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.PostScrap; -import com.gongjakso.server.domain.post.util.PostScrapUtilTest; -import com.gongjakso.server.domain.post.util.PostUtilTest; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -@DisplayName("PostScrap 도메인 테스트") -public class ScrapDomainTest{ - - private Post post; - private Member member; - - @BeforeEach - public void setUp() { - member = MemberUtilTest.buildMemberAndId(1L); - post = PostUtilTest.builderPost(1L, member); - } - - @Nested - @DisplayName("Builder테스트") - class BuilderTests { - - @Test - @DisplayName("Id없이 빌드 되어야 함") - public void testPostScrapBuilder() { - PostScrap postScrap = PostScrapUtilTest.builderPostScrap(post, post.getMember()); - System.out.println(postScrap.getMember()); - System.out.println(member); - assertThat(postScrap.getPost()).isEqualTo(post); - assertThat(postScrap.getMember()).isEqualTo(member); - assertThat(postScrap.getScrapStatus()).isTrue(); - } - - @Test - @DisplayName("Id와 함께 빌드 되어야 함") - public void testPostScrapBuilderWithId() { - Long postScrapId = 1L; - PostScrap postScrap = PostScrapUtilTest.builderPostScrapWithPostAndMember(postScrapId, post, post.getMember()); - assertThat(postScrap.getPostScrapId()).isEqualTo(postScrapId); - assertThat(postScrap.getPost()).isEqualTo(post); - assertThat(postScrap.getMember()).isEqualTo(member); - assertThat(postScrap.getScrapStatus()).isTrue(); - } - } -} \ No newline at end of file diff --git a/src/test/java/com/gongjakso/server/domain/post/service/PaginationServiceTest.java b/src/test/java/com/gongjakso/server/domain/post/service/PaginationServiceTest.java deleted file mode 100644 index 4646d150..00000000 --- a/src/test/java/com/gongjakso/server/domain/post/service/PaginationServiceTest.java +++ /dev/null @@ -1,388 +0,0 @@ -package com.gongjakso.server.domain.post.service; - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.member.util.MemberUtilTest; -import com.gongjakso.server.domain.post.dto.GetContestRes; -import com.gongjakso.server.domain.post.dto.GetProjectRes; -import com.gongjakso.server.domain.post.dto.PostScrapRes; -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.PostScrap; -import com.gongjakso.server.domain.post.enumerate.PostStatus; -import com.gongjakso.server.domain.post.repository.PostRepository; -import com.gongjakso.server.domain.post.repository.PostScrapRepository; -import com.gongjakso.server.domain.post.util.PostScrapUtilTest; -import com.gongjakso.server.domain.post.util.PostUtilTest; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -import java.time.LocalDateTime; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; - -@DisplayName("페이지네이션 및 스크랩 공고 Service 테스트") -@ExtendWith(MockitoExtension.class) -public class PaginationServiceTest { - @InjectMocks - PostService postService; - - @Mock - PostRepository postRepository; - - @Mock - PostScrapRepository postScrapRepository; - - @Nested - @DisplayName("공모전 공고 페이지네이션") - class ContestTests{ - - @Nested - @DisplayName("공모전 공고 전체 조회") - class ContestTestsAll{ - - @Test - @DisplayName("공모전 공고 전체 조회 최신순") - void getContestsByCreatedAt() { - // given - List testPosts = PostUtilTest.builderMultiplePosts(false); - Pageable pageable = PageRequest.of(0, 6); - Page testPage = new PageImpl<>(testPosts, pageable, testPosts.size()); // Page 생성 - - given(postRepository.findAllByPostTypeFalseAndDeletedAtIsNullAndFinishDateAfterAndStatusOrderByPostIdDesc( - any(LocalDateTime.class), any(PostStatus.class), any(Pageable.class) - )).willReturn(testPage); - - // when - Page res = postService.getContests("createdAt", pageable); - - // then - assertThat(res).isNotNull(); - assertThat(res.getTotalElements()).isEqualTo(7); - assertThat(res.getTotalPages()).isEqualTo(2); - assertThat(res.getContent().get(0).title()).isEqualTo("Title1"); - assertThat(res.getContent().get(1).title()).isEqualTo("Title2"); - assertThat(res.getContent().get(2).title()).isEqualTo("Title3"); - } - - @Test - @DisplayName("공모전 공고 전체 조회 인기순") - void getContestsByScrapCount() { - // given - List testPosts = PostUtilTest.builderMultiplePosts(false); - testPosts.get(3).setScrapCount(10); // 제목4 - testPosts.get(6).setScrapCount(8); // 제목7 - testPosts.sort(Comparator.comparing(Post::getScrapCount) - .thenComparing(Post::getPostId).reversed()); - Pageable pageable = PageRequest.of(0, 6); - Page testPage = new PageImpl<>(testPosts, pageable, testPosts.size()); // Page 생성 - - - given(postRepository.findAllByPostTypeFalseAndDeletedAtIsNullAndFinishDateAfterAndStatusOrderByScrapCountDescPostIdDesc( - any(LocalDateTime.class), any(PostStatus.class), any(Pageable.class) - )).willReturn(testPage); - - // When - Page res = postService.getContests("scrapCount", pageable); - - // then - assertThat(res).isNotNull(); - assertThat(res.getTotalElements()).isEqualTo(7); - assertThat(res.getTotalPages()).isEqualTo(2); - assertThat(res.getContent().get(0).title()).isEqualTo("제목4"); - assertThat(res.getContent().get(1).title()).isEqualTo("제목7"); - // 스크랩 순 -> 최신 순으로 정렬되는 지 확인 - assertThat(res.getContent().get(2).title()).isEqualTo("제목6"); - assertThat(res.getContent().get(3).title()).isEqualTo("제목5"); - } - } - @Nested - @DisplayName("공모전 공고 검색어 기반 조회") - class ContestTestsWithSearchWord { - - @Test - @DisplayName("공모전 공고 검색어 기반 조회 최신순") - void getContestsByCreatedAt() { - // given - String searchWord = "제목"; - List testPosts = PostUtilTest.builderMultiplePosts(false).stream() - .filter(post -> post.getTitle().contains(searchWord)) - .collect(Collectors.toList()); - Pageable pageable = PageRequest.of(0, 6); - Page testPage = new PageImpl<>(testPosts, pageable, testPosts.size()); - - given(postRepository.findAllByTitleContainsAndPostTypeFalseAndDeletedAtIsNullAndFinishDateAfterAndStatusOrderByPostIdDesc( - any(String.class), any(LocalDateTime.class), any(PostStatus.class), any(Pageable.class) - )).willReturn(testPage); - - // when - Page res = postService.getContestsBySearchWord("createdAt", searchWord, pageable); - - // then - assertThat(res).isNotNull(); - assertThat(res.getTotalElements()).isEqualTo(4); - assertThat(res.getTotalPages()).isEqualTo(1); - assertThat(res.getContent().get(0).title()).isEqualTo("제목4"); - assertThat(res.getContent().get(1).title()).isEqualTo("제목5"); - assertThat(res.getContent().get(2).title()).isEqualTo("제목6"); - } - - @Test - @DisplayName("공모전 공고 검색어 기반 조회 인기순") - void getContestsByScrapCount() { - // given - String searchWord = "제목"; - List testPosts = PostUtilTest.builderMultiplePosts(false); - testPosts.get(6).setScrapCount(10); // 제목7 - testPosts.get(5).setScrapCount(8); // 제목6 - testPosts.sort(Comparator.comparing(Post::getScrapCount) - .thenComparing(Post::getPostId).reversed()); - testPosts = testPosts.stream() - .filter(post -> post.getTitle().contains(searchWord)) - .collect(Collectors.toList()); - Pageable pageable = PageRequest.of(0, 6); - Page testPage = new PageImpl<>(testPosts, pageable, testPosts.size()); // Page 생성 - - given(postRepository.findAllByTitleContainsAndPostTypeFalseAndDeletedAtIsNullAndFinishDateAfterAndStatusOrderByScrapCountDescPostIdDesc( - any(String.class), any(LocalDateTime.class), any(PostStatus.class), any(Pageable.class) - )).willReturn(testPage); - - // when - Page res = postService.getContestsBySearchWord("scrapCount", searchWord, pageable); - - // then - assertThat(res).isNotNull(); - assertThat(res.getTotalElements()).isEqualTo(4); - assertThat(res.getTotalPages()).isEqualTo(1); - assertThat(res.getContent().get(0).title()).isEqualTo("제목7"); - assertThat(res.getContent().get(1).title()).isEqualTo("제목6"); - assertThat(res.getContent().get(2).title()).isEqualTo("제목5"); - } - } - - @Nested - @DisplayName("공모전 공고 검색어, 지역, 스택 기반 기반 조회") - class ContestTestsWithMeetingAreaAndCategoryAndSearchWord { - @Test - @DisplayName("공모전 공고 검색어 기반 조회 최신순") - void getContestsByCreatedAt() { - // given - String searchWord = "제목"; - String meetingCity = "서울시"; - String meetingTown = "마포구"; - String category = "BE"; - List testPosts = PostUtilTest.builderMultiplePosts(false); - testPosts = testPosts.stream() - .filter(post -> post.getTitle().contains(searchWord) && - post.getMeetingCity().contains(meetingCity) && - post.getMeetingTown().contains(meetingTown) && - post.getCategories().stream() - .map(Category::getCategoryType) - .anyMatch(catType -> String.valueOf(catType).contains(category))) - .collect(Collectors.toList()); - Pageable pageable = PageRequest.of(0, 6); - Page testPage = new PageImpl<>(testPosts, pageable, testPosts.size()); - - given(postRepository.findAllPostsJoinedWithCategoriesByTitleContainsAndPostTypeFalseAndDeletedAtIsNullAndFinishDateAfterAndStatusAndMeetingCityContainsAndMeetingTownContainsAndCategoriesCategoryTypeContainsOrderByPostIdDesc( - any(String.class), any(LocalDateTime.class), any(PostStatus.class), any(String.class), any(String.class), any(String.class), any(Pageable.class) - )).willReturn(testPage); - - // when - Page res = postService.getContestsByMeetingAreaAndCategoryAndSearchWord("createdAt", meetingCity, meetingTown, category, searchWord, pageable); - - // then - assertThat(res).isNotNull(); - assertThat(res.getTotalElements()).isEqualTo(2); - assertThat(res.getTotalPages()).isEqualTo(1); - assertThat(res.getContent().get(0).title()).isEqualTo("제목4"); - assertThat(res.getContent().get(1).title()).isEqualTo("제목5"); - } - - @Test - @DisplayName("공모전 공고 검색어 기반 조회 인기순") - void getContestsByScrapCount() { - // given - String searchWord = "제목"; - String meetingCity = "서울시"; - String meetingTown = "마포구"; - String category = "BE"; - List testPosts = PostUtilTest.builderMultiplePosts(true); - testPosts.get(4).setScrapCount(10); // 제목7 - testPosts.get(3).setScrapCount(8); // 제목6 - testPosts.sort(Comparator.comparing(Post::getScrapCount) - .thenComparing(Post::getPostId).reversed()); - testPosts = testPosts.stream() - .filter(post -> post.getTitle().contains(searchWord) && - post.getMeetingCity().contains(meetingCity) && - post.getMeetingTown().contains(meetingTown) && - post.getCategories().stream() - .map(Category::getCategoryType) - .anyMatch(catType -> String.valueOf(catType).contains(category))) - .collect(Collectors.toList()); - Pageable pageable = PageRequest.of(0, 6); - Page testPage = new PageImpl<>(testPosts, pageable, testPosts.size()); - - given(postRepository.findAllPostsJoinedWithCategoriesByTitleContainsAndPostTypeFalseAndDeletedAtIsNullAndFinishDateAfterAndStatusAndMeetingCityContainsAndMeetingTownContainsAndCategoriesCategoryTypeContainsOrderByScrapCountDescPostIdDesc( - any(String.class), any(LocalDateTime.class), any(PostStatus.class), any(String.class), any(String.class), any(String.class), any(Pageable.class) - )).willReturn(testPage); - - // when - Page res = postService.getContestsByMeetingAreaAndCategoryAndSearchWord("scrapCount", meetingCity, meetingTown, category, searchWord, pageable); - - // then - assertThat(res).isNotNull(); - assertThat(res.getTotalElements()).isEqualTo(2); - assertThat(res.getTotalPages()).isEqualTo(1); - assertThat(res.getContent().get(0).title()).isEqualTo("제목5"); - assertThat(res.getContent().get(1).title()).isEqualTo("제목4"); - } - - } - } - - @Nested - @DisplayName("공고 스크랩 테스트") - class scrapTests { - - @Test - @DisplayName("공고 스크랩 저장 및 취소 기능") - void scrapPost() { - // Given - Member member = MemberUtilTest.buildMemberAndId(1L); - Post post = PostUtilTest.builderPost(1L, member); - PostScrap postScrap = PostUtilTest.builderPostScrap(post, member, true); - - given(postRepository.findByPostIdAndDeletedAtIsNull(any(Long.class))) - .willReturn(Optional.of(post)); - given(postScrapRepository.findByPostAndMember(any(Post.class), any(Member.class))) - .willReturn(null) - .willReturn(postScrap); - - // When - PostScrapRes res = postService.scrapPost(member, post.getPostId()); - - // Then - PostScrap savedPostScrap = postScrapRepository.findByPostAndMember(post, member); - assertThat(savedPostScrap).isNotNull(); - - assertThat(res).isNotNull(); - assertThat(res.postId()).isEqualTo(1L); - assertThat(res.memberId()).isEqualTo(member.getMemberId()); - assertThat(res.scrapStatus()).isTrue(); - assertThat(savedPostScrap.getPost().getScrapCount()).isEqualTo(1); - - // given - given(postScrapRepository.findByPostAndMember(any(Post.class), any(Member.class))) - .willReturn(savedPostScrap); - - // When - res = postService.scrapPost(member, post.getPostId()); - - // Then - PostScrap canceledPostScrap = postScrapRepository.findByPostAndMember(post, member); - assertThat(canceledPostScrap).isNotNull(); - - assertThat(res.scrapStatus()).isFalse(); - assertThat(canceledPostScrap.getPost().getScrapCount()).isEqualTo(0); - } - - @Test - @DisplayName("공고 스크랩 조회 기능") - void scrapGet() { - // Given - Member member = MemberUtilTest.buildMemberAndId(1L); - Post post = PostUtilTest.builderPost(1L, member); - PostScrap postScrap = PostUtilTest.builderPostScrap(post, member, true); - - given(postRepository.findByPostIdAndDeletedAtIsNull(any(Long.class))) - .willReturn(Optional.of(post)); - given(postScrapRepository.findByPostAndMember(any(Post.class), any(Member.class))) - .willReturn(null) - .willReturn(postScrap); - - // When - PostScrapRes res = postService.scrapPost(member, post.getPostId()); - PostScrap getPostScrap = postScrapRepository.findByPostAndMember(post, member); - - // Then - assertThat(getPostScrap).isNotNull(); - assertThat(res).isNotNull(); - assertThat(res.postId()).isEqualTo(1L); - assertThat(res.memberId()).isEqualTo(member.getMemberId()); - assertThat(res.scrapStatus()).isTrue(); - assertThat(getPostScrap.getPost().getScrapCount()).isEqualTo(1); - } - - @Test - @DisplayName("내가 스크랩한 프로젝트 목록 조회 및 페이지네이션 기능 테스트") - void getMyScrapProjectTest() { - // given - Member member = MemberUtilTest.buildMemberAndId(1L); - List testPosts = PostUtilTest.builderMultiplePosts(false); - List testPostScraps= PostScrapUtilTest.builderMultiplePostScraps(testPosts, member).stream() - .filter(PostScrap::getScrapStatus) - .collect(Collectors.toList()); - Pageable pageable = PageRequest.of(0, 6); - Page testPage = new PageImpl<>(testPostScraps, pageable, testPostScraps.size()); // Page 생성 - - - given(postScrapRepository.findAllByMemberAndPostPostTypeTrueAndPostDeletedAtIsNullAndScrapStatusTrueOrderByPostScrapIdDesc( - any(Member.class), any(Pageable.class) - )).willReturn(testPage); - - // when - Page res = postService.getMyScrapProject(member, pageable); - - // then - assertThat(res).isNotNull(); - assertThat(res.getTotalElements()).isEqualTo(7); - assertThat(res.getTotalPages()).isEqualTo(2); - assertThat(res.getContent().get(0).title()).isEqualTo("Title1"); - assertThat(res.getContent().get(1).title()).isEqualTo("Title2"); - assertThat(res.getContent().get(2).title()).isEqualTo("Title3"); - } - - @Test - @DisplayName("내가 스크랩한 공모전 목록 조회 및 페이지네이션 기능 테스트") - void getMyScrapContestTest() { - // given - Member member = MemberUtilTest.buildMemberAndId(1L); - List testPosts = PostUtilTest.builderMultiplePosts(false); - List testPostScraps= PostScrapUtilTest.builderMultiplePostScraps(testPosts, member).stream() - .filter(PostScrap::getScrapStatus) - .collect(Collectors.toList()); - Pageable pageable = PageRequest.of(0, 6); - Page testPage = new PageImpl<>(testPostScraps, pageable, testPostScraps.size()); // Page 생성 - - - given(postScrapRepository.findAllByMemberAndPostPostTypeFalseAndPostDeletedAtIsNullAndScrapStatusTrueOrderByPostScrapIdDesc( - any(Member.class), any(Pageable.class) - )).willReturn(testPage); - - // when - Page res = postService.getMyScrapContest(member, pageable); - - // then - assertThat(res).isNotNull(); - assertThat(res.getTotalElements()).isEqualTo(7); - assertThat(res.getTotalPages()).isEqualTo(2); - assertThat(res.getContent().get(0).title()).isEqualTo("Title1"); - assertThat(res.getContent().get(1).title()).isEqualTo("Title2"); - assertThat(res.getContent().get(2).title()).isEqualTo("Title3"); - } - } -} diff --git a/src/test/java/com/gongjakso/server/domain/post/service/PostServiceTest.java b/src/test/java/com/gongjakso/server/domain/post/service/PostServiceTest.java deleted file mode 100644 index 328fdb30..00000000 --- a/src/test/java/com/gongjakso/server/domain/post/service/PostServiceTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.gongjakso.server.domain.post.service; - -import com.gongjakso.server.domain.post.entity.Post; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; - -@SpringBootTest -class PostServiceTest { - - @MockBean - PostService postService; - Post post = null; - - @BeforeEach - void beforeEach() { - - } - - @Test - void create() { - - } - - @Test - void read() { - } - - @Test - void modify() { - } - - @Test - void delete() { - - } -} \ No newline at end of file diff --git a/src/test/java/com/gongjakso/server/domain/post/util/PostScrapUtilTest.java b/src/test/java/com/gongjakso/server/domain/post/util/PostScrapUtilTest.java deleted file mode 100644 index 87912db1..00000000 --- a/src/test/java/com/gongjakso/server/domain/post/util/PostScrapUtilTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.gongjakso.server.domain.post.util; - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.post.dto.PostScrapRes; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.PostScrap; - -import java.util.List; -import java.util.stream.Collectors; - -public class PostScrapUtilTest { - public static PostScrap builderPostScrap(Post post, Member member) { - return new PostScrap( - post, - member, - true - ); - } - - public static List builderMultiplePostScraps(List posts, Member member){ - return posts.stream() - .map(post -> new PostScrap(post, member, true)) - .collect(Collectors.toList()); - } - - - public static PostScrap builderPostScrapWithPostAndMember(Long PostScrapId, Post post, Member member) { - return new PostScrap( - PostScrapId, - post, - member, - true - ); - } - - public static PostScrapRes ScrapPostRes(Long postId, Long memberId, boolean scrapStatus){ - return PostScrapRes.builder() - .postId(postId) - .memberId(memberId) - .scrapStatus(scrapStatus) - .build(); - } -} diff --git a/src/test/java/com/gongjakso/server/domain/post/util/PostUtilTest.java b/src/test/java/com/gongjakso/server/domain/post/util/PostUtilTest.java deleted file mode 100644 index 8cf2ec5d..00000000 --- a/src/test/java/com/gongjakso/server/domain/post/util/PostUtilTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.gongjakso.server.domain.post.util; - -import com.gongjakso.server.domain.member.entity.Member; -import com.gongjakso.server.domain.member.util.MemberUtilTest; -import com.gongjakso.server.domain.post.entity.Category; -import com.gongjakso.server.domain.post.entity.Post; -import com.gongjakso.server.domain.post.entity.PostScrap; -import com.gongjakso.server.domain.post.enumerate.MeetingMethod; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class PostUtilTest { - public static Post builderPost(Long id, Member member){ - return new Post( - id, - "Title1", - member, - "Content1", - "Link1", - LocalDateTime.now(), - LocalDateTime.now().plusDays(10), - LocalDateTime.now().plusDays(16), - 8L, - MeetingMethod.ONLINE, - "서울시", - "마포구", - true, - ".com", - false, - new ArrayList<>(), - new ArrayList<>() - ); - } - - public static Post builderPosts(Long id, String title, String contents, String link, Boolean postType) { - Member member = MemberUtilTest.buildMember(); - - return new Post( - id, - title, - member, - contents, - link, - LocalDateTime.now(), - LocalDateTime.now().plusDays(10), - LocalDateTime.now().plusDays(16), - 8L, - MeetingMethod.ONLINE, - "서울시", - "마포구", - true, - ".com", - postType, - new ArrayList<>(), - new ArrayList<>() - ); - } - - public static List builderMultiplePosts(Boolean postType) { - List postList = Arrays.asList( - builderPosts(1L, "Title1", "Content1", "Link1", postType), - builderPosts(2L, "Title2", "Content2", "Link2", postType), - builderPosts(3L, "Title3", "Content3", "Link3", postType), - builderPosts(4L, "제목4", "Content4", "Link4", postType), - builderPosts(5L, "제목5", "Content5", "Link5", postType), - builderPosts(6L, "제목6", "Content6", "Link6", postType), - builderPosts(7L, "제목7", "Content7", "Link7", postType) - ); - - createCategories(postList.get(3)); - createCategories(postList.get(4)); - - return postList; - } - public static void createCategories(Post post) { - Category category1 = new Category(post, "PLAN", 1); - Category category2 = new Category(post, "BE", 4); - Category category3 = new Category(post, "ETC", 5); - - post.setCategories(Arrays.asList(category1, category2, category3)); - } - - public static PostScrap builderPostScrap(Post post, Member member, Boolean postStatus){ - return new PostScrap( - post, - member, - postStatus - ); - } -} From f287d55c47d045491a1244a660236e6bf6df28cb Mon Sep 17 00:00:00 2001 From: dl-00-e8 Date: Thu, 15 Aug 2024 14:29:59 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[#173]=20chore:=20QueryDSL=20generated=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20gitignore=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 858efd81..48e4f2a3 100644 --- a/.gitignore +++ b/.gitignore @@ -135,4 +135,7 @@ prometheus.yml **/application-prod.yml __default__.tmpl -grafana.db \ No newline at end of file +grafana.db + +# QueryDSL +/src/main/generated/ \ No newline at end of file From f65ad03eff9af13bcafd084bc6269ce5c7c6c922 Mon Sep 17 00:00:00 2001 From: dl-00-e8 Date: Thu, 15 Aug 2024 14:30:22 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[#173]=20refactor:=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=82=AC=ED=95=AD=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EC=B6=98=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EB=B0=8F=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20DTO=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/banner/dto/response/BannerRes.java | 2 +- .../server/domain/banner/entity/Banner.java | 6 ++-- .../server/domain/contest/entity/Contest.java | 18 +++++++++-- .../domain/email/dto/response/EmailRes.java | 2 +- .../server/domain/email/entity/Email.java | 6 ++-- .../server/domain/member/dto/LoginRes.java | 2 +- .../server/domain/member/dto/MemberRes.java | 2 +- .../server/domain/member/entity/Member.java | 8 ++--- .../domain/portfolio/entity/Portfolio.java | 21 ++++++++++++ .../server/domain/team/entity/Apply.java | 32 +++++++++++++++++++ .../server/domain/team/entity/Scrap.java | 32 +++++++++++++++++++ .../server/domain/team/entity/Team.java | 22 +++++++++++++ 12 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/gongjakso/server/domain/portfolio/entity/Portfolio.java create mode 100644 src/main/java/com/gongjakso/server/domain/team/entity/Apply.java create mode 100644 src/main/java/com/gongjakso/server/domain/team/entity/Scrap.java create mode 100644 src/main/java/com/gongjakso/server/domain/team/entity/Team.java diff --git a/src/main/java/com/gongjakso/server/domain/banner/dto/response/BannerRes.java b/src/main/java/com/gongjakso/server/domain/banner/dto/response/BannerRes.java index 197ffe1a..93984a46 100644 --- a/src/main/java/com/gongjakso/server/domain/banner/dto/response/BannerRes.java +++ b/src/main/java/com/gongjakso/server/domain/banner/dto/response/BannerRes.java @@ -18,7 +18,7 @@ public record BannerRes( public static BannerRes of(Banner banner) { return BannerRes.builder() - .bannerId(banner.getBannerId()) + .bannerId(banner.getId()) .domainType(banner.getDomainType()) .imageUrl(banner.getImageUrl()) .linkUrl(banner.getLinkUrl()) diff --git a/src/main/java/com/gongjakso/server/domain/banner/entity/Banner.java b/src/main/java/com/gongjakso/server/domain/banner/entity/Banner.java index 6c329676..aa1d3b29 100644 --- a/src/main/java/com/gongjakso/server/domain/banner/entity/Banner.java +++ b/src/main/java/com/gongjakso/server/domain/banner/entity/Banner.java @@ -13,14 +13,14 @@ @Getter @Entity @Table(name = "banner") -@SQLDelete(sql = "UPDATE banner SET deleted_at = NOW() where banner_id = ?") +@SQLDelete(sql = "UPDATE banner SET deleted_at = NOW() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Banner extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "banner_id", nullable = false, columnDefinition = "bigint") - private Long bannerId; + @Column(name = "id", nullable = false, columnDefinition = "bigint") + private Long id; @Column(name = "domain_type", columnDefinition = "varchar(100)") @Enumerated(EnumType.STRING) diff --git a/src/main/java/com/gongjakso/server/domain/contest/entity/Contest.java b/src/main/java/com/gongjakso/server/domain/contest/entity/Contest.java index 96f827a3..b38721ba 100644 --- a/src/main/java/com/gongjakso/server/domain/contest/entity/Contest.java +++ b/src/main/java/com/gongjakso/server/domain/contest/entity/Contest.java @@ -1,33 +1,45 @@ package com.gongjakso.server.domain.contest.entity; +import com.gongjakso.server.global.common.BaseTimeEntity; import jakarta.persistence.*; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; import java.time.LocalDate; + @Getter -@NoArgsConstructor @Entity @Table(name = "contest") -public class Contest { +@SQLDelete(sql = "UPDATE contest SET deleted_at = NOW() where contest_id = ?") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Contest extends BaseTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "contest_id",nullable = false,columnDefinition = "bigint") + @Column(name = "id", nullable = false, columnDefinition = "bigint") private Long id; @Column(name = "title",nullable = false,columnDefinition = "varchar(150)") private String title; + @Column(name = "body",columnDefinition = "text") private String body; + @Column(name = "contest_link",columnDefinition = "text") private String contestLink; + @Column(name = "institution",columnDefinition = "varchar(100)") private String institution; + @Column(name = "started_at",columnDefinition = "timestamp") private LocalDate startedAt; + @Column(name = "finished_at",columnDefinition = "timestamp") private LocalDate finishedAt; + @Column(name = "img_url",columnDefinition = "text") private String imgUrl; diff --git a/src/main/java/com/gongjakso/server/domain/email/dto/response/EmailRes.java b/src/main/java/com/gongjakso/server/domain/email/dto/response/EmailRes.java index ba962270..1c0b852d 100644 --- a/src/main/java/com/gongjakso/server/domain/email/dto/response/EmailRes.java +++ b/src/main/java/com/gongjakso/server/domain/email/dto/response/EmailRes.java @@ -14,7 +14,7 @@ public record EmailRes( public static EmailRes of(Email email) { return EmailRes.builder() - .emailId(email.getEmailId()) + .emailId(email.getId()) .address(email.getAddress()) .isReceive(email.getIsReceive()) .build(); diff --git a/src/main/java/com/gongjakso/server/domain/email/entity/Email.java b/src/main/java/com/gongjakso/server/domain/email/entity/Email.java index dcfccf07..65f5b0cf 100644 --- a/src/main/java/com/gongjakso/server/domain/email/entity/Email.java +++ b/src/main/java/com/gongjakso/server/domain/email/entity/Email.java @@ -11,14 +11,14 @@ @Getter @Entity @Table(name = "email") -@SQLDelete(sql = "UPDATE email SET deleted_at = NOW() where email_id = ?") +@SQLDelete(sql = "UPDATE email SET deleted_at = NOW() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Email extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "email_id", nullable = false, columnDefinition = "bigint") - private Long emailId; + @Column(name = "id", nullable = false, columnDefinition = "bigint") + private Long id; @Column(name = "address", nullable = false, columnDefinition = "text") private String address; diff --git a/src/main/java/com/gongjakso/server/domain/member/dto/LoginRes.java b/src/main/java/com/gongjakso/server/domain/member/dto/LoginRes.java index 34a91274..c2c1bafe 100644 --- a/src/main/java/com/gongjakso/server/domain/member/dto/LoginRes.java +++ b/src/main/java/com/gongjakso/server/domain/member/dto/LoginRes.java @@ -26,7 +26,7 @@ public record LoginRes( ) { public static LoginRes of(Member member, TokenDto tokenDto) { return LoginRes.builder() - .memberId(member.getMemberId()) + .memberId(member.getId()) .email(member.getEmail()) .name(member.getName()) .phone(member.getPhone()) diff --git a/src/main/java/com/gongjakso/server/domain/member/dto/MemberRes.java b/src/main/java/com/gongjakso/server/domain/member/dto/MemberRes.java index d4a20613..ecf45302 100644 --- a/src/main/java/com/gongjakso/server/domain/member/dto/MemberRes.java +++ b/src/main/java/com/gongjakso/server/domain/member/dto/MemberRes.java @@ -24,7 +24,7 @@ public record MemberRes( public static MemberRes of(Member member) { return MemberRes.builder() - .memberId(member.getMemberId()) + .memberId(member.getId()) .email(member.getEmail()) .name(member.getName()) .phone(member.getPhone()) diff --git a/src/main/java/com/gongjakso/server/domain/member/entity/Member.java b/src/main/java/com/gongjakso/server/domain/member/entity/Member.java index 295503a8..1ccb095f 100644 --- a/src/main/java/com/gongjakso/server/domain/member/entity/Member.java +++ b/src/main/java/com/gongjakso/server/domain/member/entity/Member.java @@ -14,14 +14,14 @@ @Getter @Entity @Table(name = "member") -@SQLDelete(sql = "UPDATE member SET deleted_at = NOW() where member_id = ?") +@SQLDelete(sql = "UPDATE member SET deleted_at = NOW() where id = ?") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Member extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "member_id", nullable = false, columnDefinition = "bigint") - private Long memberId; + @Column(name = "id", nullable = false, columnDefinition = "bigint") + private Long id; // 이메일은 최대 255자 + 1자(@) + 69자해서 최대 320글자이므로, varchar(320) 사용 @Column(name = "email", nullable = false, columnDefinition = "varchar(320)") @@ -79,7 +79,7 @@ public Member(String email, String password, String name, String phone, String p } public Member(Long id, String email, String password, String name, String phone, String profileUrl, String memberType, String loginType, String status, String major, String job){ - this.memberId = id; + this.id = id; this.email = email; this.password = password; this.name = name; diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/entity/Portfolio.java b/src/main/java/com/gongjakso/server/domain/portfolio/entity/Portfolio.java new file mode 100644 index 00000000..29097334 --- /dev/null +++ b/src/main/java/com/gongjakso/server/domain/portfolio/entity/Portfolio.java @@ -0,0 +1,21 @@ +package com.gongjakso.server.domain.portfolio.entity; + +import com.gongjakso.server.global.common.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; + +@Getter +@Entity +@Table(name = "portfolio") +@SQLDelete(sql = "UPDATE portfolio SET deleted_at = NOW() where id = ?") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Portfolio extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id",nullable = false,columnDefinition = "bigint") + private Long id; +} diff --git a/src/main/java/com/gongjakso/server/domain/team/entity/Apply.java b/src/main/java/com/gongjakso/server/domain/team/entity/Apply.java new file mode 100644 index 00000000..fa9b731e --- /dev/null +++ b/src/main/java/com/gongjakso/server/domain/team/entity/Apply.java @@ -0,0 +1,32 @@ +package com.gongjakso.server.domain.team.entity; + +import com.gongjakso.server.global.common.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; + +@Getter +@Entity +@Table(name = "apply") +@SQLDelete(sql = "UPDATE apply SET deleted_at = NOW() where id = ?") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Apply extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false, columnDefinition = "bigint") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_id", nullable = false, columnDefinition = "bigint") + private Team team; + + + @Builder + public Apply(Team team){ + this.team = team; + } +} diff --git a/src/main/java/com/gongjakso/server/domain/team/entity/Scrap.java b/src/main/java/com/gongjakso/server/domain/team/entity/Scrap.java new file mode 100644 index 00000000..ea2c3dbe --- /dev/null +++ b/src/main/java/com/gongjakso/server/domain/team/entity/Scrap.java @@ -0,0 +1,32 @@ +package com.gongjakso.server.domain.team.entity; + +import com.gongjakso.server.global.common.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; + +@Getter +@Entity +@Table(name = "scrap") +@SQLDelete(sql = "UPDATE scrap SET deleted_at = NOW() where id = ?") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Scrap extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false, columnDefinition = "bigint") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_id", nullable = false) + private Team team; + + + @Builder + public Scrap(Team team){ + this.team = team; + } +} diff --git a/src/main/java/com/gongjakso/server/domain/team/entity/Team.java b/src/main/java/com/gongjakso/server/domain/team/entity/Team.java new file mode 100644 index 00000000..576bc653 --- /dev/null +++ b/src/main/java/com/gongjakso/server/domain/team/entity/Team.java @@ -0,0 +1,22 @@ +package com.gongjakso.server.domain.team.entity; + +import com.gongjakso.server.global.common.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; + +@Getter +@Entity +@Table(name = "team") +@SQLDelete(sql = "UPDATE team SET deleted_at = NOW() where id = ?") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Team extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", nullable = false, columnDefinition = "bigint") + private Long id; + +} \ No newline at end of file