Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/#112 admin exception #114

Merged
merged 5 commits into from
Nov 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.wooribound.domain.enterprise.dto.AdminEnterpriseDTO;
import com.wooribound.domain.enterprise.dto.AdminEnterpriseDetailDTO;
import com.wooribound.domain.enterprise.dto.AdminPendingEnterpriseDTO;
import com.wooribound.global.exception.NoEnterpriseException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -38,19 +39,23 @@ public List<AdminEnterpriseDTO> getEnterprises(AdminEnterpriseReqDTO adminEnterp

@Override
public AdminEnterpriseDetailDTO getEnterpriseInfo(String entId) {
Enterprise enterprise = enterpriseRepository.findByEntId(entId);
try {
Enterprise enterprise = enterpriseRepository.findByEntId(entId);

return AdminEnterpriseDetailDTO.builder()
.entId(enterprise.getEntId())
.ceoName(enterprise.getCeoName())
.entName(enterprise.getEntName())
.regNum(enterprise.getRegNum())
.entAddr1(enterprise.getEntAddr1())
.entAddr2(enterprise.getEntAddr2())
.entSize(enterprise.getEntSize())
.entField(enterprise.getEntField())
.revenue(enterprise.getRevenue())
.build();
return AdminEnterpriseDetailDTO.builder()
.entId(enterprise.getEntId())
.ceoName(enterprise.getCeoName())
.entName(enterprise.getEntName())
.regNum(enterprise.getRegNum())
.entAddr1(enterprise.getEntAddr1())
.entAddr2(enterprise.getEntAddr2())
.entSize(enterprise.getEntSize())
.entField(enterprise.getEntField())
.revenue(enterprise.getRevenue())
.build();
} catch (Exception e) {
throw new NoEnterpriseException("ν•΄λ‹Ή κΈ°μ—… IDλ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€: " + entId, e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,25 @@ public List<JobPostingDTO> getAllJobPostings(AdminJobPostingReqDTO adminJobPosti

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public WbUserKnowhowDTO getShareKnowhowDetail(Long knowhowId) {
Optional<Knowhow> knowhowOptional = knowhowRepository.findById(knowhowId);

if (knowhowOptional.isEmpty()) {
throw new KnowhowNotFoundException(String.format("%dλŠ” μ—†λŠ” κ²Œμ‹œλ¬Ό μž…λ‹ˆλ‹€.: ", knowhowId));
throw new KnowhowNotFoundException(String.format("%dλŠ” μ—†λŠ” κ²Œμ‹œλ¬Ό μž…λ‹ˆλ‹€.", knowhowId));
}

Knowhow knowhow = knowhowOptional.get();
Expand Down
46 changes: 26 additions & 20 deletions src/main/java/com/wooribound/domain/resume/ResumeServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.wooribound.domain.resume;

import com.amazonaws.services.s3.AmazonS3Client;
import com.wooribound.domain.resume.dto.ResumeDTO;
import com.wooribound.domain.resume.dto.ResumeDetailDTO;
import com.wooribound.domain.wbuser.WbUser;
import com.wooribound.domain.wbuser.WbUserRepository;
import com.wooribound.domain.workhistory.WorkHistory;
import com.wooribound.domain.workhistory.WorkHistoryRepository;
import com.wooribound.global.exception.NoWbUserException;
import com.wooribound.global.exception.NotEntityException;
import com.wooribound.global.util.AuthenticateUtil;
import com.wooribound.global.util.S3Util;
Expand Down Expand Up @@ -148,25 +148,31 @@ public ResumeDTO updateResume(Authentication authentication, MultipartFile userI

@Override
public ResumeDetailDTO getWbUserResume(String userId) {

Resume resume = resumeRepository.findByUserId(userId).orElseThrow();
List<WorkHistory> workHistoryList = workHistoryRepository.findByUserId(userId);

List<String> jobs = workHistoryList.stream()
.map(workHistory -> workHistory.getJob().getJobName()) // jobName만 μΆ”μΆœ
.collect(Collectors.toList());

return ResumeDetailDTO.builder()
.userName(resume.getWbUser().getName())
.jobPoint(resume.getWbUser().getJobPoint())
.phone(resume.getWbUser().getPhone())
.addrCity(resume.getWbUser().getAddrCity())
.addrProvince(resume.getWbUser().getAddrProvince())
.userIntro(resume.getUserIntro())
.userImg(resume.getUserImg())
.resumeEmail(resume.getResumeEmail())
.jobList(jobs)
.build();
try {
WbUser byIdWbUser = wbUserRepository.findById(userId)
.orElseThrow(() -> new NoWbUserException("ν•΄λ‹Ή μ‚¬μš©μž IDλ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€: " + userId));

Resume resume = resumeRepository.findByUserId(userId).orElseThrow();
List<WorkHistory> workHistoryList = workHistoryRepository.findByUserId(userId);

List<String> jobs = workHistoryList.stream()
.map(workHistory -> workHistory.getJob().getJobName()) // jobName만 μΆ”μΆœ
.collect(Collectors.toList());

return ResumeDetailDTO.builder()
.userName(resume.getWbUser().getName())
.jobPoint(resume.getWbUser().getJobPoint())
.phone(resume.getWbUser().getPhone())
.addrCity(resume.getWbUser().getAddrCity())
.addrProvince(resume.getWbUser().getAddrProvince())
.userIntro(resume.getUserIntro())
.userImg(resume.getUserImg())
.resumeEmail(resume.getResumeEmail())
.jobList(jobs)
.build();
} catch (NoWbUserException e) {
throw e;
}
}

private String createFileName(String fileName){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.wooribound.global.exception;

import lombok.experimental.StandardException;

@StandardException
public class NoEnterpriseException extends RuntimeException{

public NoEnterpriseException() {
super("κΈ°μ—…νšŒμ›μ΄ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public ResponseEntity<String> handleNotValidPasswordException(NotValidPasswordEx
public ResponseEntity<String> handleNoApproveStatusException(NoApproveStatusException e) {
return ResponseEntity.status(400).body(e.getMessage());
}

@ExceptionHandler(NoEnterpriseException.class)
public ResponseEntity<String> handleNoEnterpriseException(NoEnterpriseException e) {
return ResponseEntity.status(400).body(e.getMessage());
}
}


Expand Down
Loading