Skip to content

Commit

Permalink
[Update] Ai 서버에 전송하는 DTO 추가, 전체적인 단기 일정 데이터베이스 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
alswp006 committed Sep 9, 2024
1 parent 5d8d439 commit d347d6a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.example.bami.short_travel.controller;

import com.example.bami.short_travel.dto.PlaceDTO;
import com.example.bami.short_travel.dto.RecommendationDTO;
import com.example.bami.short_travel.dto.SaveShortTravelDTO;
import com.example.bami.short_travel.dto.ShortTravelDTO;
import com.example.bami.short_travel.dto.*;
import com.example.bami.short_travel.service.TravelPlanService;
import com.example.bami.user.domain.BamiUser;
import com.example.bami.user.repository.UserRepository;
import com.example.bami.user.security.JwtTokenProvider;
import com.example.bami.weather.service.ReverseGeocodingService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -19,6 +18,7 @@

@RestController
@RequestMapping("/api/shortTrip")
@AllArgsConstructor
@Slf4j
public class ShortTravelController {

Expand All @@ -38,18 +38,13 @@ public class ShortTravelController {
private final TravelPlanService travelPlanService;
private final JwtTokenProvider jwtTokenProvider;
private final UserRepository userRepository;
private final ReverseGeocodingService reverseGeocodingService;

public ShortTravelController(TravelPlanService travelPlanService, JwtTokenProvider jwtTokenProvider, UserRepository userRepository) {
this.travelPlanService = travelPlanService;
this.jwtTokenProvider = jwtTokenProvider;
this.userRepository = userRepository;
}

@PostMapping("/save")
public ResponseEntity<String> saveTravelPlan(@RequestBody SaveShortTravelDTO saveShortTravelDTO, HttpServletRequest request) {
log.info(saveShortTravelDTO.getStartDate());
log.info(saveShortTravelDTO.getEndDate());
System.out.println(saveShortTravelDTO);

String token = jwtTokenProvider.resolveToken(request);
if (token == null || !jwtTokenProvider.validateToken(token)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

@Data
public class AiShortTravelDTO {
private String ADDRESS; // 주소
private double LATITUDE; // 위도
private double LONGITUDE; // 경도
private int DAY;
private String MVMN_NM; // "자가용", "대중교통 등"
private String GENDER; //"남성", "여성"
private int AGE_GRP; // 20대면 20, 30대면 30 등등
Expand All @@ -20,7 +22,7 @@ public class AiShortTravelDTO {
private int TRAVEL_MOTIVE_1; // 여행 동기
private String REL_CD_Categorized; // 동행인 정보

public static AiShortTravelDTO toAiShortTravelDTO(ShortTravelDTO shortTravelDTO, String address){
public static AiShortTravelDTO toAiShortTravelDTO(ShortTravelDTO shortTravelDTO){
AiShortTravelDTO aiShortTravelDTO = new AiShortTravelDTO();
List<String> travelMotivations = List.of(
"일상적인 환경 및 역할에서의 탈출, 지루함 탈피",
Expand All @@ -35,7 +37,9 @@ public static AiShortTravelDTO toAiShortTravelDTO(ShortTravelDTO shortTravelDTO,
"기타"
);

aiShortTravelDTO.ADDRESS = address;
aiShortTravelDTO.LATITUDE = shortTravelDTO.getLocation().getLatitude();
aiShortTravelDTO.LONGITUDE = shortTravelDTO.getLocation().getLongitude();
aiShortTravelDTO.DAY = shortTravelDTO.getDay_duration();
if (shortTravelDTO.getTransport().equals("차량 이용")){
aiShortTravelDTO.MVMN_NM = "자가용";
} else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ShortTravelDTO {
private String travelPurpose;
private String startDate;
private String endDate;
private int day_duration;
private String gender;
private String ageGroup;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.bami.short_travel.service;

import com.example.bami.short_travel.dto.AiShortTravelDTO;
import com.example.bami.short_travel.dto.RecommendationDTO;
import com.example.bami.short_travel.dto.ShortTravelDTO;
import com.example.bami.weather.service.ReverseGeocodingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
Expand All @@ -16,18 +18,22 @@
public class AIRecommendationService {

private final WebClient webClient;
private final ReverseGeocodingService reverseGeocodingService;

//@Value("${ai.server.url}")
private String aiServerUrl;

public AIRecommendationService(WebClient.Builder webClientBuilder) {
public AIRecommendationService(WebClient.Builder webClientBuilder, ReverseGeocodingService reverseGeocodingService) {
this.webClient = webClientBuilder.build();
this.reverseGeocodingService = reverseGeocodingService;
}

public Mono<List<RecommendationDTO>> getRecommendations(ShortTravelDTO shortTravelDTO) {
AiShortTravelDTO aiShortTravelDTO = AiShortTravelDTO.toAiShortTravelDTO(shortTravelDTO);

return webClient.post()
.uri(aiServerUrl + "/trip/short")
.bodyValue(shortTravelDTO)
.bodyValue(aiShortTravelDTO)
.retrieve()
.bodyToMono(new ParameterizedTypeReference<List<RecommendationDTO>>() {})
.doOnError(e -> log.error("AI 서버에서 추천 데이터를 가져오는 중 오류 발생", e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private TravelPlanDTO convertToDTO(TravelPlanEntity travelPlan) {
dto.setId(travelPlan.getId());
dto.setStartDate(travelPlan.getStartDate());
dto.setEndDate(travelPlan.getEndDate());
dto.setAddress(travelPlan.getAddress());
dto.setRecommendations(travelPlan.getRecommendationDays().stream()
.map(this::convertRecommendationToDTO)
.collect(Collectors.toList()));
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/application.yaml

This file was deleted.

0 comments on commit d347d6a

Please sign in to comment.