From 2978ad7f9e15b79726b804e805dba8e07bab430c Mon Sep 17 00:00:00 2001 From: sycuuui <102959791+sycuuui@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:13:16 +0900 Subject: [PATCH] =?UTF-8?q?#30=20feat=20:=20=EC=A7=80=EC=9B=90=EA=B8=B0?= =?UTF-8?q?=EA=B0=84=20=ED=8C=90=EB=8B=A8=20=EA=B5=AC=ED=98=84=20=EB=B0=8F?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apply/controller/ApplyController.java | 2 ++ .../domain/apply/service/ApplyService.java | 20 ++++++++++++------- .../server/global/exception/ErrorCode.java | 7 ++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java b/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java index db7fbbf0..178204b0 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java +++ b/src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java @@ -11,6 +11,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; + @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/apply") diff --git a/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java b/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java index 51956e55..d3db6f01 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java +++ b/src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java @@ -10,11 +10,14 @@ import com.gongjakso.server.domain.post.entity.Post; 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.List; import java.util.stream.Collectors; @@ -27,11 +30,14 @@ public class ApplyService { 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); + } + if(post.getEndDate().isAfter(LocalDateTime.now())){ + throw new ApplicationException(ErrorCode.NOT_APPLY_EXCEPTION); + }else { + Apply apply = req.toEntity(member, post); + return applyRepository.save(apply); } - Apply apply = req.toEntity(member, post); - return applyRepository.save(apply); } public ApplicationResponse findApply(Long post_id){ @@ -56,17 +62,17 @@ private String decisionState(Apply apply){ } } public ApplicationResponse 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 updateRecruit(Long apply_id, Boolean isRecruit){ - 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_pass(isRecruit); return ApplicationResponse.ok(); } public ApplicationResponse findApplication(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)); // ApplicationRes applicationRes = ApplicationRes.builder().application(apply.getApplication()).recruit_part(apply.getRecruit_part()).build(); ApplicationRes applicationRes = ApplicationRes.of(apply); return ApplicationResponse.ok(applicationRes); diff --git a/src/main/java/com/gongjakso/server/global/exception/ErrorCode.java b/src/main/java/com/gongjakso/server/global/exception/ErrorCode.java index b383302c..b02c9bc0 100644 --- a/src/main/java/com/gongjakso/server/global/exception/ErrorCode.java +++ b/src/main/java/com/gongjakso/server/global/exception/ErrorCode.java @@ -25,7 +25,12 @@ public enum ErrorCode { KAKAO_TOKEN_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, 3000, "토큰 발급에서 오류가 발생했습니다."), KAKAO_USER_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, 3001, "카카오 프로필 정보를 가져오는 과정에서 오류가 발생했습니디."), WRONG_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, 3002, "유효하지 않은 토큰입니다."), - LOGOUT_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, 3003, "로그아웃된 토큰입니다"); + LOGOUT_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, 3003, "로그아웃된 토큰입니다"), + + //4000: Apply Error + NOT_APPLY_EXCEPTION(HttpStatus.BAD_REQUEST,4000,"지원 기간 지났습니다"), + NOT_FOUND_POST_EXCEPTION(HttpStatus.NOT_FOUND,4001,"존재하지 않는 글입니다."), + NOT_FOUND_APPLY_EXCEPTION(HttpStatus.NOT_FOUND,4002,"존재하지 않는 지원서입니다."); private final HttpStatus httpStatus; private final Integer code;