Skip to content

Commit

Permalink
Merge pull request #97 from Gongjakso/feat/apply
Browse files Browse the repository at this point in the history
Apply 코드 수정
  • Loading branch information
sycuuui authored Apr 9, 2024
2 parents a598d25 + f0192ff commit 5d48e56
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 230 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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;
Expand All @@ -21,21 +23,21 @@ public class ApplyController {
//지원 요청 api
@Operation(summary = "공고 지원 API", description = "팀 지원하기 모달창에서 지원 요청")
@PostMapping("/{post_id}")
public ApplicationResponse<Void> addApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestBody ApplyReq req){
public ApplicationResponse<Void> 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<ApplyRes> getApply(@PathVariable("post_id") Long postId){
return ApplicationResponse.ok(applyService.findApply(postId));
public ApplicationResponse<ApplyRes> 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<ApplyPageRes> getApplyList(@PathVariable("post_id") Long postId,@RequestParam(name = "page", defaultValue = "0") int page,@RequestParam(name = "size", defaultValue = "11") int size){
return ApplicationResponse.ok(applyService.applyListPage(postId,page,size));
public ApplicationResponse<ApplyPageRes> 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 = "내가 참여한 공고 정보")
Expand All @@ -47,31 +49,31 @@ public ApplicationResponse<ParticipationPageRes> getMyParticipationPostList(@Req
@Operation(summary = "지원서 열람 API", description = "내가 모집 중인 팀 페이지에서 지원서 열람 시")
@PatchMapping("/{apply_id}/open")
public ApplicationResponse<Void> updateIsOpenStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){
applyService.updateOpen(applyId);
applyService.updateState(principalDetails.getMember(),applyId, ApplyType.OPEN_APPLY);
return ApplicationResponse.ok();
}
//지원서 지원 요청 api
@Operation(summary = "합류하기 API", description = "합류하기 버튼 클릭 시")
@PatchMapping("/{apply_id}/recruit")
public ApplicationResponse<Void> updateIsRecruitStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){
applyService.updateRecruit(applyId,true);
applyService.updateState(principalDetails.getMember(),applyId,ApplyType.PASS);
return ApplicationResponse.ok();
}
//지원서 미선발 요청 api
@Operation(summary = "미선발 API", description = "미선발 버튼 클릭 시")
@PatchMapping("/{apply_id}/not-recruit")
public ApplicationResponse<Void> updateNotRecruitStatus(@PathVariable("apply_id") Long applyId){
applyService.updateRecruit(applyId,false);
public ApplicationResponse<Void> 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<ApplicationRes> findApplication(@PathVariable("apply_id") Long applyId,@PathVariable("post_id") Long postId){
return ApplicationResponse.ok(applyService.findApplication(applyId,postId));
public ApplicationResponse<ApplicationRes> 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 = "팀 지원하기 모달 창에서 카테고리들(지원 분야) 요청")
@Operation(summary = "지원시 뜨는 공고 정보 API", description = "팀 지원하기 모달 창에서 카테고리들(지원 분야) 요청")
@GetMapping("/{post_id}/category")
public ApplicationResponse<CategoryRes> getCategory(@PathVariable("post_id") Long postId){
return ApplicationResponse.ok(applyService.findPostCategory(postId));
Expand All @@ -80,21 +82,21 @@ public ApplicationResponse<CategoryRes> getCategory(@PathVariable("post_id") Lon
@Operation(summary = "공고 마감 API", description = "내가 모집 중인 팀 페이지에서 공고 마감 버튼 클릭시")
@PatchMapping("/{post_id}/close")
public ApplicationResponse<Void> updatePostStatusToClose(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){
applyService.updatePostState(postId,"close");
applyService.updatePostState(principalDetails.getMember(),postId, PostStatus.CLOSE);
return ApplicationResponse.ok();
}
//공고 취소 요청 api
@Operation(summary = "공고 취소 API", description = "내가 모집 중인 팀 페이지에서 공고 취소 버튼 클릭시")
@PatchMapping("/{post_id}/cancel")
public ApplicationResponse<Void> updatePostStatusToCancel(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){
applyService.updatePostState(postId,"cancel");
applyService.updatePostState(principalDetails.getMember(),postId, PostStatus.CLOSE);
return ApplicationResponse.ok();
}
//공고 기간 연장 요청 api
@Operation(summary = "공고 연장 API", description = "내가 모집 중인 팀 페이지에서 공고 연장 버튼 클릭시")
@PatchMapping("/{post_id}/extension")
public ApplicationResponse<Void> updatePostPeriod(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestBody PeriodReq req){
applyService.updatePostPeriod(postId,req);
applyService.updatePostPeriod(principalDetails.getMember(),postId,req);
return ApplicationResponse.ok();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
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.StackType;
import jakarta.validation.constraints.Null;
import lombok.Builder;

import java.util.List;

@Builder
public record ApplicationRes(
Boolean is_decision,
ApplyType applyType,
String major,
String application,
String recruit_part,
List<String> category,
String recruit_role,
List<String> stackName
@JsonInclude(JsonInclude.Include.NON_NULL)
List<String> postStack,
@Null
@JsonInclude(JsonInclude.Include.NON_NULL)
List<StackType> myStack

) {
public static ApplicationRes of(Apply apply, List<String> category,List<String> stackName){
return new ApplicationRes(apply.getIsDecision(),apply.getApplication(), apply.getRecruit_part(), category, apply.getRecruit_role(), stackName);
return new ApplicationRes(apply.getApplyType(),apply.getMember().getMajor(),apply.getApplication(), apply.getRecruit_part(), category, stackName,apply.getStackTypeList());
}
}
61 changes: 45 additions & 16 deletions src/main/java/com/gongjakso/server/domain/apply/dto/ApplyReq.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
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.apply.enumerate.StackType;
import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.entity.StackName;
import com.gongjakso.server.global.exception.ApplicationException;
import com.gongjakso.server.global.exception.ErrorCode;
import jakarta.validation.constraints.Null;

import java.util.ArrayList;
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public record ApplyReq(
String application,
String recruit_part,
String recruit_role,
String type,
Boolean isPass,
Boolean is_open,
Boolean isDecision
String applyType,
@Null
List<String> stack
) {
public Apply toEntity(Member member, Post post_id){
return Apply.builder()
.member(member)
.post(post_id)
.application(application)
.recruit_part(recruit_part)
.recruit_role(recruit_role)
.type(PostType.valueOf(type))
.isPass(false)
.is_open(false)
.isDecision(false)
.build();
public Apply toEntity(Member member, Post post){
if(type.equals("CONTEST")){
return Apply.builder()
.member(member)
.post(post)
.application(application)
.recruit_part(recruit_part)
.type(PostType.valueOf(type))
.applyType(ApplyType.NONE)
.build();
}else {
List<StackType> stackTypeList = new ArrayList<>();
for (String stackName : stack) {
try {
StackType stackType = StackType.valueOf(stackName.toUpperCase());
stackTypeList.add(stackType);
} catch (IllegalArgumentException e) {
throw new ApplicationException(ErrorCode.INVALID_STACK_TYPE_EXCEPTION);
}
}

return Apply.builder()
.member(member)
.post(post)
.application(application)
.recruit_part(recruit_part)
.type(PostType.valueOf(type))
.applyType(ApplyType.NONE)
.stackTypeList(stackTypeList)
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
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 max_person,
Long total_person,
int current_person,
Long max_person,
Boolean postType,
List<String> category,
List<String> stackName
List<String> category
) {
public static ApplyRes of(Post post, int current_person, List<String> category, List<String> stackName){
return new ApplyRes(post.getTitle(),post.getStartDate(),post.getEndDate(),post.getMaxPerson(),current_person,post.isPostType(), category, stackName);
public static ApplyRes of(Post post, int current_person, List<String> category){
return new ApplyRes(post.getTitle(),post.getStartDate(),post.getEndDate(),(post.getMaxPerson()+1),current_person,post.getMaxPerson(),post.isPostType(), category);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.gongjakso.server.domain.apply.dto;

import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.List;
public record CategoryRes(
List<String> category
List<String> category,
@JsonInclude(JsonInclude.Include.NON_NULL)
List<String> stack
) {
public static CategoryRes of(List<String> category,
List<String> stack){
return new CategoryRes(category,stack);
}
}
37 changes: 23 additions & 14 deletions src/main/java/com/gongjakso/server/domain/apply/entity/Apply.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
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.apply.enumerate.StackType;
import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.entity.StackName;
import com.gongjakso.server.global.common.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@Entity
Expand All @@ -32,32 +38,35 @@ public class Apply extends BaseTimeEntity {
@Column(name = "recruit_part",nullable = false,columnDefinition = "varchar(50)")
private String recruit_part;

@Column(name = "recruit_role",columnDefinition = "varchar(50)")
private String recruit_role;

@Enumerated(EnumType.STRING)
private PostType type;

@Column(name = "is_pass", columnDefinition = "boolean" )
private Boolean isPass;
@Enumerated(EnumType.STRING)
private ApplyType applyType;

@Column(name = "is_open", columnDefinition = "boolean" )
private Boolean is_open;
@Column(name = "stackTypeList")
private List<StackType> stackTypeList = new ArrayList<>();

@Column(name = "is_decision", columnDefinition = "boolean" )
private Boolean isDecision;
@Builder
public Apply(Long applyId, Member member,Post post,List<StackType> stackTypeList, String application,String recruit_part,PostType type, ApplyType applyType){
this.applyId=applyId;
this.member=member;
this.post=post;
this.stackTypeList=stackTypeList;
this.application=application;
this.recruit_part=recruit_part;
this.type=type;
this.applyType=applyType;
}

@Builder
public Apply(Long applyId, Member member,Post post, String application,String recruit_part,String recruit_role,PostType type, Boolean isPass,Boolean is_open,Boolean isDecision){
public Apply(Long applyId, Member member,Post post,String application,String recruit_part,PostType type, ApplyType applyType){
this.applyId=applyId;
this.member=member;
this.post=post;
this.application=application;
this.recruit_part=recruit_part;
this.recruit_role=recruit_role;
this.type=type;
this.isPass=isPass;
this.is_open=is_open;
this.isDecision=isDecision;
this.applyType=applyType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.gongjakso.server.domain.apply.enumerate;

public enum ApplyType {
NONE,OPEN_APPLY,NOT_PASS,PASS
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.gongjakso.server.domain.apply.enumerate;

public enum StackType {
REACT,TYPESCRIPT,JAVASCRIPT,NEXTJS,NODEJS,JAVA,SPRING,
KOTLIN,SWIFT,FLUTTER,ETC
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 org.springframework.data.domain.Page;
Expand All @@ -13,8 +14,6 @@ public interface ApplyRepository extends JpaRepository<Apply,Long> {
long countApplyByPost(Post post);
boolean existsApplyByMemberAndPost(Member member,Post post);
Page<Apply> findAllByPost(Post post, Pageable pageable);

Page<Apply> findApplyByIsPass(Boolean IsPass, Pageable pageable);

Page<Apply> findApplyByApplyType(ApplyType applyType, Pageable pageable);
List<Apply> findAllByMemberAndDeletedAtIsNull(Member member);
}
Loading

0 comments on commit 5d48e56

Please sign in to comment.