Skip to content

Commit

Permalink
#30 feat : 지원기간 판단 구현 및 오류 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Jan 31, 2024
1 parent 0e5cd71 commit 2978ad7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<ApplyRes> findApply(Long post_id){
Expand All @@ -56,17 +62,17 @@ private String decisionState(Apply apply){
}
}
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 apply = applyRepository.findById(apply_id).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_APPLY_EXCEPTION));
apply.setIs_pass(isRecruit);
return ApplicationResponse.ok();
}
public ApplicationResponse<ApplicationRes> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2978ad7

Please sign in to comment.