Skip to content

Commit 3480356

Browse files
이주승이주승
authored andcommitted
refactor: test deploy
1 parent 28970c5 commit 3480356

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI/CD with Git Actions & Docker Hub test
33
on:
44
push:
55
branches:
6-
- feat/#19
6+
- refactor/#21
77

88
jobs:
99
build:

src/main/java/com/drinkhere/drinklystore/application/service/Impl/store/GetStoresByLocationUseCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public List<GetStoresByLocationResponse> getStoresByLocation(double latitude, do
2424

2525
Map<Boolean, List<GetStoresByLocationResponse>> partitioned =
2626
storesByLocation.stream()
27-
.map(store -> GetStoresByLocationResponse.toDto(store, presignedUrlService))
27+
.map(store -> GetStoresByLocationResponse.toDto(store, presignedUrlService, latitude, longitude))
2828
.collect(Collectors.partitioningBy(GetStoresByLocationResponse::isAvailable));
2929

3030
List<GetStoresByLocationResponse> result = new ArrayList<>();

src/main/java/com/drinkhere/drinklystore/domain/dto/response/GetStoresByLocationResponse.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.drinkhere.drinklystore.domain.entity.Store;
66
import com.drinkhere.drinklystore.domain.entity.StoreImage;
77
import com.drinkhere.drinklystore.domain.enums.StoreImageType;
8+
import com.drinkhere.drinklystore.util.DistanceUtil;
89
import com.drinkhere.drinklystore.util.JsonUtil;
910

1011
import java.time.DayOfWeek;
@@ -26,9 +27,11 @@ public record GetStoresByLocationResponse(
2627
String openingInfo,
2728
String storeTel,
2829
String storeAddress,
29-
List<String> availableDrinks
30+
List<String> availableDrinks,
31+
double distance
3032
) {
31-
public static GetStoresByLocationResponse toDto(Store store, PresignedUrlService presignedUrlService) {
33+
public static GetStoresByLocationResponse toDto(Store store, PresignedUrlService presignedUrlService, double lat, double lon) {
34+
3235
String presignedUrl = presignedUrlService.getPresignedUrlForGet(store.getStoreMainImageUrl());
3336

3437
List<String> availableDrinks = store.getStoreImages().stream()
@@ -129,7 +132,8 @@ public static GetStoresByLocationResponse toDto(Store store, PresignedUrlService
129132
openingInfo,
130133
store.getStoreTel(),
131134
store.getStoreAddress(),
132-
availableDrinks
135+
availableDrinks,
136+
DistanceUtil.calculateDistance(lat, lon, Double.parseDouble(store.getLatitude()), Double.parseDouble(store.getLongitude()))
133137
);
134138
}
135139

src/main/java/com/drinkhere/drinklystore/domain/repository/StoreRepository.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ List<Store> findStoresByLocation(@Param("latitude") double latitude,
5353
@Param("searchKeyword") String searchKeyword);
5454

5555

56-
5756
@Query("SELECT s FROM Store s LEFT JOIN FETCH s.storeImages WHERE s.id = :storeId")
5857
Optional<Store> findByIdWithImages(@Param("storeId") Long storeId);
5958

src/main/java/com/drinkhere/drinklystore/domain/service/store/StoreQueryService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import com.drinkhere.drinklystore.domain.entity.Store;
55
import com.drinkhere.drinklystore.domain.repository.StoreRepository;
66
import lombok.RequiredArgsConstructor;
7-
import org.springframework.data.jpa.repository.Query;
8-
import org.springframework.data.repository.query.Param;
97
import org.springframework.transaction.annotation.Transactional;
108

119
import java.util.List;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.drinkhere.drinklystore.util;
2+
3+
public class DistanceUtil {
4+
private static final int EARTH_RADIUS_KM = 6371;
5+
6+
public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
7+
double latDistance = Math.toRadians(lat2 - lat1);
8+
double lonDistance = Math.toRadians(lon2 - lon1);
9+
10+
double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2)
11+
+ Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2))
12+
* Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
13+
14+
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
15+
16+
return EARTH_RADIUS_KM * c;
17+
}
18+
}

0 commit comments

Comments
 (0)