Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface PreferAttractionRepository extends JpaRepository<PreferAttracti
List<PreferAttraction> findAllByTripPlanId(Long tripPlanId);
List<PreferAttraction> findByTripPlanIdAndIsPreferTrue(Long tripPlanId);
boolean existsByAttraction_ContentIdAndUserId(Long attractionId, Long userId);
boolean existsByTripPlanIdAndAttractionContentId(Long tripPlanId, Long attractionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface PreferRestaurantRepository extends JpaRepository<PreferRestaura
List<PreferRestaurant> findAllByTripPlanId(Long tripPlanId);
List<PreferRestaurant> findByTripPlanIdAndIsPreferTrue(Long tripPlanId);
boolean existsByRestaurantIdAndUserId(Long restaurantId, Long userId);
boolean existsByTripPlanIdAndRestaurantId(Long tripPlanId, Long restaurantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PreferAttraction> 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<PreferRestaurant> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down