Skip to content

Commit

Permalink
#9 [Add] 신규 API 추가 및 매핑 / 저장 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 18, 2022
1 parent 39b8560 commit ce78075
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import com.mpnp.baechelin.api.dto.PublicApiRequestDto;
import com.mpnp.baechelin.api.dto.PublicApiResponseDto;
import com.mpnp.baechelin.api.model.PublicApiForm;
import com.mpnp.baechelin.api.service.PublicApiService;
import com.mpnp.baechelin.api.service.PublicNewApiService;
import com.mpnp.baechelin.store.dto.StoreCardResponseDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.io.IOException;
import java.util.List;

import static java.lang.System.currentTimeMillis;

Expand All @@ -21,7 +19,6 @@
@Slf4j
public class PublicApiController {
private final PublicApiService publicApiService;
private final PublicNewApiService publicNewApiService;
@PostMapping("/api")
public ResponseEntity<String> findPublicApi(@RequestBody PublicApiRequestDto publicApiRequestDto) throws IOException {
long start = currentTimeMillis();
Expand All @@ -32,11 +29,11 @@ public ResponseEntity<String> findPublicApi(@RequestBody PublicApiRequestDto pub
}
//TODO 정리하기
@GetMapping("/new-api")
public ResponseEntity<PublicApiForm> findNewPublicApi(@RequestParam String serviceKey,
public ResponseEntity<List<StoreCardResponseDto>> findNewPublicApi(@RequestParam String serviceKey,
@RequestParam int rslSize,
@RequestParam String siDoNm){
PublicApiForm publicApiForm = publicNewApiService.processNewApi(serviceKey, rslSize, siDoNm);
return ResponseEntity.ok(publicApiForm);
List<StoreCardResponseDto> result = publicApiService.processNewApi(serviceKey, rslSize, siDoNm);
return ResponseEntity.ok(result);
}

}
30 changes: 30 additions & 0 deletions src/main/java/com/mpnp/baechelin/api/model/BarrierCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mpnp.baechelin.api.model;

import lombok.Getter;

import java.util.Arrays;

@Getter
public enum BarrierCode {
ELEVATOR("계단 또는 승강설비", "elevator"),
TOILET_A("소변기", "toilet"),
TOILET_B("대변기", "toilet"),
PARKING("장애인전용주차구역", "parking"),
HEIGHT_DIFFERENCE("주출입구 높이차이 제거", "height_different"),
APPROACH("주출입구 접근로", "approach"),
ETC("", null);
private final String desc;
private final String columnName;

BarrierCode(String desc, String columnName) {
this.desc = desc;
this.columnName = columnName;
}

public static String getColumnFromDesc(String desc) {
BarrierCode barrierCode = Arrays.stream(BarrierCode.values())
.filter(b -> b.getDesc().equals(desc)).findFirst().orElse(ETC);
return barrierCode.getColumnName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class ServList{
private String faclInfId;
private String faclLat;
private String faclLng;
private String faclNm;
private String faclRprnNm;
private String faclTyCd;
private String lcMnad;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ public LocationKeywordSearchForm giveLatLngByAddressRest(String address) throws
}

public LocationKeywordSearchForm giveCategoryByLatLngKeywordRest(String lat, String lng, String storeName) {
LocationKeywordSearchForm searchFormResult = giveCategoryByCode(lat, lng, storeName, "FD6");
if (searchFormResult == null) {
return giveCategoryByCode(lat, lng, storeName, "CE7");
}
return searchFormResult;
}

public LocationKeywordSearchForm giveCategoryByCode(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 All @@ -128,6 +136,7 @@ public LocationKeywordSearchForm giveCategoryByLatLngKeywordRest(String lat, Str
.queryParam("query", storeName)
.queryParam("x", lng)//위도, 경도 지정
.queryParam("y", lat)
.queryParam("category_group_code", cateCode)
.queryParam("radius", 200)
.queryParam("page", 1)
.queryParam("size", 1)
Expand All @@ -140,7 +149,6 @@ public LocationKeywordSearchForm giveCategoryByLatLngKeywordRest(String lat, Str
uri, HttpMethod.GET, new HttpEntity<>(headers), LocationKeywordSearchForm.class
);
return resultRe.getBody();

}

public Map<String, Object> convertGeoAndStoreNameToKeyword(String lat, String lng, String storeName) {
Expand All @@ -157,6 +165,7 @@ public Map<String, Object> convertGeoAndStoreNameToKeyword(String lat, String ln
map.put("category", categoryFilter(latLngDoc.getCategory_name()));
map.put("storeId", Integer.parseInt(latLngDoc.getId()));
map.put("storeName", latLngDoc.getPlace_name());
map.put("phoneNumber", latLngDoc.getPhone());
map.put("status", true);
} else {
map.put("status", false);
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/com/mpnp/baechelin/store/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public Store(PublicApiResponseDto.Row row) {
this.category = row.getCategory();
}

public Store updateBookmarkCount(int upOrDown){
public Store updateBookmarkCount(int upOrDown) {
this.bookMarkCount += upOrDown;
return this;
}

// TODO 리뷰가 삭제될 때도 고려하기 - 삭제 후 적용되어야 함
public Store updatePointAvg(double changePoint){
public Store updatePointAvg(double changePoint) {
this.reviewCount = reviewList.size();
double totalPoint = 0.0;
for (Review review : reviewList) {
Expand All @@ -109,10 +109,21 @@ public Store updatePointAvg(double changePoint){
return this;
}

public Store publicApiAndTagToStore(PublicApiForm.ServList servList, List<String> barrierTagList) {
// TagList 매핑 및 생성
// Store 매핑 및 생성
return null;
public Store(int storeId, PublicApiForm.ServList servList, List<String> barrierTagList,
String phoneNumber, String category, String storeName) {
this.id = storeId;
this.name = storeName;
this.latitude = new BigDecimal(servList.getFaclLat());
this.longitude = new BigDecimal(servList.getFaclLng());
this.address = servList.getLcMnad();
this.elevator = barrierTagList.contains("elevator") ? "Y" : "N";
this.heightDifferent = barrierTagList.contains("heightDifferent") ? "Y" : "N";
this.toilet = barrierTagList.contains("toilet") ? "Y" : "N";
this.parking = barrierTagList.contains("parking") ? "Y" : "N";
this.approach = barrierTagList.contains("approach") ? "Y" : "N";

this.phoneNumber = phoneNumber;
this.category = category;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -29,15 +30,27 @@ public class StoreCardResponseDto implements Comparable<StoreCardResponseDto> {
private String phoneNumber;
private String heightDifferent;
private String approach;
private List<StoreImgResponseDto> storeImgList;
private List<StoreImgResponseDto> storeImgList = new ArrayList<>();
private int bookmarkCount;
private String bookmark;

@Builder.Default
private double pointAvg = 0.0;

public StoreCardResponseDto(Store store) {

this.storeId = store.getId();
this.category = store.getCategory();
this.name = store.getName();
this.latitude = store.getLatitude();
this.longitude = store.getLongitude();
this.address = store.getAddress();
this.elevator = store.getElevator();
this.toilet = store.getToilet();
this.parking = store.getParking();
this.phoneNumber = store.getPhoneNumber();
this.heightDifferent = store.getHeightDifferent();
this.approach = store.getApproach();
this.bookmarkCount = store.getBookMarkCount();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.mpnp.baechelin.store.repository;

import com.mpnp.baechelin.config.QuerydslLocation;
import com.mpnp.baechelin.review.domain.Review;
import com.mpnp.baechelin.store.domain.Store;
import com.mpnp.baechelin.store.dto.StoreCardResponseDto;
import com.mpnp.baechelin.store.dto.StoreResponseDto;
import com.mpnp.baechelin.user.domain.User;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -19,7 +16,6 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.stream.Collectors;

import static com.mpnp.baechelin.config.QuerydslLocation.locTwoPointAndConditions;
import static com.mpnp.baechelin.store.domain.QStore.store;
Expand Down

0 comments on commit ce78075

Please sign in to comment.