-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into refactor/#4-convert-report-pdf
- Loading branch information
Showing
16 changed files
with
258 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/swOnCampus/AIPlatform/domain/consulting/service/ConsultingAllService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.swOnCampus.AIPlatform.domain.consulting.service; | ||
|
||
import com.swOnCampus.AIPlatform.domain.consulting.web.dto.request.ConsultingAllRequestDto; | ||
import com.swOnCampus.AIPlatform.domain.consulting.web.dto.response.ConsultingAllResponseDto; | ||
|
||
public interface ConsultingAllService { | ||
ConsultingAllResponseDto.ConsultingAllResponse getConsultingAll(long memberId,ConsultingAllRequestDto.ConsultingAllRequest request); | ||
} |
101 changes: 101 additions & 0 deletions
101
...in/java/com/swOnCampus/AIPlatform/domain/consulting/service/ConsultingAllServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.swOnCampus.AIPlatform.domain.consulting.service; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.swOnCampus.AIPlatform.domain.consulting.entity.Consulting; | ||
import com.swOnCampus.AIPlatform.domain.consulting.repository.ConsultingRepository; | ||
import com.swOnCampus.AIPlatform.domain.consulting.web.dto.request.ConsultingAllRequestDto; | ||
import com.swOnCampus.AIPlatform.domain.consulting.web.dto.response.ConsultingAllResponseDto; | ||
import com.swOnCampus.AIPlatform.domain.member.entity.Member; | ||
import com.swOnCampus.AIPlatform.domain.member.repository.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestClientException; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ConsultingAllServiceImpl implements ConsultingAllService { | ||
private final MemberRepository memberRepository; | ||
private final ConsultingRepository consultingRepository; | ||
private final RestTemplate restTemplate; | ||
private final ObjectMapper objectMapper; | ||
|
||
@Value(value = "${ai.api.url}") | ||
private String apiUrl; | ||
|
||
|
||
@Override | ||
public ConsultingAllResponseDto.ConsultingAllResponse getConsultingAll(long memberId, ConsultingAllRequestDto.ConsultingAllRequest request) { | ||
|
||
String baseUrl = apiUrl + "/api/consulting"; | ||
|
||
URI uri = UriComponentsBuilder.fromHttpUrl(baseUrl) | ||
.queryParam("summary", "False") | ||
.queryParam("test", "True") | ||
.build() | ||
.toUri(); | ||
|
||
log.info("uri: {}", uri); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.set("Content-Type", "application/json"); | ||
headers.set("Accept", "application/json"); | ||
|
||
try { | ||
HttpEntity<ConsultingAllRequestDto.ConsultingAllRequest> entity = new HttpEntity<>(request, headers); | ||
|
||
ResponseEntity<String> response = restTemplate.postForEntity(uri, entity, String.class); | ||
|
||
String responseBody = response.getBody(); | ||
log.info("response: {}", responseBody); | ||
|
||
if (!response.getStatusCode().is2xxSuccessful()) { | ||
throw new RuntimeException("컨설팅 생성 오류 : " + response.getStatusCode()); | ||
} | ||
|
||
JsonNode rootNode = objectMapper.readTree(responseBody); | ||
if (!rootNode.has("result") || rootNode.get("result").isNull()) { | ||
throw new RuntimeException("컨설팅 생성에 오류가 발생하였습니다."); | ||
} | ||
String result = rootNode.get("result").asText(); | ||
|
||
Optional<Member> foundMember = memberRepository.findById(memberId); | ||
if (!foundMember.isPresent()) { | ||
throw new RuntimeException("존재하지 않는 멤버입니다."); | ||
} | ||
|
||
Member found = foundMember.get(); | ||
|
||
Consulting newAllConsulting = Consulting.builder() | ||
.consultingAll(result) | ||
.member(found) | ||
.build(); | ||
|
||
found.addConsulting(newAllConsulting); | ||
|
||
// 컨설팅 저장 | ||
consultingRepository.save(newAllConsulting); | ||
|
||
return ConsultingAllResponseDto.ConsultingAllResponse.builder() | ||
.result(result) | ||
.build(); | ||
|
||
} | ||
catch (Exception e){ | ||
e.printStackTrace(); | ||
throw new RuntimeException("전체 컨설팅 생성에 실패하였습니다."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 10 additions & 4 deletions
14
.../java/com/swOnCampus/AIPlatform/domain/consulting/web/dto/request/CompanyInfoRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
package com.swOnCampus.AIPlatform.domain.consulting.web.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record CompanyInfoRequest( | ||
@NotBlank(message="회사명을 입력해주세요.") | ||
@Schema(description = "회사명을 입력해주세요.", example = "company") | ||
@NotBlank(message = "회사명을 입력해주세요.") | ||
String name, | ||
@NotBlank(message="기업규모를 입력해주세요.") | ||
@Schema(description = "기업규모를 입력해주세요.", example = "Small") | ||
@NotBlank(message = "기업규모를 입력해주세요.") | ||
String companySize, | ||
@NotBlank(message="산업 분야를 입력해주세요.") | ||
@Schema(description = "산업 분야를 입력해주세요.", example = "Retail") | ||
@NotBlank(message = "산업 분야를 입력해주세요.") | ||
String industry, | ||
@NotBlank(message="Pain Point를 입력해주세요.") | ||
@Schema(description = "Pain point를 입력해주세요.", example = "String") | ||
@NotBlank(message = "Pain Point를 입력해주세요.") | ||
String painPoint | ||
) { | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
.../com/swOnCampus/AIPlatform/domain/consulting/web/dto/request/ConsultingAllRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.swOnCampus.AIPlatform.domain.consulting.web.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
public class ConsultingAllRequestDto { | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class ConsultingAllRequest { | ||
private String industry; | ||
private String company_size; | ||
private String pain_point; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...om/swOnCampus/AIPlatform/domain/consulting/web/dto/response/ConsultingAllResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.swOnCampus.AIPlatform.domain.consulting.web.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
public class ConsultingAllResponseDto { | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class ConsultingAllResponse { | ||
private String result; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...java/com/swOnCampus/AIPlatform/domain/consulting/web/dto/response/ConsultingResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.