Skip to content

Commit d82b6b0

Browse files
authored
♻️ Refactor - AI 호출에 WebClient를 도입한다
♻️ Refactor - AI 호출에 WebClient를 도입한다
2 parents faa1d6e + 97aafb7 commit d82b6b0

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/main/java/sopt/comfit/report/controller/AIReportController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,11 @@ public Mono<AIReportResponseDto> matchAsync(@LoginUser Long userid ,
6262
@RequestBody MatchExperienceRequestDto request) {
6363
return aiReportService.matchExperienceAsync(MatchExperienceCommandDto.of(userid, request));
6464
}
65+
66+
@PostMapping("/match/async/webclient")
67+
@SecurityRequirement(name = "JWT")
68+
public AIReportResponseDto matchAsyncWebClient(@LoginUser Long userid ,
69+
@RequestBody MatchExperienceRequestDto request) {
70+
return aiReportService.matchExperienceWebclient(MatchExperienceCommandDto.of(userid, request));
71+
}
6572
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,33 @@ public Mono<AIReportResponseDto> matchExperienceAsync(MatchExperienceCommandDto
114114
}));
115115
}
116116

117+
@Transactional
118+
public AIReportResponseDto matchExperienceWebclient(MatchExperienceCommandDto command) {
119+
Company company = companyRepository.findById(command.companyId())
120+
.orElseThrow(() -> BaseException.type(CompanyErrorCode.COMPANY_NOT_FOUND));
121+
122+
Experience experience = experienceRepository.findByIdAndUserId(command.experienceId(), command.userId())
123+
.orElseThrow(() -> new BaseException(ExperienceErrorCode.NOT_FOUND_EXPERIENCE));
124+
125+
List<CompanyIssue> companyIssueList = companyIssueRepository.findByCompanyId(command.companyId());
126+
127+
log.info("WebClient API 호출 시작 - companyId: {}, experienceId: {}", company.getId(), experience.getId());
128+
long startTime = System.currentTimeMillis();
129+
130+
CreateReportAiResponseDto response = aiWebClient
131+
.createReport(CreateReportAiRequestDto
132+
.from(AIReportPromptBuilder
133+
.build(company, experience, command.jobDescription(), companyIssueList)))
134+
.block(); // 여기서 동기로 대기
135+
136+
long duration = System.currentTimeMillis() - startTime;
137+
log.info("WebClient API 호출 완료 - duration: {}ms", duration);
138+
139+
AIReport aiReport = parseAndSave(response.getContent(), experience, company, command.jobDescription());
140+
141+
return AIReportResponseDto.from(aiReport);
142+
}
143+
117144

118145
@Transactional(readOnly = true)
119146
public PageDto<GetReportSummaryResponseDto> getReportList(Long userId, Pageable pageable, String keyword) {

0 commit comments

Comments
 (0)