Skip to content

Commit

Permalink
feat: #37 add function to set valid departure and destination stops
Browse files Browse the repository at this point in the history
- ์ž…๋ ฅ๋ฐ›์€ ์ถœ๋ฐœ ์ •๋ฅ˜์žฅ๊ณผ ํ•˜์ฐจ ์ •๋ฅ˜์žฅ์„ ๊ธฐ๋ฐ˜์œผ๋กœ, ์œ ํšจํ•œ ๋ฒ„์Šค ๊ฒฝ๋กœ๋ฅผ ์„ ํƒํ•˜๋Š” ๋กœ์ง์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • Loading branch information
dbqls200 committed Oct 29, 2024
1 parent e9feb71 commit 147b01f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
8 changes: 4 additions & 4 deletions TMT/TMT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 7P5S729LQZ;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = TMTWidget/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = TMTWidget;
Expand Down Expand Up @@ -372,7 +372,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 7P5S729LQZ;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = TMTWidget/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = TMTWidget;
Expand Down Expand Up @@ -521,7 +521,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"TMT/Preview Content\"";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 7P5S729LQZ;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "We want your location haha";
Expand Down Expand Up @@ -554,7 +554,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"TMT/Preview Content\"";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 7P5S729LQZ;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "We want your location haha";
Expand Down
43 changes: 35 additions & 8 deletions TMT/TMT/BusSearch/BusSearchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,40 @@ final class BusStopSearchViewModel: ObservableObject {
}))
}

/// ์‚ฌ์šฉ์ž ์ž…๋ ฅ์— ๋”ฐ๋ผ ์ถœ๋ฐœ ์ •๋ฅ˜์žฅ๊ณผ ํ•˜์ฐจ ์ •๋ฅ˜์žฅ ์„ค์ •
func setJourneyStops(startStop: BusStopInfo, endStop: BusStopInfo) {
self.startStop = startStop
self.endStop = endStop
func setJourneyStops(startStopString: String, endStopString: String) {
let startCandidates = searchBusStops(for: startStopString)
let endCandidates = searchBusStops(for: endStopString)

if let validStops = findValidJourneyStops(from: startCandidates, to: endCandidates) {
self.startStop = validStops.startStop
self.endStop = validStops.endStop
}
}

private func searchBusStops(for busStopName: String) -> [BusStopInfo] {
return busStops.filter{ $0.stopNameKorean == busStopName }
}

private func findValidJourneyStops(from startCandidates: [BusStopInfo], to endCandidates: [BusStopInfo]) -> (startStop: BusStopInfo, endStop: BusStopInfo)? {
let startOrders = startCandidates.compactMap { $0.stopOrder }
let endOrders = endCandidates.compactMap { $0.stopOrder }

guard let startMin = startOrders.min(), let endMin = endOrders.min(),
let startMax = startOrders.max(), let endMax = endOrders.max() else { return nil }

if startMin < endMin {
if let startInfo = startCandidates.first(where: { $0.stopOrder == startMin }),
let endInfo = endCandidates.first(where: { $0.stopOrder == endMin }) {
return (startInfo, endInfo)
}
} else {
if let startInfo = startCandidates.first(where: { $0.stopOrder == startMax }),
let endInfo = endCandidates.first(where: { $0.stopOrder == endMax }) {
return (startInfo, endInfo)
}
}

return nil
}

/// ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋‚จ์€ ์ •๋ฅ˜์žฅ ์ˆ˜ ์—…๋ฐ์ดํŠธ
Expand All @@ -91,10 +121,7 @@ final class BusStopSearchViewModel: ObservableObject {
return
}

guard let startIndex = startStop.stopOrder,
let endIndex = endStop.stopOrder,
startIndex <= endIndex else {
print("์ถœ๋ฐœ ์ •๋ฅ˜์žฅ๊ณผ ํ•˜์ฐจ ์ •๋ฅ˜์žฅ ์ˆœ์„œ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
guard let startIndex = startStop.stopOrder, let endIndex = endStop.stopOrder else {
return
}

Expand Down

0 comments on commit 147b01f

Please sign in to comment.