Skip to content

Commit ec921ef

Browse files
authored
Merge pull request #82 from cake-way/dev
지도가게검색 위도,경도,케이크리스트 추가
2 parents d151bb0 + d32325e commit ec921ef

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

src/main/java/com/example/cake_way/home/search/dto/CakeShopSearchDTO.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ public class CakeShopSearchDTO {
1515
private String contact; // 연락처
1616
private String thumbnailImage; // 썸네일 이미지
1717
private double distance; // 거리
18-
private List<CakeDTO> cakes; // 케이크 리스트
18+
private double latitude; // 위도
19+
private double longitude; // 경도
20+
private List<CakeDTO> cakes; // 해당 가게의 케이크 리스트
1921
}

src/main/java/com/example/cake_way/home/search/service/MapSearchService.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.example.cake_way.home.search.service;
22

3+
import com.example.cake_way.cake.dto.CakeDTO;
4+
import com.example.cake_way.cake.repository.CakeRepository;
35
import com.example.cake_way.cakeshop.entity.CakeShop;
46
import com.example.cake_way.cakeshop.repository.CakeShopRepository;
57
import com.example.cake_way.common.util.DistanceCalculator;
@@ -9,13 +11,16 @@
911
import java.util.Comparator;
1012
import java.util.List;
1113
import java.util.stream.Collectors;
14+
1215
@Service
1316
public class MapSearchService {
1417

1518
private final CakeShopRepository cakeShopRepository;
19+
private final CakeRepository cakeRepository;
1620

17-
public MapSearchService(CakeShopRepository cakeShopRepository) {
21+
public MapSearchService(CakeShopRepository cakeShopRepository, CakeRepository cakeRepository) {
1822
this.cakeShopRepository = cakeShopRepository;
23+
this.cakeRepository = cakeRepository;
1924
}
2025

2126
public List<CakeShopSearchDTO> searchCakeShops(String keyword, double latitude, double longitude, boolean isSameDay) {
@@ -33,18 +38,33 @@ public List<CakeShopSearchDTO> searchCakeShops(String keyword, double latitude,
3338
: cakeShopRepository.findByKeyword(keyword);
3439
}
3540

36-
// 거리 계산 및 정렬
41+
// 거리 계산 및 케이크 정보 추가
3742
return shops.stream()
38-
.map(shop -> CakeShopSearchDTO.builder()
39-
.shopId(shop.getShopId())
40-
.name(shop.getName())
41-
.address(shop.getAddress())
42-
.contact(shop.getContact())
43-
.thumbnailImage(shop.getThumbnailImage())
44-
.distance(DistanceCalculator.calculateDistance(
45-
shop.getLatitude(), shop.getLongitude(), latitude, longitude))
46-
.build())
43+
.map(shop -> {
44+
List<CakeDTO> cakes = cakeRepository.findByCakeShop(shop).stream()
45+
.map(cake -> CakeDTO.builder()
46+
.cakeId(cake.getCakeId())
47+
.name(cake.getName())
48+
.price(cake.getPrice())
49+
.imageUrl(cake.getImageUrl())
50+
.build())
51+
.collect(Collectors.toList());
52+
53+
return CakeShopSearchDTO.builder()
54+
.shopId(shop.getShopId())
55+
.name(shop.getName())
56+
.address(shop.getAddress())
57+
.contact(shop.getContact())
58+
.thumbnailImage(shop.getThumbnailImage())
59+
.distance(DistanceCalculator.calculateDistance(
60+
shop.getLatitude(), shop.getLongitude(), latitude, longitude))
61+
.latitude(shop.getLatitude()) // 위도 추가
62+
.longitude(shop.getLongitude()) // 경도 추가
63+
.cakes(cakes) // 케이크 리스트 추가
64+
.build();
65+
})
4766
.sorted(Comparator.comparingDouble(CakeShopSearchDTO::getDistance)) // 가까운 순으로 정렬
4867
.collect(Collectors.toList());
4968
}
5069
}
70+

0 commit comments

Comments
 (0)