Skip to content

Commit

Permalink
Merge pull request #84 from Korea-Certified-Store/feature/max-refresh…
Browse files Browse the repository at this point in the history
…-location(#74)

재검색 최대 좌표 설정
  • Loading branch information
SungMinCho-Kor authored Jan 21, 2024
2 parents 73ffd12 + cf55182 commit 89e0383
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 108 deletions.
8 changes: 4 additions & 4 deletions KCS/KCS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
59C306B22B50001F00862625 /* StoreRepositoryImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C306B12B50001F00862625 /* StoreRepositoryImpl.swift */; };
59C306B42B50015500862625 /* APIResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C306B32B50015500862625 /* APIResponse.swift */; };
59C306B62B50027300862625 /* Store.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C306B52B50027300862625 /* Store.swift */; };
59C306BB2B5003F500862625 /* NetworkURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C306BA2B5003F500862625 /* NetworkURL.swift */; };
59C306BD2B500D3D00862625 /* MockStoreResponse.json in Resources */ = {isa = PBXBuildFile; fileRef = 59C306BC2B500D3D00862625 /* MockStoreResponse.json */; };
59C306BF2B50109100862625 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C306BE2B50109100862625 /* Location.swift */; };
59C306C32B50114100862625 /* Day.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C306C22B50114100862625 /* Day.swift */; };
Expand All @@ -50,6 +49,7 @@
59F478B52B59BE0B002FEF9E /* FetchImageUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59F478B42B59BE0B002FEF9E /* FetchImageUseCase.swift */; };
59F478BB2B5ADC64002FEF9E /* GetStoreInformationUseCaseImplTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59F478BA2B5ADC64002FEF9E /* GetStoreInformationUseCaseImplTests.swift */; };
59F478BD2B5AE180002FEF9E /* FetchStoresUseCaseImplTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59F478BC2B5AE180002FEF9E /* FetchStoresUseCaseImplTests.swift */; };
59F478BF2B5BEA08002FEF9E /* RequestLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59F478BE2B5BEA08002FEF9E /* RequestLocation.swift */; };
8FE699E5DAEEDFE5A53D5E82 /* Pods_KCS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E11E3144529848C9A0FC6F77 /* Pods_KCS.framework */; };
A802D1F62B5277630091FDE7 /* CertificationLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A802D1F52B5277620091FDE7 /* CertificationLabel.swift */; };
A81EFBB32B5BC57800D0C0D7 /* OpenClosedContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81EFBB22B5BC57800D0C0D7 /* OpenClosedContent.swift */; };
Expand Down Expand Up @@ -114,7 +114,6 @@
59C306B12B50001F00862625 /* StoreRepositoryImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreRepositoryImpl.swift; sourceTree = "<group>"; };
59C306B32B50015500862625 /* APIResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIResponse.swift; sourceTree = "<group>"; };
59C306B52B50027300862625 /* Store.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Store.swift; sourceTree = "<group>"; };
59C306BA2B5003F500862625 /* NetworkURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkURL.swift; sourceTree = "<group>"; };
59C306BC2B500D3D00862625 /* MockStoreResponse.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = MockStoreResponse.json; sourceTree = "<group>"; };
59C306BE2B50109100862625 /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = "<group>"; };
59C306C22B50114100862625 /* Day.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Day.swift; sourceTree = "<group>"; };
Expand All @@ -130,6 +129,7 @@
59F478B42B59BE0B002FEF9E /* FetchImageUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchImageUseCase.swift; sourceTree = "<group>"; };
59F478BA2B5ADC64002FEF9E /* GetStoreInformationUseCaseImplTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetStoreInformationUseCaseImplTests.swift; sourceTree = "<group>"; };
59F478BC2B5AE180002FEF9E /* FetchStoresUseCaseImplTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchStoresUseCaseImplTests.swift; sourceTree = "<group>"; };
59F478BE2B5BEA08002FEF9E /* RequestLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestLocation.swift; sourceTree = "<group>"; };
5FF0FF2386EEB69182D6EA4C /* Pods-KCSUnitTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KCSUnitTest.debug.xcconfig"; path = "Target Support Files/Pods-KCSUnitTest/Pods-KCSUnitTest.debug.xcconfig"; sourceTree = "<group>"; };
9EA5C8EA72EA9E937C11400A /* Pods-KCS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KCS.debug.xcconfig"; path = "Target Support Files/Pods-KCS/Pods-KCS.debug.xcconfig"; sourceTree = "<group>"; };
A802D1F52B5277620091FDE7 /* CertificationLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertificationLabel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -351,6 +351,7 @@
59C306A52B4D966C00862625 /* CertificationType.swift */,
A8ACB7DC2B58E3DE00540BD1 /* OpenClosedType.swift */,
5977BE732B57FA7A00725C90 /* FilteredStores.swift */,
59F478BE2B5BEA08002FEF9E /* RequestLocation.swift */,
A81EFBB22B5BC57800D0C0D7 /* OpenClosedContent.swift */,
);
path = Entity;
Expand All @@ -372,7 +373,6 @@
59C306D42B50629400862625 /* Error */,
59C306B72B50033200862625 /* Response */,
59C306AB2B4FFABA00862625 /* DTO */,
59C306BA2B5003F500862625 /* NetworkURL.swift */,
59C306CA2B50357900862625 /* Router.swift */,
59C306CC2B5035B100862625 /* StoreAPI.swift */,
);
Expand Down Expand Up @@ -731,7 +731,7 @@
59C306B42B50015500862625 /* APIResponse.swift in Sources */,
5977BE582B5524D500725C90 /* RefreshButton.swift in Sources */,
5977BE942B59738800725C90 /* FetchStoresUseCase.swift in Sources */,
59C306BB2B5003F500862625 /* NetworkURL.swift in Sources */,
59F478BF2B5BEA08002FEF9E /* RequestLocation.swift in Sources */,
59C306B22B50001F00862625 /* StoreRepositoryImpl.swift in Sources */,
5977BE9A2B59AC3300725C90 /* ImageRepository.swift in Sources */,
591A887D2B384E600059E40F /* AppDelegate.swift in Sources */,
Expand Down
14 changes: 0 additions & 14 deletions KCS/KCS/Data/Network/NetworkURL.swift

This file was deleted.

29 changes: 28 additions & 1 deletion KCS/KCS/Data/Network/StoreAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ extension StoreAPI: Router, URLRequestConvertible {
public var baseURL: String {
switch self {
case .getStores:
return NetworkURL.storeURL
do {
return try getURL(type: .develop)
} catch {
print(error.localizedDescription)
return ""
}
case .getImage(let url):
return url
}
Expand Down Expand Up @@ -93,3 +98,25 @@ extension StoreAPI: Router, URLRequestConvertible {
}

}

private extension StoreAPI {

enum URLType {

case develop
case product

}

func getURL(type: URLType) throws -> String {
switch type {
case .develop:
guard let url = Bundle.main.object(forInfoDictionaryKey: "DEV_SERVER_URL") as? String else { throw NetworkError.wrongURL }
return url
case .product:
guard let url = Bundle.main.object(forInfoDictionaryKey: "PROD_SERVER_URL") as? String else { throw NetworkError.wrongURL }
return url
}
}

}
21 changes: 9 additions & 12 deletions KCS/KCS/Data/Repository/StoreRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ final class StoreRepositoryImpl: StoreRepository {
}

func fetchRefreshStores(
northWestLocation: Location,
southWestLocation: Location,
southEastLocation: Location,
northEastLocation: Location
requestLocation: RequestLocation
) -> Observable<[Store]> {
return Observable<[Store]>.create { observer -> Disposable in
AF.request(StoreAPI.getStores(location: RequestLocationDTO(
nwLong: northWestLocation.longitude,
nwLat: northWestLocation.latitude,
swLong: southWestLocation.longitude,
swLat: southWestLocation.latitude,
seLong: southEastLocation.longitude,
seLat: southEastLocation.latitude,
neLong: northEastLocation.longitude,
neLat: northEastLocation.latitude
nwLong: requestLocation.northWest.longitude,
nwLat: requestLocation.northWest.latitude,
swLong: requestLocation.southWest.longitude,
swLat: requestLocation.southWest.latitude,
seLong: requestLocation.southEast.longitude,
seLat: requestLocation.southEast.latitude,
neLong: requestLocation.northEast.longitude,
neLat: requestLocation.northEast.latitude
)))
.responseDecodable(of: StoreResponse.self) { [weak self] response in
switch response.result {
Expand Down
17 changes: 17 additions & 0 deletions KCS/KCS/Domain/Entity/RequestLocation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// RequestLocation.swift
// KCS
//
// Created by 조성민 on 1/20/24.
//

import Foundation

struct RequestLocation {

let northWest: Location
let southWest: Location
let southEast: Location
let northEast: Location

}
5 changes: 1 addition & 4 deletions KCS/KCS/Domain/Interface/Repository/StoreRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import RxSwift
protocol StoreRepository {

func fetchRefreshStores(
northWestLocation: Location,
southWestLocation: Location,
southEastLocation: Location,
northEastLocation: Location
requestLocation: RequestLocation
) -> Observable<[Store]>

func fetchStores() -> [Store]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ protocol FetchRefreshStoresUseCase {
init(repository: StoreRepository)

func execute(
northWestLocation: Location,
southWestLocation: Location,
southEastLocation: Location,
northEastLocation: Location
requestLocation: RequestLocation
) -> Observable<[Store]>

}
83 changes: 74 additions & 9 deletions KCS/KCS/Domain/UseCase/FetchRefreshStoresUseCaseImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,81 @@ struct FetchRefreshStoresUseCaseImpl: FetchRefreshStoresUseCase {
let repository: StoreRepository

func execute(
northWestLocation: Location,
southWestLocation: Location,
southEastLocation: Location,
northEastLocation: Location
requestLocation: RequestLocation
) -> Observable<[Store]> {
return repository.fetchRefreshStores(
northWestLocation: northWestLocation,
southWestLocation: southWestLocation,
southEastLocation: southEastLocation,
northEastLocation: northEastLocation
let newLocation = parallelTranslate(requestLocation: requestLocation)

return repository.fetchRefreshStores(requestLocation: newLocation)
}

func parallelTranslate (requestLocation: RequestLocation) -> RequestLocation {
let distance1 = sqrt(
pow(requestLocation.northWest.longitude - requestLocation.southWest.longitude, 2)
+ pow(requestLocation.northWest.latitude - requestLocation.southWest.latitude, 2)
)
let distance2 = sqrt(
pow(requestLocation.northWest.longitude - requestLocation.northEast.longitude, 2) +
pow(requestLocation.northWest.latitude - requestLocation.northEast.latitude, 2)
)

let center = Location(
longitude: (requestLocation.northWest.longitude + requestLocation.southEast.longitude) / 2.0,
latitude: (requestLocation.northWest.latitude + requestLocation.southEast.latitude) / 2.0
)

var newLocation: RequestLocation
if distance1 > 0.07 {
newLocation = translateHeightLocations(
loc1: requestLocation.northWest,
loc2: requestLocation.northEast,
center: center
)
if distance2 > 0.07 {
return translateHeightLocations(
loc1: newLocation.northEast,
loc2: newLocation.southEast,
center: center
)
}
return newLocation
}

return requestLocation
}

func translateHeightLocations(loc1: Location, loc2: Location, center: Location) -> RequestLocation {
if loc1.latitude == loc2.latitude {
return RequestLocation(
northWest: Location(longitude: loc1.longitude, latitude: center.latitude + 0.035),
southWest: Location(longitude: loc1.longitude, latitude: center.latitude - 0.035),
southEast: Location(longitude: loc2.longitude, latitude: center.latitude - 0.035),
northEast: Location(longitude: loc2.longitude, latitude: center.latitude + 0.035)
)
} else if loc1.longitude == loc2.longitude {
return RequestLocation(
northWest: Location(longitude: center.longitude + 0.035, latitude: loc1.latitude),
southWest: Location(longitude: center.longitude - 0.035, latitude: loc1.latitude),
southEast: Location(longitude: center.longitude - 0.035, latitude: loc2.latitude),
northEast: Location(longitude: center.longitude + 0.035, latitude: loc2.latitude)
)

}

let slope = (loc2.latitude - loc1.latitude) / (loc2.longitude - loc1.longitude)
let constant1 = 0.035 * sqrt(pow(slope, 2) + 1) - slope * center.longitude + center.latitude
let constant2 = (-0.035) * sqrt(pow(slope, 2) + 1) - slope * center.longitude + center.latitude

return RequestLocation(
northWest: getNewLocation(location: loc1, slope: slope, constant: constant1),
southWest: getNewLocation(location: loc1, slope: slope, constant: constant2),
southEast: getNewLocation(location: loc2, slope: slope, constant: constant2),
northEast: getNewLocation(location: loc2, slope: slope, constant: constant1)
)
}
func getNewLocation(location: Location, slope: Double, constant: Double) -> Location {
return Location(
longitude: (location.latitude + (location.longitude / slope) - constant) / (slope + 1 / slope),
latitude: (slope * location.latitude + location.longitude + constant / slope) / (slope + 1 / slope)
)
}

Expand Down
72 changes: 38 additions & 34 deletions KCS/KCS/Presentation/Home/View/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,28 @@ final class HomeViewController: UIViewController {
.bind { [weak self] _ in
guard let self = self else { return }
let northWestPoint = mapView.mapView.projection.latlng(from: CGPoint(x: 0, y: 0))
let southWestPoint = mapView.mapView.projection.latlng(from: CGPoint(x: view.frame.width, y: 0))
let southWestPoint = mapView.mapView.projection.latlng(from: CGPoint(x: 0, y: view.frame.height))
let southEastPoint = mapView.mapView.projection.latlng(from: CGPoint(x: view.frame.width, y: view.frame.height))
let northEastPoint = mapView.mapView.projection.latlng(from: CGPoint(x: 0, y: view.frame.height))
let northEastPoint = mapView.mapView.projection.latlng(from: CGPoint(x: view.frame.width, y: 0))
viewModel.action(
input: .refresh(
northWestLocation: Location(
longitude: northWestPoint.lng,
latitude: northWestPoint.lat
),
southWestLocation: Location(
longitude: southWestPoint.lng,
latitude: southWestPoint.lat
),
southEastLocation: Location(
longitude: southEastPoint.lng,
latitude: southEastPoint.lat
),
northEastLocation: Location(
longitude: northEastPoint.lng,
latitude: northEastPoint.lat
requestLocation: RequestLocation(
northWest: Location(
longitude: northWestPoint.lng,
latitude: northWestPoint.lat
),
southWest: Location(
longitude: southWestPoint.lng,
latitude: southWestPoint.lat
),
southEast: Location(
longitude: southEastPoint.lng,
latitude: southEastPoint.lat
),
northEast: Location(
longitude: northEastPoint.lng,
latitude: northEastPoint.lat
)
),
filters: getActivatedTypes()
)
Expand Down Expand Up @@ -401,26 +403,28 @@ extension HomeViewController: NMFMapViewCameraDelegate {
locationButton.setImage(UIImage.locationButtonNormal, for: .normal)

let northWestPoint = mapView.projection.latlng(from: CGPoint(x: 0, y: 0))
let southWestPoint = mapView.projection.latlng(from: CGPoint(x: view.frame.width, y: 0))
let southWestPoint = mapView.projection.latlng(from: CGPoint(x: 0, y: view.frame.height))
let southEastPoint = mapView.projection.latlng(from: CGPoint(x: view.frame.width, y: view.frame.height))
let northEastPoint = mapView.projection.latlng(from: CGPoint(x: 0, y: view.frame.height))
let northEastPoint = mapView.projection.latlng(from: CGPoint(x: view.frame.width, y: 0))
viewModel.action(
input: .refresh(
northWestLocation: Location(
longitude: northWestPoint.lng,
latitude: northWestPoint.lat
),
southWestLocation: Location(
longitude: southWestPoint.lng,
latitude: southWestPoint.lat
),
southEastLocation: Location(
longitude: southEastPoint.lng,
latitude: southEastPoint.lat
),
northEastLocation: Location(
longitude: northEastPoint.lng,
latitude: northEastPoint.lat
requestLocation: RequestLocation(
northWest: Location(
longitude: northWestPoint.lng,
latitude: northWestPoint.lat
),
southWest: Location(
longitude: southWestPoint.lng,
latitude: southWestPoint.lat
),
southEast: Location(
longitude: southEastPoint.lng,
latitude: southEastPoint.lat
),
northEast: Location(
longitude: northEastPoint.lng,
latitude: northEastPoint.lat
)
),
filters: getActivatedTypes()
)
Expand Down
Loading

0 comments on commit 89e0383

Please sign in to comment.