diff --git a/src/main/java/com/example/bami/short_travel/controller/ShortTravelController.java b/src/main/java/com/example/bami/short_travel/controller/ShortTravelController.java index 09dd4b8..4f602d9 100644 --- a/src/main/java/com/example/bami/short_travel/controller/ShortTravelController.java +++ b/src/main/java/com/example/bami/short_travel/controller/ShortTravelController.java @@ -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; @@ -19,6 +18,7 @@ @RestController @RequestMapping("/api/shortTrip") +@AllArgsConstructor @Slf4j public class ShortTravelController { @@ -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 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)) { diff --git a/src/main/java/com/example/bami/short_travel/dto/AiShortTravelDTO.java b/src/main/java/com/example/bami/short_travel/dto/AiShortTravelDTO.java index 2a59923..472b7b3 100644 --- a/src/main/java/com/example/bami/short_travel/dto/AiShortTravelDTO.java +++ b/src/main/java/com/example/bami/short_travel/dto/AiShortTravelDTO.java @@ -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 등등 @@ -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 travelMotivations = List.of( "일상적인 환경 및 역할에서의 탈출, 지루함 탈피", @@ -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{ diff --git a/src/main/java/com/example/bami/short_travel/dto/ShortTravelDTO.java b/src/main/java/com/example/bami/short_travel/dto/ShortTravelDTO.java index c600ba0..2b94e7f 100644 --- a/src/main/java/com/example/bami/short_travel/dto/ShortTravelDTO.java +++ b/src/main/java/com/example/bami/short_travel/dto/ShortTravelDTO.java @@ -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; diff --git a/src/main/java/com/example/bami/short_travel/service/AIRecommendationService.java b/src/main/java/com/example/bami/short_travel/service/AIRecommendationService.java index 40fd10a..8a99946 100644 --- a/src/main/java/com/example/bami/short_travel/service/AIRecommendationService.java +++ b/src/main/java/com/example/bami/short_travel/service/AIRecommendationService.java @@ -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; @@ -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> getRecommendations(ShortTravelDTO shortTravelDTO) { + AiShortTravelDTO aiShortTravelDTO = AiShortTravelDTO.toAiShortTravelDTO(shortTravelDTO); + return webClient.post() .uri(aiServerUrl + "/trip/short") - .bodyValue(shortTravelDTO) + .bodyValue(aiShortTravelDTO) .retrieve() .bodyToMono(new ParameterizedTypeReference>() {}) .doOnError(e -> log.error("AI 서버에서 추천 데이터를 가져오는 중 오류 발생", e)); diff --git a/src/main/java/com/example/bami/short_travel/service/TravelPlanService.java b/src/main/java/com/example/bami/short_travel/service/TravelPlanService.java index 343150f..c9e278d 100644 --- a/src/main/java/com/example/bami/short_travel/service/TravelPlanService.java +++ b/src/main/java/com/example/bami/short_travel/service/TravelPlanService.java @@ -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())); diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml deleted file mode 100644 index 3d7808a..0000000 --- a/src/main/resources/application.yaml +++ /dev/null @@ -1,3 +0,0 @@ -spring: - profiles: - active: dev