diff --git a/src/main/java/com/mpnp/baechelin/api/controller/PublicApiController.java b/src/main/java/com/mpnp/baechelin/api/controller/PublicApiController.java index 3671e64..ef41810 100644 --- a/src/main/java/com/mpnp/baechelin/api/controller/PublicApiController.java +++ b/src/main/java/com/mpnp/baechelin/api/controller/PublicApiController.java @@ -1,17 +1,14 @@ package com.mpnp.baechelin.api.controller; import com.mpnp.baechelin.api.dto.PublicApiRequestDto; -import com.mpnp.baechelin.api.dto.PublicApiResponseDto; import com.mpnp.baechelin.api.service.PublicApiService; -import com.mpnp.baechelin.store.dto.StoreCardResponseDto; +import com.mpnp.baechelin.common.SuccessResponse; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.io.IOException; -import java.util.List; import static java.lang.System.currentTimeMillis; @@ -23,21 +20,21 @@ public class PublicApiController { private final PublicApiService publicApiService; @ApiOperation(value="공공 API V1을 통해 DB에 정보를 저장/업데이트하는 함수") @PostMapping("/api") - public ResponseEntity findPublicApi(@RequestBody PublicApiRequestDto publicApiRequestDto) throws IOException { + public SuccessResponse getPublicApi(@RequestBody PublicApiRequestDto publicApiRequestDto) throws IOException { long start = currentTimeMillis(); publicApiService.processApiToDBWithRestTemplate(publicApiRequestDto); // ResponseEntity result = ResponseEntity.ok(publicApiService.processApiToDBWithWebclientMono(publicApiRequestDto)); log.info("Elapsed Time : {}", currentTimeMillis() - start); - return ResponseEntity.ok("공공 API 저장 완료"); + return new SuccessResponse("공공 API V1 적용 완료"); } //TODO 정리하기 @ApiOperation(value="공공 API V2을 통해 DB에 정보를 저장/업데이트하는 함수") @GetMapping("/new-api") - public ResponseEntity findNewPublicApi(@RequestParam String serviceKey, - @RequestParam int rslSize, - @RequestParam String siDoNm){ + public SuccessResponse getPublicApiV2(@RequestParam String serviceKey, + @RequestParam int rslSize, + @RequestParam String siDoNm){ publicApiService.processNewApi(serviceKey, rslSize, siDoNm); - return ResponseEntity.ok("공공 API V2 저장 완료"); + return new SuccessResponse("공공 API V2 적용 완료"); } } diff --git a/src/main/java/com/mpnp/baechelin/api/dto/PublicApiRequestDto.java b/src/main/java/com/mpnp/baechelin/api/dto/PublicApiRequestDto.java index a220556..b468ece 100644 --- a/src/main/java/com/mpnp/baechelin/api/dto/PublicApiRequestDto.java +++ b/src/main/java/com/mpnp/baechelin/api/dto/PublicApiRequestDto.java @@ -5,8 +5,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder -@Getter -@Setter +@Getter @Setter public class PublicApiRequestDto { private String key; private String type; diff --git a/src/main/java/com/mpnp/baechelin/api/dto/PublicApiResponseDto.java b/src/main/java/com/mpnp/baechelin/api/dto/PublicApiResponseDto.java index 8d8b409..b8ea89d 100644 --- a/src/main/java/com/mpnp/baechelin/api/dto/PublicApiResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/api/dto/PublicApiResponseDto.java @@ -88,5 +88,8 @@ public static class Row { String ST11; @JsonProperty("ST12") String ST12; + public boolean validation(){ + return this.latitude != null && this.longitude != null && this.category != null && this.storeId != null; + } } } diff --git a/src/main/java/com/mpnp/baechelin/api/model/PublicApiCategoryForm.java b/src/main/java/com/mpnp/baechelin/api/model/PublicApiCategoryForm.java index 57668cd..c6a712f 100644 --- a/src/main/java/com/mpnp/baechelin/api/model/PublicApiCategoryForm.java +++ b/src/main/java/com/mpnp/baechelin/api/model/PublicApiCategoryForm.java @@ -5,7 +5,6 @@ import lombok.Setter; import javax.xml.bind.annotation.XmlRootElement; -import java.util.ArrayList; import java.util.List; @NoArgsConstructor @@ -23,7 +22,7 @@ public static class ServList{ private String evalInfo; private String faclNm; private String wfcltId; - public boolean validateServList(){ + public boolean validation(){ return this.evalInfo != null; } } diff --git a/src/main/java/com/mpnp/baechelin/api/service/LocationService.java b/src/main/java/com/mpnp/baechelin/api/service/LocationService.java index 00fcae8..dae3579 100644 --- a/src/main/java/com/mpnp/baechelin/api/service/LocationService.java +++ b/src/main/java/com/mpnp/baechelin/api/service/LocationService.java @@ -1,6 +1,5 @@ package com.mpnp.baechelin.api.service; -import com.fasterxml.jackson.core.JsonProcessingException; import com.mpnp.baechelin.api.model.LocationAddressSearchForm; import com.mpnp.baechelin.common.httpclient.HttpConfig; import com.mpnp.baechelin.api.model.LocationKeywordSearchForm; @@ -29,7 +28,7 @@ public class LocationService { * @param address 주소 * @return LocationKeywordSearchForm의 규격에 맞는 결과 하나를 가져옴 */ - public LocationKeywordSearchForm giveLatLngByAddress(String address) { + public LocationKeywordSearchForm getLatLngByAddress(String address) { WebClient client = WebClient.builder() .baseUrl("https://dapi.kakao.com/v2/local/search/keyword.json") .defaultUriVariables(Collections.singletonMap("url", "https://dapi.kakao.com/v2/local/search/keyword.json")) @@ -55,7 +54,7 @@ public LocationKeywordSearchForm giveLatLngByAddress(String address) { * @param storeName 업장명 * @return 위도, 경도, 업장명을 만족하는 장소 찾기 */ - public LocationKeywordSearchForm giveCategoryByLatLngKeyword(String lat, String lng, String storeName) { + public LocationKeywordSearchForm getCategoryByLatLngKeyword(String lat, String lng, String storeName) { WebClient client = WebClient.builder() .baseUrl("https://dapi.kakao.com/v2/local/search/keyword.json") .defaultUriVariables(Collections.singletonMap("url", "https://dapi.kakao.com/v2/local/search/keyword.json")) @@ -85,7 +84,7 @@ public LocationKeywordSearchForm giveCategoryByLatLngKeyword(String lat, String public Map convertAddressToGeo(String address) { Map map = new HashMap<>(); // status, latitude, longitude 를 키로 가지는 HashMap 생성 - LocationKeywordSearchForm locationKeywordSearchForm = giveLatLngByAddress(address); + LocationKeywordSearchForm locationKeywordSearchForm = getLatLngByAddress(address); // latLngDoc.getY() if (locationKeywordSearchForm == null) { map.put("status", false); @@ -107,7 +106,7 @@ public Map convertAddressToGeo(String address) { * @param address 변환할 주소 * @return RestTemplate를 이용해 변환한 위도, 경도 */ - public LocationKeywordSearchForm giveLatLngByAddressRest(String address) { + public LocationKeywordSearchForm getLatLngByAddressRest(String address) { HttpHeaders headers = new HttpHeaders(); headers.setAccept(List.of(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); @@ -128,10 +127,10 @@ public LocationKeywordSearchForm giveLatLngByAddressRest(String address) { return resultRe.getBody(); } - public LocationKeywordSearchForm giveCategoryByLatLngKeywordRest(String lat, String lng, String storeName) { - LocationKeywordSearchForm searchFormResult = giveCategoryByCode(lat, lng, storeName, "FD6"); + public LocationKeywordSearchForm getCategoryByLatLngKeywordRest(String lat, String lng, String storeName) { + LocationKeywordSearchForm searchFormResult = getCategoryByCode(lat, lng, storeName, "FD6"); if (searchFormResult == null) { - return giveCategoryByCode(lat, lng, storeName, "CE7"); + return getCategoryByCode(lat, lng, storeName, "CE7"); } return searchFormResult; } @@ -143,7 +142,7 @@ public LocationKeywordSearchForm giveCategoryByLatLngKeywordRest(String lat, Str * @param cateCode 카테고리 코드 * @return 위도, 경도, 업장명, 카테고리 코드 조건에 맞는 정보를 리턴 */ - public LocationKeywordSearchForm giveCategoryByCode(String lat, String lng, String storeName, String cateCode) { + public LocationKeywordSearchForm getCategoryByCode(String lat, String lng, String storeName, String cateCode) { HttpHeaders headers = new HttpHeaders(); headers.setAccept(List.of(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); @@ -177,7 +176,7 @@ public LocationKeywordSearchForm giveCategoryByCode(String lat, String lng, Stri public Map convertGeoAndStoreNameToKeyword(String lat, String lng, String storeName) { Map map = new HashMap<>(); // status?, latitude, longitude 를 키로 가지는 HashMap 생성 - LocationKeywordSearchForm locationKeywordSearchForm = giveCategoryByLatLngKeywordRest(lat, lng, storeName); + LocationKeywordSearchForm locationKeywordSearchForm = getCategoryByLatLngKeywordRest(lat, lng, storeName); // latLngDoc.getY() if (locationKeywordSearchForm == null) { map.put("status", false); diff --git a/src/main/java/com/mpnp/baechelin/api/service/PublicApiService.java b/src/main/java/com/mpnp/baechelin/api/service/PublicApiService.java index deeb13d..9f1875c 100644 --- a/src/main/java/com/mpnp/baechelin/api/service/PublicApiService.java +++ b/src/main/java/com/mpnp/baechelin/api/service/PublicApiService.java @@ -118,7 +118,7 @@ private void setInfos(PublicApiResponseDto publicApiResponseDto) { private boolean setRowLngLat(PublicApiResponseDto.Row row) throws JsonProcessingException { - LocationKeywordSearchForm latLngSearchForm = locationService.giveLatLngByAddressRest(row.getADDR()); + LocationKeywordSearchForm latLngSearchForm = locationService.getLatLngByAddressRest(row.getADDR()); // LocationKeywordSearchForm latLngSearchForm = locationService.giveLatLngByAddress(row.getADDR()); if (latLngSearchForm == null) return false; LocationKeywordSearchForm.Documents latLngDoc = Arrays.stream(latLngSearchForm.getDocuments()).findFirst().orElse(null); @@ -132,7 +132,7 @@ private boolean setRowLngLat(PublicApiResponseDto.Row row) throws JsonProcessing private void setRowCategoryAndId(PublicApiResponseDto.Row row) throws JsonProcessingException { LocationKeywordSearchForm categorySearchForm = locationService - .giveCategoryByLatLngKeywordRest(String.valueOf(row.getLatitude()), String.valueOf(row.getLongitude()), row.getSISULNAME()); + .getCategoryByLatLngKeywordRest(String.valueOf(row.getLatitude()), String.valueOf(row.getLongitude()), row.getSISULNAME()); // LocationKeywordSearchForm categorySearchForm = locationService.giveCategoryByLatLngKeyword(row.getLatitude(), row.getLongitude(), row.getSISULNAME()); LocationKeywordSearchForm.Documents categoryDoc = Arrays.stream(categorySearchForm.getDocuments()).findFirst().orElse(null); if (categoryDoc == null || !Arrays.asList("FD6", "CE7").contains(categoryDoc.getCategory_group_code()))