diff --git a/build.gradle b/build.gradle index dbdb451..06287a0 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,8 @@ dependencies { compileOnly 'org.projectreactor:reactor-spring:1.0.1.RELEASE' compileOnly 'org.apache.httpcomponents:httpclient:4.5.13' implementation 'org.springframework.boot:spring-boot-starter-reactor-netty:2.7.1' - + //tomcat + implementation 'org.springframework.boot:spring-boot-starter-tomcat' // OAuth2 implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.7.0' // jwt diff --git a/src/main/java/com/mpnp/baechelin/config/QuerydslConfiguration.java b/src/main/java/com/mpnp/baechelin/config/QuerydslConfiguration.java index b5d5680..1a30435 100644 --- a/src/main/java/com/mpnp/baechelin/config/QuerydslConfiguration.java +++ b/src/main/java/com/mpnp/baechelin/config/QuerydslConfiguration.java @@ -1,11 +1,15 @@ package com.mpnp.baechelin.config; +import com.querydsl.core.BooleanBuilder; import com.querydsl.jpa.impl.JPAQueryFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import java.math.BigDecimal; + +import static com.mpnp.baechelin.store.domain.QStore.store; @Configuration public class QuerydslConfiguration { @@ -17,4 +21,11 @@ public class QuerydslConfiguration { public JPAQueryFactory jpaQueryFactory() { return new JPAQueryFactory(entityManager); } + + public static void locationBuilder(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, BooleanBuilder builder) { + builder.and(latStart == null ? null : store.latitude.goe(latStart)); + builder.and(latEnd == null ? null : store.latitude.loe(latEnd)); + builder.and(lngStart == null ? null : store.longitude.goe(lngStart)); + builder.and(lngEnd == null ? null : store.longitude.loe(lngEnd)); + } } diff --git a/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java b/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java index fb8c647..aa412d6 100644 --- a/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java +++ b/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java @@ -1,7 +1,9 @@ package com.mpnp.baechelin.review.controller; +import com.mpnp.baechelin.review.dto.ReviewMainResDto; import com.mpnp.baechelin.review.dto.ReviewReqDTO; import com.mpnp.baechelin.review.dto.ReviewResDTO; +import com.mpnp.baechelin.review.repository.ReviewQueryRepository; import com.mpnp.baechelin.review.service.ReviewService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; @@ -11,14 +13,20 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.math.BigDecimal; +import java.util.List; +import java.util.stream.Collectors; @RestController @RequiredArgsConstructor public class ReviewController { private final ReviewService reviewService; + private final ReviewQueryRepository reviewQueryRepository; - /**리뷰 작성*/ + /** + * 리뷰 작성 + */ @PostMapping("/review") public ReviewResDTO review(@RequestParam double point, @RequestParam String comment, @@ -26,7 +34,7 @@ public ReviewResDTO review(@RequestParam double point, @RequestParam int userId, @RequestParam(required = false) MultipartFile imageFile) throws IOException { - ReviewReqDTO reviewReqDTO =new ReviewReqDTO(); + ReviewReqDTO reviewReqDTO = new ReviewReqDTO(); ReviewReqDTO .builder() .point(point) @@ -39,9 +47,32 @@ public ReviewResDTO review(@RequestParam double point, reviewService.review(reviewReqDTO); return null; } + // TODO - 최근 등록한 리뷰 보여주기 + // 반경 넓히기 @GetMapping("/recent-review") - public ReviewResDTO recentReview(){ - return null; + public List recentReview(@RequestParam(required = false) BigDecimal lat, + @RequestParam(required = false) BigDecimal lng, + @RequestParam int limit) { + + BigDecimal[] locationRange = getRange(lat, lng, 20); + + + List result = reviewQueryRepository + .findRecentReviews(locationRange[0], locationRange[1], locationRange[2], locationRange[3], limit) + .stream().map(ReviewMainResDto::new).collect(Collectors.toList()); + return result; + } + + // km : 반경 + private BigDecimal[] getRange(BigDecimal lat, BigDecimal lng, int km) { + // km->lat,lng로 변환하기 + final BigDecimal latitude = BigDecimal.valueOf(km / 110.569); // 반경 + final BigDecimal longitutde = BigDecimal.valueOf(km / 111.322); + // 남서, 북동으로 받아오기 + // start lat-lng, end lat-lng으로 Array 받아오기 + return new BigDecimal[]{lat.subtract(latitude), lat.add(latitude), + lng.subtract(longitutde), lng.add(longitutde)}; } + } diff --git a/src/main/java/com/mpnp/baechelin/review/dto/ReviewMainResDto.java b/src/main/java/com/mpnp/baechelin/review/dto/ReviewMainResDto.java new file mode 100644 index 0000000..a003fcc --- /dev/null +++ b/src/main/java/com/mpnp/baechelin/review/dto/ReviewMainResDto.java @@ -0,0 +1,24 @@ +package com.mpnp.baechelin.review.dto; + +import com.mpnp.baechelin.review.domain.Review; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ReviewMainResDto { + // review 테이블 컬럼 + private String comment; //리뷰 코멘트 + private double point; //별점 + private String imageFileUrl; //리뷰 이미지 사진 + + public ReviewMainResDto(Review review) { + this.comment = review.getReview(); + this.point = review.getPoint(); + this.imageFileUrl = review.getReviewImageUrl(); + } +} \ No newline at end of file diff --git a/src/main/java/com/mpnp/baechelin/review/repository/ReviewQueryRepository.java b/src/main/java/com/mpnp/baechelin/review/repository/ReviewQueryRepository.java index 83a1ec2..5876149 100644 --- a/src/main/java/com/mpnp/baechelin/review/repository/ReviewQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/review/repository/ReviewQueryRepository.java @@ -1,8 +1,7 @@ package com.mpnp.baechelin.review.repository; -import com.mpnp.baechelin.review.domain.QReview; import com.mpnp.baechelin.review.domain.Review; -import com.mpnp.baechelin.store.domain.Store; +import com.mpnp.baechelin.store.domain.QStore; import com.querydsl.core.BooleanBuilder; import com.querydsl.jpa.impl.JPAQueryFactory; import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; @@ -12,8 +11,10 @@ import java.math.BigDecimal; import java.util.List; +import static com.mpnp.baechelin.config.QuerydslConfiguration.locationBuilder; import static com.mpnp.baechelin.review.domain.QReview.review1; import static com.mpnp.baechelin.store.domain.QStore.store; +import static com.querydsl.jpa.JPAExpressions.select; @Repository @Transactional @@ -31,17 +32,16 @@ public List findRecentReviews(BigDecimal latStart, BigDecimal lngStart, BigDecimal lngEnd, int limit) { - builder.and(store.latitude.goe(latStart)); - builder.and(store.latitude.loe(latEnd)); - builder.and(store.longitude.goe(lngStart)); - builder.and(store.longitude.loe(lngEnd)); + locationBuilder(latStart, latEnd, lngStart, lngEnd, builder); // 위도 경도에 해당하는 가게를 찾음 -> 해당 댓글을 다 가져옴 -> 내림차순 정렬 -> limit return queryFactory.selectFrom(review1) .innerJoin(review1.storeId, store) - .where(review1.storeId - .in(queryFactory.select(store).from(store).where(builder))) + .on(review1.storeId.id.eq(store.id)) + .where(builder) .limit(limit) .fetch(); } + + } \ No newline at end of file diff --git a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java index 429f124..18ef361 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java @@ -24,42 +24,37 @@ public class StoreController { private final StoreService storeService; private final StoreQueryRepository storeQueryRepository; - @GetMapping - public List getStoreList() { - return storeService.getStoreList(); - } - @GetMapping("/near") - public List giveStoreInRange(@RequestParam BigDecimal latStart, - @RequestParam BigDecimal latEnd, - @RequestParam BigDecimal lngStart, - @RequestParam BigDecimal lngEnd, - @RequestParam(required = false) String category, - @RequestParam(required = false) List facility, - @PageableDefault Pageable pageable) { + public List getStoreInRange(@RequestParam(required = false) BigDecimal latStart, + @RequestParam(required = false) BigDecimal latEnd, + @RequestParam(required = false) BigDecimal lngStart, + @RequestParam(required = false) BigDecimal lngEnd, + @RequestParam(required = false) String category, + @RequestParam(required = false) List facility, + @PageableDefault Pageable pageable) { List betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable); return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장 } - @GetMapping("/near/high-point") - public List giveStoreInRangeHighPoint(@RequestParam BigDecimal latStart, - @RequestParam BigDecimal latEnd, - @RequestParam BigDecimal lngStart, - @RequestParam BigDecimal lngEnd, - @RequestParam(required = false) String category, - @RequestParam(required = false) List facility, - @PageableDefault Pageable pageable) { + @GetMapping("/point") + public List getStoreInRangeHighPoint(@RequestParam(required = false) BigDecimal latStart, + @RequestParam(required = false) BigDecimal latEnd, + @RequestParam(required = false) BigDecimal lngStart, + @RequestParam(required = false) BigDecimal lngEnd, + @RequestParam(required = false) String category, + @RequestParam(required = false) List facility, + @PageableDefault Pageable pageable) { List betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable); return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장 } - @GetMapping("/near/high-bookmark") - public List giveStoreInRangeHighBookmark(@RequestParam BigDecimal latStart, - @RequestParam BigDecimal latEnd, - @RequestParam BigDecimal lngStart, - @RequestParam BigDecimal lngEnd, - @RequestParam(required = false) String category, - @RequestParam(required = false) List facility, - @RequestParam int limit) { + @GetMapping("/bookmark") + public List getStoreInRangeHighBookmark(@RequestParam(required = false) BigDecimal latStart, + @RequestParam(required = false) BigDecimal latEnd, + @RequestParam(required = false) BigDecimal lngStart, + @RequestParam(required = false) BigDecimal lngEnd, + @RequestParam(required = false) String category, + @RequestParam(required = false) List facility, + @RequestParam int limit) { List betweenLngLat = storeQueryRepository.findStoreOrderByBookmark(latStart, latEnd, lngStart, lngEnd, category, facility, limit); return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장 } diff --git a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java index eec65b5..e7cb37f 100644 --- a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java @@ -1,5 +1,7 @@ package com.mpnp.baechelin.store.repository; +import com.mpnp.baechelin.config.QuerydslConfiguration; +import com.mpnp.baechelin.review.repository.ReviewQueryRepository; import com.mpnp.baechelin.store.domain.QStore; import com.mpnp.baechelin.store.domain.Store; import com.mpnp.baechelin.tag.domain.QTag; @@ -107,10 +109,7 @@ private StringPath givePath(String dbFacility) { } private void locAndConditions(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List facility) { - builder.and(store.latitude.goe(latStart)); - builder.and(store.latitude.loe(latEnd)); - builder.and(store.longitude.goe(lngStart)); - builder.and(store.longitude.loe(lngEnd)); + QuerydslConfiguration.locationBuilder(latStart, latEnd, lngStart, lngEnd, builder); builder.and(category == null ? null : store.category.eq(category)); if (facility != null && facility.size() > 0) { for (String fac : facility) {