Skip to content

Commit

Permalink
Merge pull request #18 from NARAE-FLIWITH/feat/areaBased
Browse files Browse the repository at this point in the history
feat: 위치기반 모든 유형 관광지 목록 조회
  • Loading branch information
jjunjji authored May 22, 2024
2 parents e4f0f59 + b3c89af commit 1bd64ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
public class TourController {

private final TourService tourService;
// @GetMapping("/tour")
// public ResponseEntity<BaseRes<List<TourType>>> getTourByType(@AuthenticationPrincipal CustomUser customUser, @RequestParam String latitude, @RequestParam String longitude, @RequestParam String contentTypeId){
// return ResponseEntity.ok(BaseRes.create(HttpStatus.OK.value(), "관광지 목록 조회에 성공했습니다.", tourService.getTourByType(
// customUser.getEmail(), latitude, longitude, contentTypeId)));
// }

@GetMapping("/tour")
public ResponseEntity<BaseRes<List<TourType>>> getTourByType(@AuthenticationPrincipal CustomUser customUser, @RequestParam String latitude, @RequestParam String longitude, @RequestParam String contentTypeId){
return ResponseEntity.ok(BaseRes.create(HttpStatus.OK.value(), "관광지 목록 조회에 성공했습니다.", tourService.getTourByType(
customUser.getEmail(), latitude, longitude, contentTypeId)));
public ResponseEntity<BaseRes<List<TourType>>> getTourByType(@AuthenticationPrincipal CustomUser customUser, @RequestParam double latitude, @RequestParam double longitude){
return ResponseEntity.ok(BaseRes.create(HttpStatus.OK.value(), "위치기반 모든 유형의 관광지 목록 조회에 성공했습니다.", tourService.getNearEveryTourType(
customUser.getEmail(), latitude, longitude)));
}

@GetMapping("/tour/{contentTypeId}/{contentId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package com.narae.fliwith.repository;

import com.narae.fliwith.domain.Location;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface LocationRepository extends JpaRepository<Location, Long> {
@Query(value = "select * from location l " +
"where (6371 * acos(cos(radians(:curLat)) * cos(radians(l.latitude)) " +
"* cos(radians(l.longitude) - radians(:curLong)) " +
"+ sin(radians(:curLat)) * sin(radians(l.latitude)))) <= 3", nativeQuery = true)
List<Location> findNearEverySpotType(@Param("curLat")Double curLatitude, @Param("curLong")Double curLongitude);

}
33 changes: 8 additions & 25 deletions src/main/java/com/narae/fliwith/service/openAPI/TourService.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,15 @@ public Mono<DetailIntroRes.Item> getDetailIntro(String contentId, String content
.onErrorReturn(DecodingException.class, new DetailIntroRes.Item());
}

public List<TourType> getTourByType(String email, String latitude, String longitude, String contentTypeId) {
public List<TourType> getNearEveryTourType(String email, double latitude, double longitude) {
User user = authService.authUser(email);
return webClient.get()
.uri(uriBuilder ->
uriBuilder.path("/locationBasedList1")
.queryParam("MobileOS", "AND")
.queryParam("MobileApp", "fliwith")
.queryParam("mapX", longitude)
.queryParam("mapY", String.valueOf(latitude))
.queryParam("radius", "1500")
.queryParam("_type", "json")
.queryParam("contentTypeId", String.valueOf(contentTypeId))
.queryParam("serviceKey", serviceKey)
.build()
)
.retrieve()
.bodyToFlux(new ParameterizedTypeReference<LocationBasedListRes.Root>() {
})
.map(root -> root.getResponse().getBody().getItems().getItem().stream()
.map(item -> TourType.builder().contentId(Integer.parseInt(item.getContentid())).contentTypeId(Integer.parseInt(item.getContenttypeid())).latitude(
Double.parseDouble(item.getMapy())).longitude(Double.parseDouble(item.getMapx())).build()).collect(
Collectors.toList()))
.onErrorReturn(DecodingException.class, new ArrayList<>())
.blockFirst();
//TODO: DB에 관광지 미리 저장해두고, 조회하는 걸로 로직 변경하기

return locationRepository.findNearEverySpotType(latitude, longitude).stream()
.map(location -> TourType.builder()
.contentTypeId(location.getSpot().getContentTypeId())
.contentId(location.getSpot().getId())
.latitude(location.getLatitude())
.longitude(location.getLongitude()).build())
.collect(Collectors.toList());
}

public TourDetailRes getTour(String email, String contentTypeId, String contentId) {
Expand Down

0 comments on commit 1bd64ba

Please sign in to comment.