Skip to content

Commit

Permalink
[feat] create search location api
Browse files Browse the repository at this point in the history
  • Loading branch information
Parkjyun committed Jul 12, 2024
1 parent 946b6bb commit 507eb45
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.hankki.hankkiserver.api.external.controller;

import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.api.dto.HankkiResponse;
import org.hankki.hankkiserver.api.external.service.ExternalService;
import org.hankki.hankkiserver.api.external.service.response.LocationsResponse;
import org.hankki.hankkiserver.common.code.CommonSuccessCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1")
public class ExternalController {

private final ExternalService externalService;

@GetMapping("/locations")
public HankkiResponse<LocationsResponse> getLocations(@RequestParam String query) {
return HankkiResponse.success(CommonSuccessCode.OK, externalService.getLocations(query));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.hankki.hankkiserver.api.external.service;

import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.api.external.service.response.LocationResponse;
import org.hankki.hankkiserver.api.external.service.response.LocationsResponse;
import org.hankki.hankkiserver.external.openfeign.naver.dto.NaverLocationsDto;
import org.hankki.hankkiserver.external.openfeign.naver.NaverFeignClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class ExternalService {

@Value("${naver.clientId}")
private String clientId;
@Value("${naver.clientSecret}")
private String clientSecret;
private static final int DEFAULT_SEARCH_SIZE = 5;

private final NaverFeignClient naverFeignClient;

public LocationsResponse getLocations(String query) {
NaverLocationsDto locationsDto = naverFeignClient.getLocationInfo(clientId, clientSecret, query, DEFAULT_SEARCH_SIZE);
return LocationsResponse.of(locationsDto.items().stream()
.map(LocationResponse::of)
.collect(Collectors.toList()));
}
}

0 comments on commit 507eb45

Please sign in to comment.