diff --git a/src/main/java/com/wooribound/domain/jobposting/JobPostingRepository.java b/src/main/java/com/wooribound/domain/jobposting/JobPostingRepository.java index 9870bb8..faafdc9 100644 --- a/src/main/java/com/wooribound/domain/jobposting/JobPostingRepository.java +++ b/src/main/java/com/wooribound/domain/jobposting/JobPostingRepository.java @@ -70,7 +70,7 @@ List findJobPostingsNew(@Param("exJobs") List exJo @Param("interestJobs") List interestJobs); // 2. 공고 상세 조회 - JobPosting findJobPostingByPostId(@Param("postId") Long postId); + Optional findJobPostingByPostId(@Param("postId") Long postId); // 3. 내 기업 공고 목록 조회 // JOBPOSTING + COUNT(쿼리연산) 반환해야해서 프로젝션 인터페이스로 리턴값 설정 JobPostingDetailProjection diff --git a/src/main/java/com/wooribound/domain/jobposting/Service/AdminJobPostingServiceImpl.java b/src/main/java/com/wooribound/domain/jobposting/Service/AdminJobPostingServiceImpl.java index 1f3ae6f..0683db0 100644 --- a/src/main/java/com/wooribound/domain/jobposting/Service/AdminJobPostingServiceImpl.java +++ b/src/main/java/com/wooribound/domain/jobposting/Service/AdminJobPostingServiceImpl.java @@ -18,6 +18,7 @@ import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @RequiredArgsConstructor @@ -37,30 +38,28 @@ public List getAllJobPostings(AdminJobPostingReqDTO adminJobPosti @Override public JobPostingDetailDTO getJobPostingDetail(Long postId) { - try { - JobPosting jobPosting = jobPostingRepository.findJobPostingByPostId(postId); + Optional optionalJobPosting = jobPostingRepository.findJobPostingByPostId(postId); - if (jobPosting == null) { - throw new NoJobPostingException("해당 공고 ID를 찾을 수 없습니다: " + postId); - } - - return JobPostingDetailDTO.builder() - .postTitle(jobPosting.getPostTitle()) - .entName(jobPosting.getEnterprise().getEntName()) - .postImg(jobPosting.getPostImg()) - .startDate(jobPosting.getStartDate()) - .endDate(jobPosting.getEndDate()) - .jobName(jobPosting.getJob().getJobName()) - .entAddr1(jobPosting.getEnterprise().getEntAddr1()) - .build(); - } catch (Exception e) { - throw new NoJobPostingException("채용공고 정보를 가져오는 도중 에러가 발생했습니다: " + postId, e); + if (optionalJobPosting.isEmpty()) { + throw new NoJobPostingException("해당 공고 ID를 찾을 수 없습니다: " + postId); } + + JobPosting jobPosting = optionalJobPosting.get(); + + return JobPostingDetailDTO.builder() + .postTitle(jobPosting.getPostTitle()) + .entName(jobPosting.getEnterprise().getEntName()) + .postImg(jobPosting.getPostImg()) + .startDate(jobPosting.getStartDate()) + .endDate(jobPosting.getEndDate()) + .jobName(jobPosting.getJob().getJobName()) + .entAddr1(jobPosting.getEnterprise().getEntAddr1()) + .build(); } @Override public String deleteJobPosting(Long postId) { - JobPosting jobPosting = jobPostingRepository.findJobPostingByPostId(postId); + Optional optionalJobPosting = jobPostingRepository.findJobPostingByPostId(postId); if (jobPostingRepository.updateIsDeletedByPostId(postId) != 0) { try { @@ -70,6 +69,8 @@ public String deleteJobPosting(Long postId) { throw new NoUserApplyException(postId); // 지원자가 없을 경우 예외 던짐 } + JobPosting jobPosting = optionalJobPosting.get(); + for (UserApply userApply : userApplies) { Notification notification = Notification.builder() .wbUser(userApply.getWbUser()) diff --git a/src/main/java/com/wooribound/domain/resume/ResumeServiceImpl.java b/src/main/java/com/wooribound/domain/resume/ResumeServiceImpl.java index 4693615..b017d83 100644 --- a/src/main/java/com/wooribound/domain/resume/ResumeServiceImpl.java +++ b/src/main/java/com/wooribound/domain/resume/ResumeServiceImpl.java @@ -148,7 +148,6 @@ public ResumeDTO updateResume(Authentication authentication, MultipartFile userI @Override public ResumeDetailDTO getWbUserResume(String userId) { - try { WbUser byIdWbUser = wbUserRepository.findById(userId) .orElseThrow(() -> new NoWbUserException("해당 사용자 ID를 찾을 수 없습니다: " + userId)); @@ -170,9 +169,6 @@ public ResumeDetailDTO getWbUserResume(String userId) { .resumeEmail(resume.getResumeEmail()) .jobList(jobs) .build(); - } catch (NoWbUserException e) { - throw e; - } } private String createFileName(String fileName){