Skip to content

Commit b272ece

Browse files
authored
Merge pull request #37 from krystxf/feat/ios-app
feat: ios app
2 parents 004bb02 + d69afb0 commit b272ece

29 files changed

+1024
-192
lines changed

apps/backend/src/config/cache-module.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ export const cacheModuleConfig: CacheModuleAsyncOptions = {
1010
port: parseInt(process.env.REDIS_PORT || "6379"),
1111
},
1212
}),
13-
max: 1_000,
1413
}),
1514
};

apps/backend/src/modules/departure/departure.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { toArray } from "src/utils/array.utils";
2525
@ApiTags("departure")
2626
@Controller("departure")
2727
@UseInterceptors(CacheInterceptor, LogInterceptor)
28-
@CacheTTL(2_000)
28+
@CacheTTL(4 * 1000)
2929
export class DepartureController {
3030
constructor(private readonly departureService: DepartureService) {}
3131

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// metro-now
2+
// https://github.com/krystxf/metro-now
3+
4+
import SwiftUI
5+
6+
struct RouteNameIconView: View {
7+
let label: String
8+
let background: Color
9+
10+
var body: some View {
11+
Text(label.uppercased())
12+
.font(.system(size: 12, weight: .bold))
13+
.foregroundStyle(.white)
14+
.fixedSize(horizontal: true, vertical: true)
15+
.frame(width: 26, height: 26)
16+
.background(Rectangle().fill(background))
17+
.clipShape(.rect(cornerRadius: 6))
18+
}
19+
}
20+
21+
#Preview {
22+
RouteNameIconView(
23+
label: "a",
24+
background: .green
25+
)
26+
27+
RouteNameIconView(
28+
label: "b",
29+
background: .yellow
30+
)
31+
32+
RouteNameIconView(
33+
label: "c",
34+
background: .red
35+
)
36+
37+
RouteNameIconView(
38+
label: "28",
39+
background: .purple
40+
)
41+
42+
RouteNameIconView(
43+
label: "99",
44+
background: .black
45+
)
46+
47+
RouteNameIconView(
48+
label: "149",
49+
background: .blue
50+
)
51+
52+
RouteNameIconView(
53+
label: "912",
54+
background: .black
55+
)
56+
}

apps/mobile/metro-now/common/const/api-const.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
// https://github.com/krystxf/metro-now
33

44
let ENDPOINT: String = "https://api.metronow.dev"
5+
// let ENDPOINT: String = "http://localhost:3001"

apps/mobile/metro-now/common/managers/network-manager.swift

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import Foundation
55

66
final class NetworkManager {
7-
static let shared = NetworkManager()
7+
static let shared = NetworkManager(
8+
)
89

910
private init() {}
1011

@@ -50,6 +51,48 @@ final class NetworkManager {
5051
task.resume()
5152
}
5253

54+
func getAllStops(
55+
completed: @escaping (Result<[ApiStop], FetchErrorNew>) -> Void
56+
) {
57+
guard let url = URL(string: "\(ENDPOINT)/stop/all") else {
58+
completed(.failure(.invalidUrl))
59+
return
60+
}
61+
62+
let task = URLSession.shared.dataTask(
63+
with: URLRequest(url: url)
64+
) {
65+
data, response, error in
66+
67+
if let _ = error {
68+
completed(.failure(.general))
69+
return
70+
}
71+
72+
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
73+
completed(.failure(.invalidResponse))
74+
return
75+
}
76+
77+
guard let data else {
78+
completed(.failure(.invalidData))
79+
return
80+
}
81+
82+
do {
83+
let decoder = JSONDecoder()
84+
let decodedResponse = try decoder.decode([ApiStop].self, from: data)
85+
completed(.success(decodedResponse))
86+
return
87+
} catch {
88+
completed(.failure(.invalidData))
89+
return
90+
}
91+
}
92+
93+
task.resume()
94+
}
95+
5396
func getDepartures(
5497
stopIds: [String], platformIds: [String], completed: @escaping (Result<[ApiDeparture], FetchErrorNew>) -> Void
5598
) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// metro-now
2+
// https://github.com/krystxf/metro-now
3+
4+
import SwiftUI
5+
6+
private let FALLBACK_COLOR: Color = .black
7+
8+
func getColorByRouteName(_ metroLine: MetroLine?) -> Color {
9+
switch metroLine {
10+
case .A:
11+
.green
12+
case .B:
13+
.yellow
14+
case .C:
15+
.red
16+
default: FALLBACK_COLOR
17+
}
18+
}
19+
20+
func getColorByRouteName(_ routeNumber: Int?) -> Color {
21+
guard let routeNumber else {
22+
return FALLBACK_COLOR
23+
}
24+
25+
// tram
26+
if routeNumber < 100 {
27+
if routeNumber >= 90 {
28+
return .black
29+
}
30+
31+
return .purple
32+
}
33+
34+
// bus
35+
if routeNumber >= 900 {
36+
return .black
37+
}
38+
39+
return .blue
40+
}
41+
42+
func getColorByRouteName(_ routeName: String?) -> Color {
43+
guard let routeName else {
44+
return FALLBACK_COLOR
45+
}
46+
47+
if let routeNumber = Int(routeName) {
48+
return getColorByRouteName(routeNumber)
49+
} else if let metroLine = MetroLine(rawValue: routeName) {
50+
return getColorByRouteName(metroLine)
51+
}
52+
53+
// ferry
54+
if routeName.hasPrefix("P") {
55+
return Color.blue
56+
}
57+
58+
// funicular
59+
if routeName.hasPrefix("LD") {
60+
return Color.blue
61+
}
62+
63+
return FALLBACK_COLOR
64+
}

apps/mobile/metro-now/common/utils/metro-line.utils.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

apps/mobile/metro-now/metro-now Watch App/ContentView.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ struct ContentView: View {
1313

1414
var body: some View {
1515
VStack {
16-
if
17-
let location = locationManager.location,
18-
let stops,
19-
let closestStop = findClosestStop(to: location, stops: stops)
16+
if let location = locationManager.location,
17+
let stops,
18+
let closestStop = findClosestStop(to: location, stops: stops)
2019
{
21-
MainPage(
20+
StopDeparturesView(
2221
title: closestStop.name,
2322
platforms: closestStop.platforms.map {
2423
platform in
@@ -31,7 +30,6 @@ struct ContentView: View {
3130
)
3231
}
3332
)
34-
3533
} else {
3634
ProgressView()
3735
}

apps/mobile/metro-now/metro-now Watch App/pages/departure-placeholder.swift

Lines changed: 0 additions & 33 deletions
This file was deleted.

apps/mobile/metro-now/metro-now Watch App/pages/main-page.swift

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)