Skip to content

Commit

Permalink
Merge pull request #45 from Gongjakso/feat/apply
Browse files Browse the repository at this point in the history
Feat/apply
  • Loading branch information
sycuuui authored Feb 14, 2024
2 parents 2943612 + 370f603 commit 275acec
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.gongjakso.server.domain.apply.service.ApplyService;
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;
Expand All @@ -16,54 +17,71 @@
public class ApplyController {
private final ApplyService applyService;
//지원 요청 api
@Operation(summary = "공고 지원 API", description = "팀 지원하기 모달창에서 지원 요청")
@PostMapping("/{post_id}")
public ApplicationResponse<Void> addApply(@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 applyService.findApply(postId);
return ApplicationResponse.ok(applyService.findApply(postId));
}
//지원서 열람 요청 api
@Operation(summary = "지원서 열람 API", description = "내가 모집 중인 팀 페이지에서 지원서 열람 시")
@PatchMapping("/{apply_id}/open")
public ApplicationResponse<Void> updateIsOpenStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){
return applyService.updateOpen(applyId);
applyService.updateOpen(applyId);
return ApplicationResponse.ok();
}
//지원서 지원 요청 api
@Operation(summary = "합류하기 API", description = "합류하기 버튼 클릭 시")
@PatchMapping("/{apply_id}/recruit")
public ApplicationResponse<Void> updateIsRecruitStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){
return applyService.updateRecruit(applyId,true);
applyService.updateRecruit(applyId,true);
return ApplicationResponse.ok();
}
//지원서 미선발 요청 api
@Operation(summary = "미선발 API", description = "미선발 버튼 클릭 시")
@PatchMapping("/{apply_id}/not-recruit")
public ApplicationResponse<Void> updateNotRecruitStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){
return applyService.updateRecruit(applyId,false);
applyService.updateRecruit(applyId,false);
return ApplicationResponse.ok();
}
// 특정 지원자 지원서 가져오는 api
@Operation(summary = "지원서 API", description = "내가 모집 중인 팀 페이지에서 지원자 지원서 요청")
@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);
applyService.findApplication(applyId,postId);
return ApplicationResponse.ok();
}
//공고 카테고리 요청 api
@Operation(summary = "공고 카테고리 API", description = "팀 지원하기 모달 창에서 카테고리들(지원 분야) 요청")
@GetMapping("/{post_id}/category")
public ApplicationResponse<CategoryRes> getCategory(@PathVariable("post_id") Long postId){
return applyService.findPostCategory(postId);
return ApplicationResponse.ok(applyService.findPostCategory(postId));
}
//공고 마감 요청 api
@Operation(summary = "공고 마감 API", description = "내가 모집 중인 팀 페이지에서 공고 마감 버튼 클릭시")
@PatchMapping("/{post_id}/close")
public ApplicationResponse<Void> updatePostStatusToClose(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId){
applyService.updatePostState(postId,"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");
return ApplicationResponse.ok();
}
// //공고 마감 요청 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
@Operation(summary = "공고 연장 API", description = "내가 모집 중인 팀 페이지에서 공고 연장 버튼 클릭시")
@PatchMapping("/{post_id}/extension")
public ApplicationResponse<Void> updatePostPeriod(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestBody PeriodReq req){
return applyService.updatePostPeriod(postId,req);
applyService.updatePostPeriod(postId,req);
return ApplicationResponse.ok();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.gongjakso.server.domain.apply.dto;

import java.time.LocalDateTime;

public record PeriodReq(
int addDateNum
LocalDateTime endDate
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,30 @@
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.enumerate.PostStatus;
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;

import static com.gongjakso.server.domain.post.enumerate.PostStatus.RECRUITING;

@Service
@Transactional
@RequiredArgsConstructor
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){
public void save(Member member, Long post_id, ApplyReq req){
Post post = postRepository.findByPostId(post_id);
if (post == null) {
throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION);
Expand All @@ -41,25 +42,29 @@ public Apply save(Member member, Long post_id, ApplyReq req){
throw new ApplicationException(ErrorCode.NOT_APPLY_EXCEPTION);
}else {
Apply apply = req.toEntity(member, post);
return applyRepository.save(apply);
applyRepository.save(apply);
}
}else {
throw new ApplicationException(ErrorCode.ALREADY_APPLY_EXCEPTION);
}
}
}

public ApplicationResponse<ApplyRes> findApply(Long 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()
.map(apply -> ApplyList.of(apply, decisionState(apply)))
.collect(Collectors.toList());
ApplyRes applyRes = ApplyRes.of(post,current_person,applyLists);
return ApplicationResponse.ok(applyRes);
public ApplyRes findApply(Long post_id){
Post post = postRepository.findByPostId(post_id);
if (post == null) {
throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION);
}else{
int current_person = (int) applyRepository.countApplyByPost(post);
List<Apply> applies = applyRepository.findAllByPost(post);
List<ApplyList> applyLists = applies.stream()
.map(apply -> ApplyList.of(apply, decisionState(apply)))
.collect(Collectors.toList());
ApplyRes applyRes = ApplyRes.of(post,current_person,applyLists);
return applyRes;
}
}
public ApplicationResponse<CategoryRes> findPostCategory(Long post_id){
public CategoryRes findPostCategory(Long post_id){
Post post = postRepository.findByPostId(post_id);
if (post == null) {
throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION);
Expand All @@ -73,7 +78,7 @@ public ApplicationResponse<CategoryRes> findPostCategory(Long post_id){
}
}
CategoryRes categoryRes = new CategoryRes(list);
return ApplicationResponse.ok(categoryRes);
return categoryRes;
}else {
throw new ApplicationException(ErrorCode.NOT_FOUND_CATEGORY_EXCEPTION);
}
Expand All @@ -95,12 +100,11 @@ private String decisionState(Apply apply){
}

}
public ApplicationResponse<Void> updateOpen(Long apply_id){
public void updateOpen(Long 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){
public void updateRecruit(Long apply_id, Boolean isRecruit){
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION));
if(!apply.getIs_decision()){
apply.setIs_pass(isRecruit);
Expand All @@ -113,55 +117,62 @@ public ApplicationResponse<Void> updateRecruit(Long apply_id, Boolean isRecruit)
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 void updatePostState(Long post_id,String state){
Post post = postRepository.findByPostId(post_id);
if (post == null) {
throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION);
}else{
//공고 상태가 모집 중인지 판단
if(post.getStatus()==RECRUITING){
if(state.equals("close")){
post.setStatus(PostStatus.CLOSE);
} else {
post.setStatus(PostStatus.CANCEL);
}
}else {
throw new ApplicationException(ErrorCode.NOT_RECRUITING_EXCEPION);
}
}
}
public void updatePostPeriod(Long post_id, PeriodReq req) {
Post post = postRepository.findByPostId(post_id);
if (post == null) {
throw new ApplicationException(ErrorCode.NOT_FOUND_POST_EXCEPTION);
}else {
//공고 상태가 모집 중인지 판단
if(post.getStatus()==RECRUITING){
post.setEndDate(req.endDate());
}else {
throw new ApplicationException(ErrorCode.NOT_RECRUITING_EXCEPION);
}
}
}

public ApplicationResponse<ApplicationRes> findApplication(Long apply_id,Long post_id){
public 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()));
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()));
}
}
}else {
throw new ApplicationException(ErrorCode.NOT_FOUND_CATEGORY_EXCEPTION);
}
}else {
throw new ApplicationException(ErrorCode.NOT_FOUND_CATEGORY_EXCEPTION);
ApplicationRes applicationRes = ApplicationRes.of(apply,list);
return applicationRes;
}
ApplicationRes applicationRes = ApplicationRes.of(apply,list);
return ApplicationResponse.ok(applicationRes);
}
}

0 comments on commit 275acec

Please sign in to comment.