diff --git a/src/main/java/com/example/ai_jeju/controller/RecommendationController.java b/src/main/java/com/example/ai_jeju/controller/RecommendationController.java index aca418d..6aaab6f 100644 --- a/src/main/java/com/example/ai_jeju/controller/RecommendationController.java +++ b/src/main/java/com/example/ai_jeju/controller/RecommendationController.java @@ -29,7 +29,7 @@ public ResponseEntity saveRecommendations(@RequestHeader(value = "Author if (tokenProvider.validToken(accessToken)) { Long userId = tokenProvider.getUserId(accessToken); try { - recommendationService.saveRecommendations(userId, recommendRequest.getRecommendations()); + recommendationService.saveRecommendations(userId, recommendRequest.getRestaurants(), recommendRequest.getLeisures(), recommendRequest.getHotels()); return ResponseEntity.ok("선택ID저장"); } catch (IllegalArgumentException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("잘못된 데이터: " + e.getMessage()); diff --git a/src/main/java/com/example/ai_jeju/dto/RecommendRequest.java b/src/main/java/com/example/ai_jeju/dto/RecommendRequest.java index 00762c7..4cc0300 100644 --- a/src/main/java/com/example/ai_jeju/dto/RecommendRequest.java +++ b/src/main/java/com/example/ai_jeju/dto/RecommendRequest.java @@ -1,17 +1,16 @@ package com.example.ai_jeju.dto; -import java.util.List; +import lombok.Getter; +import lombok.Setter; -public class RecommendRequest { +import java.util.List; - private List> recommendations; - // Getter and Setter - public List> getRecommendations() { - return recommendations; - } +@Getter +@Setter +public class RecommendRequest { - public void setRecommendations(List> recommendations) { - this.recommendations = recommendations; - } + private List restaurants; + private List leisures; + private List hotels; } diff --git a/src/main/java/com/example/ai_jeju/service/RecommendationService.java b/src/main/java/com/example/ai_jeju/service/RecommendationService.java index c77ae9c..ba4e3e6 100644 --- a/src/main/java/com/example/ai_jeju/service/RecommendationService.java +++ b/src/main/java/com/example/ai_jeju/service/RecommendationService.java @@ -16,17 +16,34 @@ public class RecommendationService { @Autowired private RecommendationRepository recommendationRepository; - @Transactional // 트랜잭션 처리 추가 - public void saveRecommendations(Long userId, List> recommendIdsList) { + @Transactional + public void saveRecommendations(Long userId, List restaurantIds, List leisureIds, List hotelIds) { List recommendations = new ArrayList<>(); - for (List recommendIds : recommendIdsList) { - for (Long recommendId : recommendIds) { - recommendations.add(Recommendation.builder() - .userId(userId) - .recommendId(recommendId) - .build()); - } + + // 음식점 리스트 저장 + for (Long restaurantId : restaurantIds) { + recommendations.add(Recommendation.builder() + .userId(userId) + .recommendId(restaurantId) + .build()); + } + + // 레저 리스트 저장 + for (Long leisureId : leisureIds) { + recommendations.add(Recommendation.builder() + .userId(userId) + .recommendId(leisureId) + .build()); } - recommendationRepository.saveAll(recommendations); // 성능 개선을 위해 한번에 저장 + + // 호텔 리스트 저장 + for (Long hotelId : hotelIds) { + recommendations.add(Recommendation.builder() + .userId(userId) + .recommendId(hotelId) + .build()); + } + + recommendationRepository.saveAll(recommendations); // 성능 개선을 위해 한 번에 저장 } -} +} \ No newline at end of file