Skip to content

Commit

Permalink
[chore] #112 - JobPostingRepository에서 JobPosting 타입 Optional로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
2oo1s committed Nov 20, 2024
1 parent 702ec9c commit ab9bc18
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ List<JobPostingProjection> findJobPostingsNew(@Param("exJobs") List<String> exJo
@Param("interestJobs") List<String> interestJobs);

// 2. 공고 상세 조회
JobPosting findJobPostingByPostId(@Param("postId") Long postId);
Optional<JobPosting> findJobPostingByPostId(@Param("postId") Long postId);

// 3. 내 기업 공고 목록 조회
// JOBPOSTING + COUNT(쿼리연산) 반환해야해서 프로젝션 인터페이스로 리턴값 설정 JobPostingDetailProjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RequiredArgsConstructor
Expand All @@ -37,30 +38,28 @@ public List<JobPostingDTO> getAllJobPostings(AdminJobPostingReqDTO adminJobPosti

@Override
public JobPostingDetailDTO getJobPostingDetail(Long postId) {
try {
JobPosting jobPosting = jobPostingRepository.findJobPostingByPostId(postId);
Optional<JobPosting> 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 <JobPosting> optionalJobPosting = jobPostingRepository.findJobPostingByPostId(postId);

if (jobPostingRepository.updateIsDeletedByPostId(postId) != 0) {
try {
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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){
Expand Down

0 comments on commit ab9bc18

Please sign in to comment.