Skip to content

Commit

Permalink
Merge pull request #33 from Gongjakso/feat/apply
Browse files Browse the repository at this point in the history
Feat/apply
  • Loading branch information
dl-00-e8 authored Feb 6, 2024
2 parents 69b957a + 52d8eb8 commit 6dfaae6
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.gongjakso.server.domain.apply.controller;

import com.gongjakso.server.domain.apply.dto.ApplyReq;
import com.gongjakso.server.domain.apply.dto.ApplicationRes;
import com.gongjakso.server.domain.apply.dto.ApplyRes;
import com.gongjakso.server.domain.apply.dto.*;
import com.gongjakso.server.domain.apply.service.ApplyService;
import com.gongjakso.server.global.common.ApplicationResponse;
import com.gongjakso.server.global.security.PrincipalDetails;
Expand Down Expand Up @@ -44,8 +42,28 @@ public ApplicationResponse<Void> updateNotRecruitStatus(@AuthenticationPrincipal
return applyService.updateRecruit(applyId,false);
}
// 특정 지원자 지원서 가져오는 api
@GetMapping("/{apply_id}/application")
public ApplicationResponse<ApplicationRes> findApplication(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){
return applyService.findApplication(applyId);
@GetMapping("/{post_id}/{apply_id}/application")
public ApplicationResponse<ApplicationRes> findApplication(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId,@PathVariable("post_id") Long postId){
return applyService.findApplication(applyId,postId);
}
//공고 카테고리 요청 api
@GetMapping("/{post_id}/category")
public ApplicationResponse<CategoryRes> getCategory(@PathVariable("post_id") Long postId){
return applyService.findPostCategory(postId);
}
// //공고 마감 요청 api
// @PatchMapping("/{post_id}/close")
// public ApplicationResponse<Void> updatePostStatusToClose(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){
// return applyService.updatePostState(postId,"close");
// }
// //공고 취소 요청 api
// @PatchMapping("/{post_id}/cancel")
// public ApplicationResponse<Void> updatePostStatusToCancel(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){
// return applyService.updatePostState(postId,"cancel");
// }
//공고 기간 연장 요청 api
@PatchMapping("/{post_id}/extension")
public ApplicationResponse<Void> updatePostPeriod(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestBody PeriodReq req){
return applyService.updatePostPeriod(postId,req);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import com.gongjakso.server.domain.apply.entity.Apply;
import lombok.Builder;

import java.util.List;

@Builder
public record ApplicationRes(
Boolean is_decision,
String application,
String recruit_part
// String[] category
String recruit_part,
List<String> category
) {
public static ApplicationRes of(Apply apply){
return new ApplicationRes(apply.getApplication(), apply.getRecruit_part());
public static ApplicationRes of(Apply apply,List<String> category){
return new ApplicationRes(apply.getIs_decision(),apply.getApplication(), apply.getRecruit_part(),category);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@
public record ApplyReq(
String application,
String recruit_part,
String recruit_role,
String type,
Boolean is_pass,
Boolean is_open
Boolean is_open,
Boolean is_decision
) {
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))
.is_pass(false)
.is_open(false)
.is_decision(false)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.gongjakso.server.domain.apply.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.RequiredArgsConstructor;

import java.util.List;

public record CategoryRes(
List<String> category
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.gongjakso.server.domain.apply.dto;

public record PeriodReq(
int addDateNum
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ 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;

Expand All @@ -41,15 +44,20 @@ public class Apply extends BaseTimeEntity {
@Column(name = "is_open", columnDefinition = "boolean" )
private Boolean is_open;

@Column(name = "is_decision", columnDefinition = "boolean" )
private Boolean is_decision;

@Builder
public Apply(Long applyId, Member member,Post post, String application,String recruit_part,PostType type, Boolean is_pass,Boolean is_open){
public Apply(Long applyId, Member member,Post post, String application,String recruit_part,String recruit_role,PostType type, Boolean is_pass,Boolean is_open,Boolean is_decision){
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.is_pass=is_pass;
this.is_open=is_open;
this.is_decision=is_decision;
}
}
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.member.entity.Member;
import com.gongjakso.server.domain.post.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -9,4 +10,5 @@
public interface ApplyRepository extends JpaRepository<Apply,Long> {
long countApplyByPost(Post post);
List<Apply> findAllByPost(Post post);
boolean existsApplyByMemberAndPost(Member member,Post post);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.gongjakso.server.domain.apply.service;

import com.gongjakso.server.domain.apply.dto.ApplyList;
import com.gongjakso.server.domain.apply.dto.ApplyReq;
import com.gongjakso.server.domain.apply.dto.ApplicationRes;
import com.gongjakso.server.domain.apply.dto.ApplyRes;
import com.gongjakso.server.domain.apply.dto.*;
import com.gongjakso.server.domain.apply.entity.Apply;
import com.gongjakso.server.domain.apply.repository.ApplyRepository;
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.enumerate.CategoryType;
import com.gongjakso.server.domain.post.repository.CategoryRepository;
import com.gongjakso.server.domain.post.repository.PostRepository;
import com.gongjakso.server.global.common.ApplicationResponse;
import com.gongjakso.server.global.exception.ApplicationException;
import com.gongjakso.server.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import org.webjars.NotFoundException;

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

Expand All @@ -24,18 +28,29 @@
public class ApplyService {
private final ApplyRepository applyRepository;
private final PostRepository postRepository;
private final CategoryRepository categoryRepository;
public Apply save(Member member, Long post_id, ApplyReq req){
Post post = postRepository.findByPostId(post_id);
if (post == null) {
// Handle the case where the Post entity with the given post_id is not found
throw new NotFoundException("Post not found with id: " + post_id);
throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION);
}else {
//재지원 판단
if(!applyRepository.existsApplyByMemberAndPost(member, post)){
//지원 기간인지 판단
if(post.getEndDate().isBefore(LocalDateTime.now())){
throw new ApplicationException(ErrorCode.NOT_APPLY_EXCEPTION);
}else {
Apply apply = req.toEntity(member, post);
return applyRepository.save(apply);
}
}else {
throw new ApplicationException(ErrorCode.ALREADY_APPLY_EXCEPTION);
}
}
Apply apply = req.toEntity(member, post);
return applyRepository.save(apply);
}

public ApplicationResponse<ApplyRes> findApply(Long post_id){
Post post = postRepository.findById(post_id).orElseThrow(()->new NotFoundException("Post not found with id: " + post_id));
Post post = postRepository.findById(post_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION));
int current_person = (int) applyRepository.countApplyByPost(post);
List<Apply> applies = applyRepository.findAllByPost(post);
List<ApplyList> applyLists = applies.stream()
Expand All @@ -44,31 +59,109 @@ public ApplicationResponse<ApplyRes> findApply(Long post_id){
ApplyRes applyRes = ApplyRes.of(post,current_person,applyLists);
return ApplicationResponse.ok(applyRes);
}
public ApplicationResponse<CategoryRes> findPostCategory(Long post_id){
Post post = postRepository.findByPostId(post_id);
if (post == null) {
throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION);
}else {
List<Category> categoryList = categoryRepository.findCategoryByPost(post);
List<String> list = new ArrayList<>();
if(categoryList!=null){
for (Category category : categoryList){
for(int i=0;i<category.getSize();i++){
list.add(String.valueOf(category.getCategoryType()));
}
}
CategoryRes categoryRes = new CategoryRes(list);
return ApplicationResponse.ok(categoryRes);
}else {
throw new ApplicationException(ErrorCode.NOT_FOUND_CATEGORY_EXCEPTION);
}
}
}
private String decisionState(Apply apply){
if(apply.getIs_pass()) {
return "합류 완료";
if(apply.getIs_decision()){
if(apply.getIs_pass()) {
return "합류 완료";
}else {
return "미선발";
}
}else {
if(apply.getIs_open()){
return "열람 완료";
}else {
return "미선발";
return "미열람";
}
}

}
public ApplicationResponse<Void> updateOpen(Long apply_id){
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new NotFoundException("Apply not found with id: " + apply_id));
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION));
apply.setIs_open(true);
return ApplicationResponse.ok();
}
public ApplicationResponse<Void> updateRecruit(Long apply_id, Boolean isRecruit){
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new NotFoundException("Apply not found with id: " + apply_id));
apply.setIs_pass(isRecruit);
return ApplicationResponse.ok();
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION));
if(!apply.getIs_decision()){
apply.setIs_pass(isRecruit);
apply.setIs_decision(true);
Post post = apply.getPost();
//지원 파트 size 감소
Category category = categoryRepository.findCategoryByPostAndCategoryType(post, CategoryType.valueOf(apply.getRecruit_part()));
System.out.println("null"+",post:"+post+",categroy:"+apply.getRecruit_part());
if(category.getSize()-1<=0){
throw new ApplicationException(ErrorCode.OVER_APPLY_EXCEPTION);
}else {
category.setSize(category.getSize()-1);
return ApplicationResponse.ok();
}
}else {
throw new ApplicationException(ErrorCode.ALREADY_DECISION_EXCEPION);
}

}
// public ApplicationResponse<Void> updatePostState(Long post_id,String state){
// Post post = postRepository.findById(post_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION));
// //공고 상태가 모집 중인지 판단
// if(post.getStatus()==RECRUITING){
// if(state.equals("close")){
// post.setStatus(PostStatus.CLOSE);
// return ApplicationResponse.ok();
// } else {
// post.setStatus(PostStatus.CANCEL);
// return ApplicationResponse.ok();
// }
// }else {
// throw new ApplicationException(ErrorCode.NOT_RECRUITING_EXCEPION);
// }
// }
public ApplicationResponse<Void> updatePostPeriod(Long post_id, PeriodReq req) {
Post post = postRepository.findById(post_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION));
LocalDateTime extendedPeriod = post.getEndDate().plusDays(req.addDateNum());
// //공고 상태가 모집 중인지 판단
// if(post.getStatus()==RECRUITING){
post.setEndDate(extendedPeriod);
return ApplicationResponse.ok();
// }else {
// throw new ApplicationException(ErrorCode.NOT_RECRUITING_EXCEPION);
// }
}
public ApplicationResponse<ApplicationRes> findApplication(Long apply_id){
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new NotFoundException("Apply not found with id: " + apply_id));
// ApplicationRes applicationRes = ApplicationRes.builder().application(apply.getApplication()).recruit_part(apply.getRecruit_part()).build();
ApplicationRes applicationRes = ApplicationRes.of(apply);

public ApplicationResponse<ApplicationRes> findApplication(Long apply_id,Long post_id){
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION));
Post post = postRepository.findById(post_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION));
List<Category> categoryList = categoryRepository.findCategoryByPost(post);
List<String> list = new ArrayList<>();
if(categoryList!=null) {
for (Category category : categoryList) {
for (int i = 0; i < category.getSize(); i++) {
list.add(String.valueOf(category.getCategoryType()));
}
}
}else {
throw new ApplicationException(ErrorCode.NOT_FOUND_CATEGORY_EXCEPTION);
}
ApplicationRes applicationRes = ApplicationRes.of(apply,list);
return ApplicationResponse.ok(applicationRes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import com.gongjakso.server.domain.post.enumerate.CategoryType;
import com.gongjakso.server.global.common.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

@Getter
@Setter
@Entity
@Table(name = "category")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import lombok.*;

@Getter
@Setter
@Entity
@Table(name = "post")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.gongjakso.server.domain.post.enumerate;

public enum CategoryType {
PLAN,DESIGN,FE,BE,ETC,LATER
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
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;

public interface CategoryRepository extends JpaRepository<Category, Long> {
import java.util.List;

public interface CategoryRepository extends JpaRepository<Category, Long> {
List<Category> findCategoryByPost(Post post);
Category findCategoryByPostAndCategoryType(Post post, CategoryType categoryType);
}
Loading

0 comments on commit 6dfaae6

Please sign in to comment.