Skip to content

Commit 149b096

Browse files
authored
♻️ Refactor - AI API 1번 요청을 병렬 요청으로 리팩토링한다
♻️ Refactor - AI API 1번 요청을 병렬 요청으로 리팩토링한다
2 parents 6fc58ce + 4f8386c commit 149b096

13 files changed

Lines changed: 813 additions & 252 deletions

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import lombok.RequiredArgsConstructor;
66
import org.springframework.data.domain.PageRequest;
77
import org.springframework.data.domain.Pageable;
8-
import org.springframework.http.ResponseEntity;
98
import org.springframework.web.bind.annotation.*;
109
import reactor.core.publisher.Mono;
1110
import sopt.comfit.company.dto.response.GetReportCompanyResponseDto;
@@ -16,57 +15,64 @@
1615
import sopt.comfit.report.dto.request.MatchExperienceRequestDto;
1716
import sopt.comfit.report.dto.response.AIReportResponseDto;
1817
import sopt.comfit.report.dto.response.GetReportSummaryResponseDto;
19-
import sopt.comfit.report.service.AIReportService;
18+
import sopt.comfit.report.service.AIReportFacade;
2019

2120
@RestController
2221
@RequiredArgsConstructor
2322
@RequestMapping("/api/v1/ai-reports")
2423
public class AIReportController implements AIReportSwagger {
2524

26-
private final AIReportService aiReportService;
27-
28-
@Override
29-
public AIReportResponseDto matchExperience(@LoginUser Long userId,
30-
@Valid @RequestBody MatchExperienceRequestDto requestDto){
31-
return aiReportService.matchExperience(MatchExperienceCommandDto.of(userId, requestDto));
32-
}
25+
private final AIReportFacade aiReportFacade;
3326

3427
@Override
3528
public PageDto<GetReportSummaryResponseDto> getReportList(@LoginUser Long userId,
3629
@RequestParam(defaultValue = "1") int page,
3730
@RequestParam(required = false) String keyword){
3831
Pageable pageable = PageRequest.of(Math.max(page - 1, 0), 4);
39-
return aiReportService.getReportList(userId, pageable, keyword);
32+
return aiReportFacade.getReportList(userId, pageable, keyword);
4033
}
4134

4235
@Override
4336
public AIReportResponseDto getReport(@LoginUser Long userId,
4437
@PathVariable Long reportId){
45-
return aiReportService.getReport(userId, reportId);
38+
return aiReportFacade.getReport(userId, reportId);
4639
}
4740

4841
@Override
4942
public GetReportExperienceResponseDto getReportExperience(@LoginUser Long userId){
5043

51-
return aiReportService.getReportExperience(userId);
44+
return aiReportFacade.getReportExperience(userId);
5245
}
5346

5447
@Override
5548
public GetReportCompanyResponseDto getReportCompany(@PathVariable Long companyId){
56-
return aiReportService.getReportCompany(companyId);
49+
return aiReportFacade.getReportCompany(companyId);
50+
}
51+
52+
@Override
53+
public AIReportResponseDto matchExperience(@LoginUser Long userId,
54+
@Valid @RequestBody MatchExperienceRequestDto requestDto){
55+
return aiReportFacade.matchExperience(MatchExperienceCommandDto.of(userId, requestDto));
5756
}
5857

5958
@PostMapping("/match/async")
6059
@SecurityRequirement(name = "JWT")
6160
public Mono<AIReportResponseDto> matchAsync(@LoginUser Long userid ,
6261
@RequestBody MatchExperienceRequestDto request) {
63-
return aiReportService.matchExperienceAsync(MatchExperienceCommandDto.of(userid, request));
62+
return aiReportFacade.matchExperienceAsync(MatchExperienceCommandDto.of(userid, request));
6463
}
6564

6665
@PostMapping("/match/async/webclient")
6766
@SecurityRequirement(name = "JWT")
6867
public AIReportResponseDto matchAsyncWebClient(@LoginUser Long userid ,
6968
@RequestBody MatchExperienceRequestDto request) {
70-
return aiReportService.matchExperienceWebclient(MatchExperienceCommandDto.of(userid, request));
69+
return aiReportFacade.matchExperienceWebclient(MatchExperienceCommandDto.of(userid, request));
70+
}
71+
72+
@PostMapping("/match/async/parallel")
73+
@SecurityRequirement(name = "JWT")
74+
public Mono<AIReportResponseDto> matchExperienceWebfluxParallel(@LoginUser Long userId,
75+
@RequestBody MatchExperienceRequestDto requestDto){
76+
return aiReportFacade.matchExperienceParallel(MatchExperienceCommandDto.of(userId, requestDto));
7177
}
7278
}

src/main/java/sopt/comfit/report/domain/AIReport.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,4 @@ public static AIReport create(
9090
.company(company)
9191
.build();
9292
}
93-
94-
95-
9693
}

src/main/java/sopt/comfit/report/exception/AIReportErrorCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public enum AIReportErrorCode implements ErrorCode {
1717
AI_AUTH_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "AI_500_002", "AI 서비스 인증 실패"),
1818
AI_RATE_LIMITED(HttpStatus.TOO_MANY_REQUESTS, "AI_429_001", "AI 요청 한도 초과"),
1919
AI_SERVER_ERROR(HttpStatus.BAD_GATEWAY, "AI_502_002", "AI 서버 오류"),
20-
20+
AI_CALL_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "AI_500_003", "AI 병렬 호출 실패"),
21+
AI_RESPONSE_REQUIRED_FIELD_OMIT(HttpStatus.INTERNAL_SERVER_ERROR, "AI_500_004", "AI 응답이 필수 응답값을 누락했습니다.")
2122
;
2223
private final HttpStatus status;
2324
private final String prefix;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package sopt.comfit.report.infra.dto;
2+
3+
import sopt.comfit.company.domain.Company;
4+
import sopt.comfit.company.domain.CompanyIssue;
5+
import sopt.comfit.experience.domain.Experience;
6+
7+
import java.util.List;
8+
9+
public record PreparedDataDto(
10+
Company company,
11+
Experience experience,
12+
String jobDescription,
13+
List<CompanyIssue> issues
14+
) {
15+
public static PreparedDataDto of(Company company,
16+
Experience experience,
17+
String jobDescription,
18+
List<CompanyIssue> issues) {
19+
return new PreparedDataDto(company, experience, jobDescription, issues);
20+
}
21+
}

0 commit comments

Comments
 (0)