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 14f1996..664c352 100644 --- a/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java +++ b/src/main/java/com/mpnp/baechelin/api/controller/LocationController.java @@ -1,8 +1,8 @@ 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.api.repository.MapQueryRepository; import com.mpnp.baechelin.store.repository.StoreRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java b/src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java index f117752..d457397 100644 --- a/src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java +++ b/src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java @@ -1,7 +1,12 @@ package com.mpnp.baechelin.review.repository; import com.mpnp.baechelin.review.domain.Review; +import com.mpnp.baechelin.store.domain.Store; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ReviewRepository extends JpaRepository { + + List findAllByStoreId(Store store); } 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 60b3883..43e6e2d 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java @@ -18,6 +18,7 @@ public class StoreController { @GetMapping public List getStoreList() { - return null; + List storeList = storeService.getStoreList(); + return storeList; } } diff --git a/src/main/java/com/mpnp/baechelin/store/dto/StoreResponseDto.java b/src/main/java/com/mpnp/baechelin/store/dto/StoreResponseDto.java index 224b10c..beffed5 100644 --- a/src/main/java/com/mpnp/baechelin/store/dto/StoreResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/store/dto/StoreResponseDto.java @@ -4,7 +4,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; +import java.math.BigDecimal; import java.util.List; @Getter @@ -13,8 +13,8 @@ public class StoreResponseDto { private int storeId; private String category; private String name; - private String latitude; - private String longitude; + private BigDecimal latitude; + private BigDecimal longitude; private String address; private String elevator; private String toilet; @@ -23,7 +23,6 @@ public class StoreResponseDto { private String heightDifferent; private String approach; private List storeImgList; - private LocalDateTime storeModifiedAt; private double pointAvg; // private List reviewList; @@ -32,8 +31,8 @@ public StoreResponseDto( int storeId, String category, String name, - String latitude, - String longitude, + BigDecimal latitude, + BigDecimal longitude, String address, String elevator, String toilet, @@ -42,7 +41,6 @@ public StoreResponseDto( String heightDifferent, String approach, List storeImgList, - LocalDateTime storeModifiedAt, double pointAvg) { this.storeId = storeId; @@ -58,7 +56,6 @@ public StoreResponseDto( this.heightDifferent = heightDifferent; this.approach = approach; this.storeImgList = storeImgList; - this.storeModifiedAt = storeModifiedAt; this.pointAvg = pointAvg; } } 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 e312127..be85fe5 100644 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java +++ b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java @@ -1,10 +1,14 @@ package com.mpnp.baechelin.store.service; +import com.mpnp.baechelin.review.domain.Review; +import com.mpnp.baechelin.review.repository.ReviewRepository; +import com.mpnp.baechelin.store.domain.Store; import com.mpnp.baechelin.store.dto.StoreResponseDto; import com.mpnp.baechelin.store.repository.StoreRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; @Service @@ -12,8 +16,49 @@ public class StoreService { private final StoreRepository storeRepository; + private final ReviewRepository reviewRepository; public List getStoreList() { - return null; + List storeList = storeRepository.findAll(); + + List storeResponseList = new ArrayList<>(); + + for (Store store : storeList) { + List reviewList = reviewRepository.findAllByStoreId(store); + + double totalPoint = 0; + + double pointAvg = 0; + if (reviewList.size() > 0) { + for (Review review : reviewList) { + totalPoint += review.getPoint(); + } + + pointAvg = Double.parseDouble(String.format("%.1f", totalPoint / reviewList.size())); + } else { + pointAvg = 0; + } + + 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); + } + + + return storeResponseList; } }