diff --git a/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java b/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java index 8eb9edd..407d329 100644 --- a/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java +++ b/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java @@ -1,21 +1,12 @@ package com.mpnp.baechelin.api.controller; -import com.mpnp.baechelin.api.repository.MapQueryRepository; import com.mpnp.baechelin.api.service.LocationService; -import com.mpnp.baechelin.store.domain.Store; import com.mpnp.baechelin.store.repository.StoreRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Pageable; -import org.springframework.data.web.PageableDefault; -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; -import java.math.BigDecimal; -import java.util.List; - @RestController @RequiredArgsConstructor @Slf4j @@ -24,26 +15,4 @@ public class LocationController { private final LocationService locationService; private final StoreRepository storeRepository; - // TODO 위도, 경도를 두 개 받아 해당 범위 안에 있는 Store 리턴하기 - @GetMapping - public List giveStoreInRange(@RequestParam BigDecimal latStart, - @RequestParam BigDecimal latEnd, - @RequestParam BigDecimal lngStart, - @RequestParam BigDecimal lngEnd, - // sort 기준 정하기 - //@PageableDefault(sort = {""}, direction = Sort.Direction.DESC) Pageable pageable){ - @PageableDefault Pageable pageable) { - // TODO 페이징 적용 - log.info("latStart : {}", latStart); // 위도 - log.info("latEnd : {}", latEnd); // 위도 - log.info("lngStart : {}", lngStart); // 경도 - log.info("lngEnd : {}", lngEnd); // 경도 - return locationService.giveStoresByRange(latStart,latEnd,lngStart,lngEnd,pageable); - } - @GetMapping("/test") - public List storeTest(){ - return storeRepository.findAll(); - } - - } \ No newline at end of file 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 ca4cea8..8d8b409 100644 --- a/src/main/java/com/mpnp/baechelin/api/dto/PublicApiResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/api/dto/PublicApiResponseDto.java @@ -4,8 +4,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.mpnp.baechelin.api.model.LocationKeywordSearchForm; +import com.mpnp.baechelin.store.domain.Store; import lombok.*; +import java.math.BigDecimal; import java.util.List; @Builder @@ -46,9 +48,9 @@ public static class Result { public static class Row { @JsonProperty("SEQ") int SEQ; - String storeId; - String latitude; - String longitude; + Integer storeId; + BigDecimal latitude; + BigDecimal longitude; String category; @JsonProperty("SISULNAME") String SISULNAME; @@ -86,14 +88,5 @@ public static class Row { String ST11; @JsonProperty("ST12") String ST12; - public Row updateLatLng(String lat, String lng){ - this.latitude = lat; - this.longitude = lng; - return this; - } - public Row updateCategory(String category){ - this.category = category; - return this; - } } } 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 dac43c4..d942869 100644 --- a/src/main/java/com/mpnp/baechelin/api/service/LocationService.java +++ b/src/main/java/com/mpnp/baechelin/api/service/LocationService.java @@ -3,11 +3,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.mpnp.baechelin.config.httpclient.HttpConfig; import com.mpnp.baechelin.api.model.LocationKeywordSearchForm; -import com.mpnp.baechelin.store.domain.Store; -import com.mpnp.baechelin.api.repository.MapQueryRepository; +import com.mpnp.baechelin.store.controller.StoreQueryRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Pageable; import org.springframework.http.*; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.stereotype.Service; @@ -16,7 +14,6 @@ import org.springframework.web.util.UriComponentsBuilder; import javax.transaction.Transactional; -import java.math.BigDecimal; import java.net.URI; import java.util.*; @@ -26,7 +23,7 @@ @Transactional public class LocationService { private final HttpConfig httpConfig; - private final MapQueryRepository mapQueryRepository; + private final StoreQueryRepository storeQueryRepository; /** * @param address 주소 * @return LocationKeywordSearchForm의 규격에 맞는 결과 하나를 가져옴 @@ -124,7 +121,4 @@ public LocationKeywordSearchForm giveCategoryByLatLngKeywordRest(String lat, Str return resultRe.getBody(); } - public List giveStoresByRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, Pageable pageable) { - return mapQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, pageable); - } } 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 6d9ae72..78f6357 100644 --- a/src/main/java/com/mpnp/baechelin/api/service/PublicApiService.java +++ b/src/main/java/com/mpnp/baechelin/api/service/PublicApiService.java @@ -20,6 +20,7 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.util.UriComponentsBuilder; +import software.amazon.ion.Decimal; import javax.transaction.Transactional; import java.io.IOException; @@ -83,7 +84,7 @@ public class PublicApiService { // // } - public PublicApiResponseDto processApiToDBWithRestTemplate(PublicApiRequestDto publicApiRequestDto) throws UnsupportedEncodingException, JsonProcessingException { + public PublicApiResponseDto processApiToDBWithRestTemplate(PublicApiRequestDto publicApiRequestDto){ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_XML); headers.setAccept(List.of(MediaType.APPLICATION_JSON)); @@ -132,20 +133,20 @@ private boolean setRowLngLat(PublicApiResponseDto.Row row) throws JsonProcessing LocationKeywordSearchForm.Documents latLngDoc = Arrays.stream(latLngSearchForm.getDocuments()).findFirst().orElse(null); if (latLngDoc == null) return false; - row.setLatitude(latLngDoc.getY()); - row.setLongitude(latLngDoc.getX()); + row.setLatitude(Decimal.valueOf(latLngDoc.getY())); + row.setLongitude(Decimal.valueOf(latLngDoc.getX())); // 카테고리 ENUM으로 전환하기 row.setCategory(categoryFilter(Optional.of(latLngDoc.getCategory_name()).orElse("기타"))); return true; } private void setRowCategoryAndId(PublicApiResponseDto.Row row) throws JsonProcessingException { - LocationKeywordSearchForm categorySearchForm = locationService.giveCategoryByLatLngKeywordRest(row.getLatitude(), row.getLongitude(), row.getSISULNAME()); + LocationKeywordSearchForm categorySearchForm = locationService.giveCategoryByLatLngKeywordRest(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())) return; - row.setStoreId(categoryDoc.getId()); + row.setStoreId(Integer.parseInt(categoryDoc.getId())); row.setSISULNAME(categoryDoc.getPlace_name()); row.setCategory(categoryFilter(Optional.of(categoryDoc.getCategory_name()).orElse(null))); } diff --git a/src/main/java/com/mpnp/baechelin/api/repository/MapQueryRepository.java b/src/main/java/com/mpnp/baechelin/store/controller/StoreQueryRepository.java similarity index 82% rename from src/main/java/com/mpnp/baechelin/api/repository/MapQueryRepository.java rename to src/main/java/com/mpnp/baechelin/store/controller/StoreQueryRepository.java index f98a809..f342f46 100644 --- a/src/main/java/com/mpnp/baechelin/api/repository/MapQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreQueryRepository.java @@ -1,4 +1,4 @@ -package com.mpnp.baechelin.api.repository; +package com.mpnp.baechelin.store.controller; import com.mpnp.baechelin.store.domain.Store; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -14,21 +14,20 @@ @Repository @Transactional -public class MapQueryRepository extends QuerydslRepositorySupport { +public class StoreQueryRepository extends QuerydslRepositorySupport { private final JPAQueryFactory queryFactory; - public MapQueryRepository(JPAQueryFactory queryFactory) { + public StoreQueryRepository(JPAQueryFactory queryFactory) { super(Store.class); this.queryFactory = queryFactory; } - public List findBetweenLngLat(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, Pageable pageable) { - return queryFactory.selectFrom(store) + List storeList = queryFactory.selectFrom(store) .where(store.latitude.goe(latStart), store.latitude.loe(latEnd), store.longitude.goe(lngStart), @@ -36,5 +35,6 @@ public List findBetweenLngLat(BigDecimal latStart, .limit(pageable.getPageSize()) .offset(pageable.getOffset()) .fetch(); + return storeList; } } diff --git a/src/main/java/com/mpnp/baechelin/store/domain/Store.java b/src/main/java/com/mpnp/baechelin/store/domain/Store.java index ec9cf10..43f235c 100644 --- a/src/main/java/com/mpnp/baechelin/store/domain/Store.java +++ b/src/main/java/com/mpnp/baechelin/store/domain/Store.java @@ -60,7 +60,7 @@ public class Store { public Store(PublicApiResponseDto.Row row) { //storeId - 임시 - this.id = Integer.parseInt(row.getStoreId()); + this.id = row.getStoreId(); this.name = row.getSISULNAME(); this.address = row.getADDR(); this.phoneNumber = row.getTEL(); @@ -75,8 +75,8 @@ public Store(PublicApiResponseDto.Row row) { //화장실 this.toilet = row.getST5(); - this.latitude = new BigDecimal(row.getLatitude()); - this.longitude = new BigDecimal(row.getLongitude()); + this.latitude = row.getLatitude(); + this.longitude = row.getLongitude(); this.category = row.getCategory(); } diff --git a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java index be85fe5..df04e51 100644 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java +++ b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java @@ -24,41 +24,43 @@ public List getStoreList() { List storeResponseList = new ArrayList<>(); for (Store store : storeList) { - List reviewList = reviewRepository.findAllByStoreId(store); + storeResponseList.add(storeToResDto(store)); + } + + return storeResponseList; + } - double totalPoint = 0; + public StoreResponseDto storeToResDto(Store store){ + List reviewList = reviewRepository.findAllByStoreId(store); - double pointAvg = 0; - if (reviewList.size() > 0) { - for (Review review : reviewList) { - totalPoint += review.getPoint(); - } + double totalPoint = 0; - pointAvg = Double.parseDouble(String.format("%.1f", totalPoint / reviewList.size())); - } else { - pointAvg = 0; + double pointAvg = 0; + if (reviewList.size() > 0) { + for (Review review : reviewList) { + totalPoint += review.getPoint(); } - StoreResponseDto storeResponse = StoreResponseDto.builder() - .storeId(store.getId()) - .category(store.getCategory()) - .name(store.getName()) - .latitude(store.getLatitude()) - .longitude(store.getLongitude()) - .address(store.getAddress()) - .elevator(store.getElevator()) - .toilet(store.getToilet()) - .parking(store.getParking()) - .phoneNumber(store.getPhoneNumber()) - .heightDifferent(store.getHeightDifferent()) - .approach(store.getApproach()) - .storeImgList(null) - .pointAvg(pointAvg) - .build(); - storeResponseList.add(storeResponse); + pointAvg = Double.parseDouble(String.format("%.1f", totalPoint / reviewList.size())); + } else { + pointAvg = 0; } - - return storeResponseList; + return StoreResponseDto.builder() + .storeId(store.getId()) + .category(store.getCategory()) + .name(store.getName()) + .latitude(store.getLatitude()) + .longitude(store.getLongitude()) + .address(store.getAddress()) + .elevator(store.getElevator()) + .toilet(store.getToilet()) + .parking(store.getParking()) + .phoneNumber(store.getPhoneNumber()) + .heightDifferent(store.getHeightDifferent()) + .approach(store.getApproach()) + .storeImgList(null) + .pointAvg(pointAvg) + .build(); } } diff --git a/src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java b/src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java index 5b8775a..6785642 100644 --- a/src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java @@ -24,7 +24,7 @@ public class UserInfoResponseDto { public UserInfoResponseDto(User user) { this.name = user.getName(); - this.reviewList = user.getReviewList().stream().map(ReviewResponseDto::new).collect(Collectors.toList()); + this.reviewList = user.getReviewsList().stream().map(ReviewResponseDto::new).collect(Collectors.toList()); this.bookmarkFolderList = user.getFolderList().stream().map(BookmarkFolderResponseDto::new).collect(Collectors.toList()); //folder diff --git a/src/main/java/com/mpnp/baechelin/user/entity/user/User.java b/src/main/java/com/mpnp/baechelin/user/entity/user/User.java index 3e34a65..47d1ef4 100644 --- a/src/main/java/com/mpnp/baechelin/user/entity/user/User.java +++ b/src/main/java/com/mpnp/baechelin/user/entity/user/User.java @@ -79,10 +79,4 @@ public User(String socialId, this.providerType = providerType; this.roleType = roleType; } - - @OneToMany(mappedBy = "userId", cascade = CascadeType.ALL, orphanRemoval = true) - private List reviewList; - - @OneToMany(mappedBy = "userId", cascade = CascadeType.ALL, orphanRemoval = true) - private List folderList = new ArrayList<>(); }