diff --git a/src/main/java/com/umc/hackaton/snapspot/category/controller/CategoryController.java b/src/main/java/com/umc/hackaton/snapspot/category/controller/CategoryController.java index c58aa16..eb82659 100644 --- a/src/main/java/com/umc/hackaton/snapspot/category/controller/CategoryController.java +++ b/src/main/java/com/umc/hackaton/snapspot/category/controller/CategoryController.java @@ -43,16 +43,16 @@ public ResponseEntity showAllCategories() { } } -// @GetMapping("/spots") -// public ResponseEntity showSpotsByCategoryId( -// @RequestParam List categoryIds -// ) { -// try { -// List spots = categoryService.showSpotsByCategoryIds(categoryIds); -// return ResponseEntity.ok().body(spots); -// } catch (Exception e){ -// log.info("카테고리별 스팟 리스트 조회에 실패하였습니다.", e); -// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("카테고리별 스팟 리스트 조회에 실패하였습니다."); -// } -// } + @GetMapping("/spots") + public ResponseEntity showSpotsByCategoryId( + @RequestParam List categoryIds + ) { + try { + List spots = categoryService.showSpotsByCategoryIds(categoryIds); + return ResponseEntity.ok().body(spots); + } catch (Exception e){ + log.info("카테고리별 스팟 리스트 조회에 실패하였습니다.", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("카테고리별 스팟 리스트 조회에 실패하였습니다."); + } + } } diff --git a/src/main/java/com/umc/hackaton/snapspot/category/repository/CategorySpotRepository.java b/src/main/java/com/umc/hackaton/snapspot/category/repository/CategorySpotRepository.java index 3d9401d..a15fbda 100644 --- a/src/main/java/com/umc/hackaton/snapspot/category/repository/CategorySpotRepository.java +++ b/src/main/java/com/umc/hackaton/snapspot/category/repository/CategorySpotRepository.java @@ -2,14 +2,10 @@ import com.umc.hackaton.snapspot.category.entity.Category; import com.umc.hackaton.snapspot.category.entity.CategorySpot; -import com.umc.hackaton.snapspot.spot.entity.Spot; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; -import java.util.Optional; public interface CategorySpotRepository extends JpaRepository { List findAllByCategory(Category category); - - List findAllBySpot(Spot spot); } diff --git a/src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.java b/src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.java index 252b59d..1d77bb8 100644 --- a/src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.java +++ b/src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.java @@ -11,8 +11,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.util.List; - @RequiredArgsConstructor @RestController @@ -78,16 +76,14 @@ public ResponseEntity patchSpot( return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("스팟 수정에 실패하였습니다."); } } - - @GetMapping("list") public ResponseEntity> readNearSpotList(@RequestParam("latitude") double latitude, @RequestParam("longitude") double longitude){ return ResponseEntity.ok(spotService.readNearSpotList(latitude, longitude)); } - - @GetMapping("list/category") + + @GetMapping("list/category") public ResponseEntity> readCategoryNearSpotList(@RequestParam("latitude") double latitude, @RequestParam("longitude") double longitude, @RequestParam("categoryId") Long categoryId){ List list = spotService.readNearSpotList(latitude, longitude); return ResponseEntity.ok(spotService.readCategoryNearSpotList(list, categoryId)); - } + } } diff --git a/src/main/java/com/umc/hackaton/snapspot/spot/dto/SpotResponseDto.java b/src/main/java/com/umc/hackaton/snapspot/spot/dto/SpotResponseDto.java index c27a2d0..3480c43 100644 --- a/src/main/java/com/umc/hackaton/snapspot/spot/dto/SpotResponseDto.java +++ b/src/main/java/com/umc/hackaton/snapspot/spot/dto/SpotResponseDto.java @@ -1,10 +1,8 @@ package com.umc.hackaton.snapspot.spot.dto; import lombok.Builder; -import lombok.Getter; @Builder -@Getter public class SpotResponseDto { Long spotId; String imgUrl; diff --git a/src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.java b/src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.java index 55515a6..e84b122 100644 --- a/src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.java +++ b/src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.java @@ -95,21 +95,4 @@ public List readNearSpotList(double latitude, double longitude) List spotList = spotRepository.findSpotsWithinDistance(latitude, longitude, 0.5); return SpotConverter.toDtoList(spotList); } - - - public List readCategoryNearSpotList(List spotList, Long categoryId) { - List filteredSpots = new ArrayList<>(); - - for (SpotResponseDto s : spotList) { - List categorySpotList = categorySpotRepository.findAllBySpot( - spotRepository.findById(s.getSpotId()).orElseThrow(()-> new IllegalArgumentException("존재하지 않는 사용자입니다.")) - ); - for (CategorySpot cs : categorySpotList) { - if (cs.getCategory().getId() == categoryId) { - filteredSpots.add(s); - } - } - } - return filteredSpots; - } }