Skip to content

Commit

Permalink
#18 [Refactor] 함수명 통일 및 Validation 정정
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 19, 2022
1 parent 802da56 commit fa11a34
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,21 +20,21 @@ public class PublicApiController {
private final PublicApiService publicApiService;
@ApiOperation(value="공공 API V1을 통해 DB에 정보를 저장/업데이트하는 함수")
@PostMapping("/api")
public ResponseEntity<String> findPublicApi(@RequestBody PublicApiRequestDto publicApiRequestDto) throws IOException {
public SuccessResponse getPublicApi(@RequestBody PublicApiRequestDto publicApiRequestDto) throws IOException {
long start = currentTimeMillis();
publicApiService.processApiToDBWithRestTemplate(publicApiRequestDto);
// ResponseEntity<PublicApiResponseDto> 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<String> 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 적용 완료");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Setter
@Getter @Setter
public class PublicApiRequestDto {
private String key;
private String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Setter;

import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor
Expand All @@ -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;
}
}
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/mpnp/baechelin/api/service/LocationService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -85,7 +84,7 @@ public LocationKeywordSearchForm giveCategoryByLatLngKeyword(String lat, String
public Map<String, Object> convertAddressToGeo(String address) {
Map<String, Object> map = new HashMap<>();
// status, latitude, longitude 를 키로 가지는 HashMap 생성
LocationKeywordSearchForm locationKeywordSearchForm = giveLatLngByAddress(address);
LocationKeywordSearchForm locationKeywordSearchForm = getLatLngByAddress(address);
// latLngDoc.getY()
if (locationKeywordSearchForm == null) {
map.put("status", false);
Expand All @@ -107,7 +106,7 @@ public Map<String, Object> 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);
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -177,7 +176,7 @@ public LocationKeywordSearchForm giveCategoryByCode(String lat, String lng, Stri
public Map<String, Object> convertGeoAndStoreNameToKeyword(String lat, String lng, String storeName) {
Map<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()))
Expand Down

0 comments on commit fa11a34

Please sign in to comment.