-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
프론트에서 사용할 수 있게끔 임시로 업장 리스트 조회 구현
- Loading branch information
Showing
5 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/java/com/mpnp/baechelin/api/controller/LocationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/mpnp/baechelin/review/repository/ReviewRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Review, Integer> { | ||
|
||
List<Review> findAllByStoreId(Store store); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 46 additions & 1 deletion
47
src/main/java/com/mpnp/baechelin/store/service/StoreService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,64 @@ | ||
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 | ||
@RequiredArgsConstructor | ||
public class StoreService { | ||
|
||
private final StoreRepository storeRepository; | ||
private final ReviewRepository reviewRepository; | ||
|
||
public List<StoreResponseDto> getStoreList() { | ||
return null; | ||
List<Store> storeList = storeRepository.findAll(); | ||
|
||
List<StoreResponseDto> storeResponseList = new ArrayList<>(); | ||
|
||
for (Store store : storeList) { | ||
List<Review> 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; | ||
} | ||
} |