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 eb82659..c58aa16 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 a15fbda..3d9401d 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,10 +2,14 @@ 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 ef88f25..5638934 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 @@ -10,6 +10,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RequiredArgsConstructor @RestController @@ -75,14 +77,16 @@ 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 3480c43..c27a2d0 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,8 +1,10 @@ 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 dcd003f..71d3705 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 @@ -84,4 +84,21 @@ 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; + } }