From 4b1885e426f471e9e6ab93b6d846723f4f1e2347 Mon Sep 17 00:00:00 2001 From: msk226 Date: Tue, 29 Apr 2025 13:58:28 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FEATURE]=20=EC=B6=94=EC=B2=9C=20=EC=97=AC?= =?UTF-8?q?=ED=96=89=EC=A7=80=20=EB=B0=8F=20=EC=8B=9D=EB=8B=B9=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20API=20=EC=8B=9C=EA=B7=B8=EB=8B=88=EC=B2=98=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/TripPlanController.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/hyu/erica/capstone/web/controller/TripPlanController.java b/src/main/java/hyu/erica/capstone/web/controller/TripPlanController.java index 7873932..72c8d95 100644 --- a/src/main/java/hyu/erica/capstone/web/controller/TripPlanController.java +++ b/src/main/java/hyu/erica/capstone/web/controller/TripPlanController.java @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -132,6 +133,40 @@ public ApiResponse viewRestaurantDetail( return ApiResponse.onSuccess(SuccessStatus._OK, tripPlanQueryService.getRecommendRestaurantDetail(restaurantId)); } + // 선택지 편집 + @Tag(name = "선택지 확인", description = "선택지 확인 API") + @Operation(summary = "추천 여행지 편집", description = """ + ### 추천 여행지 편집 API + + ### Path Variables + - tripPlansId: 여행 계획 ID + """) + @PutMapping("/{tripPlansId}/attractions/edit") + public ApiResponse editPlaces( + @PathVariable Long tripPlansId, + @RequestBody SaveAttractionRequestDTO request) { + // 선택지 편집 + tripPlanCommandService.editAttractionRecommendation(tripPlansId, request); + return ApiResponse.onSuccess(SuccessStatus._OK); + } + + // 음식점 편집 + @Tag(name = "선택지 확인", description = "선택지 확인 API") + @Operation(summary = "추천 음식점 편집", description = """ + ### 추천 음식점 편집 API + + ### Path Variables + - tripPlansId: 여행 계획 ID + """) + @PutMapping("/{tripPlansId}/restaurants/edit") + public ApiResponse editRestaurants( + @PathVariable Long tripPlansId, + @RequestBody SaveRestaurantRequestDTO request) { + // 음식점 편집 + tripPlanCommandService.editRestaurantRecommendation(tripPlansId, request); + return ApiResponse.onSuccess(SuccessStatus._OK); + } + // 음식점 키워드 검색 @Tag(name = "선택지 확인", description = "선택지 확인 API") From e611c6203d777d01797de8d705c994071e7fddf3 Mon Sep 17 00:00:00 2001 From: msk226 Date: Tue, 29 Apr 2025 13:58:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FEATURE]=20=EC=B6=94=EC=B2=9C=20=EC=97=AC?= =?UTF-8?q?=ED=96=89=EC=A7=80=20=EB=B0=8F=20=EC=8B=9D=EB=8B=B9=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=82=B4=EB=B6=80=20=EB=A1=9C=EC=A7=81=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PreferAttractionRepository.java | 1 + .../PreferRestaurantRepository.java | 1 + .../tripPlan/TripPlanCommandService.java | 4 ++ .../impl/TripPlanCommandServiceImpl.java | 58 ++++++++++++++++++- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/main/java/hyu/erica/capstone/repository/PreferAttractionRepository.java b/src/main/java/hyu/erica/capstone/repository/PreferAttractionRepository.java index 1a00e8b..09569ae 100644 --- a/src/main/java/hyu/erica/capstone/repository/PreferAttractionRepository.java +++ b/src/main/java/hyu/erica/capstone/repository/PreferAttractionRepository.java @@ -11,4 +11,5 @@ public interface PreferAttractionRepository extends JpaRepository findAllByTripPlanId(Long tripPlanId); List findByTripPlanIdAndIsPreferTrue(Long tripPlanId); boolean existsByAttraction_ContentIdAndUserId(Long attractionId, Long userId); + boolean existsByTripPlanIdAndAttractionContentId(Long tripPlanId, Long attractionId); } diff --git a/src/main/java/hyu/erica/capstone/repository/PreferRestaurantRepository.java b/src/main/java/hyu/erica/capstone/repository/PreferRestaurantRepository.java index dd441ec..f11e3a1 100644 --- a/src/main/java/hyu/erica/capstone/repository/PreferRestaurantRepository.java +++ b/src/main/java/hyu/erica/capstone/repository/PreferRestaurantRepository.java @@ -10,4 +10,5 @@ public interface PreferRestaurantRepository extends JpaRepository findAllByTripPlanId(Long tripPlanId); List findByTripPlanIdAndIsPreferTrue(Long tripPlanId); boolean existsByRestaurantIdAndUserId(Long restaurantId, Long userId); + boolean existsByTripPlanIdAndRestaurantId(Long tripPlanId, Long restaurantId); } diff --git a/src/main/java/hyu/erica/capstone/service/tripPlan/TripPlanCommandService.java b/src/main/java/hyu/erica/capstone/service/tripPlan/TripPlanCommandService.java index f91e409..6e9dfa5 100644 --- a/src/main/java/hyu/erica/capstone/service/tripPlan/TripPlanCommandService.java +++ b/src/main/java/hyu/erica/capstone/service/tripPlan/TripPlanCommandService.java @@ -11,4 +11,8 @@ public interface TripPlanCommandService { Long confirmRestaurantRecommendation(Long tripPlanId, SaveRestaurantRequestDTO request); void updatePlan(UpdateAllScheduleOrderRequest request); + + void editAttractionRecommendation(Long tripPlansId, SaveAttractionRequestDTO request); + + void editRestaurantRecommendation(Long tripPlansId, SaveRestaurantRequestDTO request); } diff --git a/src/main/java/hyu/erica/capstone/service/tripPlan/impl/TripPlanCommandServiceImpl.java b/src/main/java/hyu/erica/capstone/service/tripPlan/impl/TripPlanCommandServiceImpl.java index bf233aa..fa3a7b6 100644 --- a/src/main/java/hyu/erica/capstone/service/tripPlan/impl/TripPlanCommandServiceImpl.java +++ b/src/main/java/hyu/erica/capstone/service/tripPlan/impl/TripPlanCommandServiceImpl.java @@ -24,11 +24,9 @@ import hyu.erica.capstone.web.dto.tripPlan.request.UpdateAllScheduleOrderRequest.ScheduleOrderItemDTO; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.Set; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -117,6 +115,62 @@ public void updatePlan(UpdateAllScheduleOrderRequest request) { } } + @Override + public void editAttractionRecommendation(Long tripPlansId, SaveAttractionRequestDTO request) { + if (!tripPlanRepository.existsById(tripPlansId)) { + throw new GeneralException(ErrorStatus._TRIP_PLAN_NOT_FOUND); + } + + List preferAttractions = preferAttractionRepository.findAllByTripPlanId(tripPlansId); + + for (PreferAttraction preferAttraction : preferAttractions) { + if (!request.attractionIds().contains(preferAttraction.getAttraction().getContentId())) { + preferAttraction.setPrefer(false); + } + } + + // 입력 받은 것 중, 기존 DB에 없는 것들은 새로 추가. + for (Long attractionId : request.attractionIds()) { + if (!preferAttractionRepository.existsByTripPlanIdAndAttractionContentId(tripPlansId, attractionId)) { + PreferAttraction preferAttraction = PreferAttraction.builder() + .tripPlan(tripPlanRepository.getReferenceById(tripPlansId)) + .attraction(attractionRepository.getReferenceById(attractionId)) + .isPrefer(true) + .build(); + preferAttractionRepository.save(preferAttraction); + } + } + } + + + @Override + public void editRestaurantRecommendation(Long tripPlansId, SaveRestaurantRequestDTO request) { + if (!tripPlanRepository.existsById(tripPlansId)) { + throw new GeneralException(ErrorStatus._TRIP_PLAN_NOT_FOUND); + } + + List preferRestaurants = preferRestaurantRepository.findAllByTripPlanId(tripPlansId); + + for (PreferRestaurant preferRestaurant : preferRestaurants) { + if (!request.restaurantIds().contains(preferRestaurant.getRestaurant().getId())) { + preferRestaurant.setPrefer(false); + } + } + + // 입력 받은 것 중, 기존 DB에 없는 것들은 새로 추가. + for (Long restaurantId : request.restaurantIds()) { + if (!preferRestaurantRepository.existsByTripPlanIdAndRestaurantId(tripPlansId, restaurantId)) { + PreferRestaurant preferRestaurant = PreferRestaurant.builder() + .tripPlan(tripPlanRepository.getReferenceById(tripPlansId)) + .restaurant(restaurantRepository.getReferenceById(restaurantId)) + .isPrefer(true) + .build(); + preferRestaurantRepository.save(preferRestaurant); + } + } + + } + private void createTripPlanFinal(Long tripPlanId) { TripPlan tripPlan = tripPlanRepository.findById(tripPlanId) .orElseThrow(() -> new GeneralException(ErrorStatus._TRIP_PLAN_NOT_FOUND));