Skip to content

Commit

Permalink
Merge branch 'main' into feat/post
Browse files Browse the repository at this point in the history
  • Loading branch information
jinnxyoung authored Feb 8, 2024
2 parents 7472862 + 6dfaae6 commit 476b89b
Show file tree
Hide file tree
Showing 26 changed files with 596 additions and 51 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 @@ -9,19 +9,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,21 +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 java.util.Optional;
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 @@ -25,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 @@ -45,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
@@ -0,0 +1,40 @@
package com.gongjakso.server.domain.banner.controller;

import com.gongjakso.server.domain.banner.dto.response.BannerRes;
import com.gongjakso.server.domain.banner.service.BannerService;
import com.gongjakso.server.global.common.ApplicationResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/banner")
@Tag(name = "Banner", description = "메인 페이지, 공고 페이지 등의 배너 이미지 정보 반환 API")
public class BannerController {

private final BannerService bannerService;

@Operation(description = "메인 페이지 공고 리스트 반환")
@GetMapping("/main")
public ApplicationResponse<List<BannerRes>> getMainImageList() {
return ApplicationResponse.ok(bannerService.getMainImageList());
}

@Operation(description = "프로젝트 공고 페이지 배너 리스트 반환")
@GetMapping("/project")
public ApplicationResponse<List<BannerRes>> getProjectImageList() {
return ApplicationResponse.ok(bannerService.getProjectImageList());
}

@Operation(description = "공모전 공고 페이지 배너 리스트 반환")
@GetMapping("/content")
public ApplicationResponse<List<BannerRes>> getContestImageList() {
return ApplicationResponse.ok(bannerService.getContestImageList());
}
}
Loading

0 comments on commit 476b89b

Please sign in to comment.