Skip to content

Commit

Permalink
Merge pull request #92 from Gongjakso/feat/postModified
Browse files Browse the repository at this point in the history
fix: post 코드 리팩토링
  • Loading branch information
yumzen authored Apr 13, 2024
2 parents 4848586 + f6216d6 commit 3d74a9d
Show file tree
Hide file tree
Showing 21 changed files with 738 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import java.util.List;

public interface ApplyRepository extends JpaRepository<Apply,Long> {
long countApplyWithStackNameUsingFetchJoinByPost(Post post);
long countApplyByPost(Post post);
boolean existsApplyByMemberAndPost(Member member,Post post);
Page<Apply> findAllByPost(Post post, Pageable pageable);
Page<Apply> findApplyByApplyType(ApplyType applyType, Pageable pageable);
List<Apply> findAllByMemberAndDeletedAtIsNull(Member member);
}
List<Apply> findAllByPost(Post post);
Long findApplyIdByMemberAndPost(Member member,Post post);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Optional;
import java.util.List;
import java.util.stream.Collectors;

import static com.gongjakso.server.domain.post.enumerate.PostStatus.RECRUITING;
import static com.gongjakso.server.global.exception.ErrorCode.NOT_FOUND_POST_EXCEPTION;

@Service
@Transactional
Expand Down Expand Up @@ -249,4 +251,33 @@ public List<MyPageRes> getMyApplyList(Member member) {
})
.collect(Collectors.toList());
}

public Long getApplicantApplyId(Long memberId, Long postId) {
Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId);

if (post == null) {
throw new ApplicationException(NOT_FOUND_POST_EXCEPTION);
}

List<Apply> applyList = applyRepository.findAllByPost(post);

// 지원자 목록에 해당 멤버가 포함되어 있는지 확인하고 해당하는 apply의 id를 반환
Optional<Apply> applicantApply = applyList.stream()
.filter(apply -> memberId.equals(apply.getMember().getMemberId()))
.findFirst();

return applicantApply.map(Apply::getApplyId)
.orElse(null);
}

public ApplicationRes getMyApplication(Member member, Long postId){
Post post = postRepository.findWithStackNameAndCategoryUsingFetchJoinByPostId(postId);

if (post == null) {
throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION);
}else{
Long applyId = applyRepository.findApplyIdByMemberAndPost(member, post);
return findApplication(member, applyId, postId);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ public ApplicationResponse<PostDeleteRes> delete(@AuthenticationPrincipal Princi
public ApplicationResponse<Page<GetContestRes>> contestList(@PageableDefault(size = 6) Pageable pageable,
@RequestParam(value = "searchWord", required = false) String searchWord,
@RequestParam(value = "category", required = false) String category,
@RequestParam(value = "meetingArea", required = false) String meetingArea,
@RequestParam(value = "meetingCity", required = false) String meetingCity,
@RequestParam(value = "meetingTown", required = false) String meetingTown,
@RequestParam(value = "sort", required = false) String sort) {
if(category.isBlank() && meetingArea.isBlank()){
if(category.isBlank() && meetingCity.isBlank()){
if(searchWord.isBlank()){
return ApplicationResponse.ok(postService.getContests(sort, pageable));
}else {
return ApplicationResponse.ok(postService.getContestsBySearchWord(sort, searchWord, pageable));
}
}else {
return ApplicationResponse.ok(postService.getContestsByMeetingAreaAndCategoryAndSearchWord(sort, meetingArea, category, searchWord, pageable));
return ApplicationResponse.ok(postService.getContestsByMeetingAreaAndCategoryAndSearchWord(sort, meetingCity, meetingTown, category, searchWord, pageable));
}
}

Expand All @@ -69,16 +70,17 @@ public ApplicationResponse<Page<GetContestRes>> contestList(@PageableDefault(siz
public ApplicationResponse<Page<GetProjectRes>> projectList(@PageableDefault(size = 6) Pageable pageable,
@RequestParam(value = "searchWord", required = false) String searchWord,
@RequestParam(value = "stackName", required = false) String stackName,
@RequestParam(value = "meetingArea", required = false) String meetingArea,
@RequestParam(value = "meetingCity", required = false) String meetingCity,
@RequestParam(value = "meetingTown", required = false) String meetingTown,
@RequestParam(value = "sort", required = false) String sort) {
if(stackName.isBlank() && meetingArea.isBlank()){
if(stackName.isBlank() && meetingCity.isBlank()){
if(searchWord.isBlank()){
return ApplicationResponse.ok(postService.getProjects(sort, pageable));
}else {
return ApplicationResponse.ok(postService.getProjectsBySearchWord(sort, searchWord, pageable));
}
}else {
return ApplicationResponse.ok(postService.getProjectsByMeetingAreaAndStackNameAndSearchWord(sort, meetingArea, stackName, searchWord, pageable));
return ApplicationResponse.ok(postService.getProjectsByMeetingAreaAndStackNameAndSearchWord(sort, meetingCity, meetingTown, stackName, searchWord, pageable));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
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
){}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gongjakso.server.domain.post.entity.Category;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

import java.time.LocalDateTime;
Expand All @@ -11,15 +12,57 @@

@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<Category> categories,

@Schema(
description = "공고 스크랩 수, 스크랩 수가 높을수록 인기순 우선순위",
defaultValue = "0"
)
long scrapCount
){ public static GetContestRes of(Post post){
return GetContestRes.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gongjakso.server.domain.post.entity.Category;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.enumerate.PostStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

import java.time.LocalDateTime;
Expand All @@ -11,15 +12,57 @@

@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<Category> categories,

@Schema(
description = "공고 스크랩 수, 스크랩 수가 높을수록 인기순 우선순위",
defaultValue = "0"
)
long scrapCount
){ public static GetProjectRes of(Post post){
return GetProjectRes.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

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){
Expand Down
Loading

0 comments on commit 3d74a9d

Please sign in to comment.