Skip to content

Commit 7b5cd8a

Browse files
committed
reafactor: Vaildate Ids Add And Dto Apply #89
1 parent ad68250 commit 7b5cd8a

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/main/java/sopt/comfit/report/job/AIReportJobService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sopt.comfit.global.exception.BaseException;
99
import sopt.comfit.report.domain.AIReportJob;
1010
import sopt.comfit.report.domain.AIReportJobRepository;
11+
import sopt.comfit.report.dto.command.MatchExperienceCommandDto;
1112
import sopt.comfit.report.exception.AIReportErrorCode;
1213

1314
@Service
@@ -18,14 +19,19 @@ public class AIReportJobService {
1819
private final StringRedisTemplate redisTemplate;
1920

2021
@Transactional
21-
public Long createJob(Long userId, Long companyId, Long experienceId, String jobDescription) {
22+
public Long createJob(MatchExperienceCommandDto command) {
2223

2324
Long queueSize = redisTemplate.opsForList().size(Constants.JOB_QUEUE_KEY);
2425

2526
if (queueSize != null && queueSize > 200) {
2627
throw BaseException.type(AIReportErrorCode.JOB_QUEUE_FULL);
2728
}
28-
AIReportJob job = AIReportJob.create(userId, companyId, experienceId, jobDescription);
29+
AIReportJob job = AIReportJob.create(
30+
command.userId(),
31+
command.companyId(),
32+
command.experienceId(),
33+
command.jobDescription());
34+
2935
reportJobRepository.save(job);
3036

3137
redisTemplate.opsForList().leftPush(Constants.JOB_QUEUE_KEY, String.valueOf(job.getId()));

src/main/java/sopt/comfit/report/service/AIReportFacade.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,8 @@ public AIReportResponseDto matchExperienceVirtualThread(MatchExperienceCommandDt
122122

123123
public Long matchExperienceJob(MatchExperienceCommandDto command) {
124124

125-
return aiReportJobService.createJob(
126-
command.userId(),
127-
command.companyId(),
128-
command.experienceId(),
129-
command.jobDescription());
125+
aiReportQueryService.validateIds(command);
126+
127+
return aiReportJobService.createJob(command);
130128
}
131129
}

src/main/java/sopt/comfit/report/service/AIReportQueryService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,15 @@ public PreparedDataDto prepareData(MatchExperienceCommandDto command) {
8787

8888
return PreparedDataDto.of(company, experience, command.jobDescription(), issues);
8989
}
90+
91+
@Transactional(readOnly = true)
92+
public void validateIds(MatchExperienceCommandDto command) {
93+
if(!companyRepository.existsById(command.companyId())){
94+
throw new BaseException(CompanyErrorCode.COMPANY_NOT_FOUND);
95+
}
96+
if(!experienceRepository.existsById(command.experienceId())){
97+
throw new BaseException(ExperienceErrorCode.NOT_FOUND_EXPERIENCE);
98+
}
99+
}
90100
}
91101

0 commit comments

Comments
 (0)