Skip to content

Commit

Permalink
Merge pull request #42 from UMC-HACKATHON-SnapSpot/feat/#25
Browse files Browse the repository at this point in the history
feat: 반경 500미터 필터링
  • Loading branch information
2hy2on authored Jul 4, 2024
2 parents 3f77940 + abc1968 commit 5fe57d5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ public ResponseEntity<?> showAllCategories() {
}
}

@GetMapping("/spots")
public ResponseEntity<?> showSpotsByCategoryId(
@RequestParam List<Long> categoryIds
) {
try {
List<Spot> 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<Long> categoryIds
// ) {
// try {
// List<Spot> spots = categoryService.showSpotsByCategoryIds(categoryIds);
// return ResponseEntity.ok().body(spots);
// } catch (Exception e){
// log.info("카테고리별 스팟 리스트 조회에 실패하였습니다.", e);
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("카테고리별 스팟 리스트 조회에 실패하였습니다.");
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CategorySpot, Long> {
List<CategorySpot> findAllByCategory(Category category);

List<CategorySpot> findAllBySpot(Spot spot);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RequiredArgsConstructor
@RestController
Expand Down Expand Up @@ -75,14 +77,16 @@ public ResponseEntity<?> patchSpot(
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("스팟 수정에 실패하였습니다.");
}
}


@GetMapping("list")
public ResponseEntity<List<SpotResponseDto>> readNearSpotList(@RequestParam("latitude") double latitude, @RequestParam("longitude") double longitude){
return ResponseEntity.ok(spotService.readNearSpotList(latitude, longitude));
}
@GetMapping("list/category")

@GetMapping("list/category")
public ResponseEntity<List<SpotResponseDto>> readCategoryNearSpotList(@RequestParam("latitude") double latitude, @RequestParam("longitude") double longitude, @RequestParam("categoryId") Long categoryId){
List<SpotResponseDto> list = spotService.readNearSpotList(latitude, longitude);
return ResponseEntity.ok(spotService.readCategoryNearSpotList(list, categoryId));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,21 @@ public List<SpotResponseDto> readNearSpotList(double latitude, double longitude)
List<Spot> spotList = spotRepository.findSpotsWithinDistance(latitude, longitude, 0.5);
return SpotConverter.toDtoList(spotList);
}


public List<SpotResponseDto> readCategoryNearSpotList(List<SpotResponseDto> spotList, Long categoryId) {
List<SpotResponseDto> filteredSpots = new ArrayList<>();

for (SpotResponseDto s : spotList) {
List<CategorySpot> categorySpotList = categorySpotRepository.findAllBySpot(
spotRepository.findById(s.getSpotId()).orElseThrow(()-> new IllegalArgumentException("존재하지 않는 사용자입니다."))
);
for (CategorySpot cs : categorySpotList) {
if (cs.getCategory().getId() == categoryId) {
filteredSpots.add(s);
}
}
}
return filteredSpots;
}
}

0 comments on commit 5fe57d5

Please sign in to comment.