Skip to content

Commit

Permalink
Adopt new api architecture (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
mltbnz committed Jun 2, 2023
1 parent 4aff6db commit 5135607
Show file tree
Hide file tree
Showing 42 changed files with 994 additions and 802 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Changelog for Critical Maps iOS

# [4.2.0] - 2023-06-01

### Added

- Adopt new Backend architecture
- Update BottomSheet view that will focus on available next ride
- Performance enhencements

# [4.0.0] - 2022-03-18

__Proposal for the release is to make it `4.0.0`__
Expand Down
26 changes: 19 additions & 7 deletions CriticalMaps.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
732734462771172C0007579E /* CriticalMapsKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = CriticalMapsKit; sourceTree = "<group>"; };
7327344B277118670007579E /* TwitterFeaturePreview.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TwitterFeaturePreview.app; sourceTree = BUILT_PRODUCTS_DIR; };
7327344D277118670007579E /* TwitterFeaturePreviewApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwitterFeaturePreviewApp.swift; sourceTree = "<group>"; };
7347AB262A27BE2A00BCA949 /* ChatFeature.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = ChatFeature.xctestplan; sourceTree = "<group>"; };
7347AB272A27C0A900BCA949 /* MapFeature.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = MapFeature.xctestplan; sourceTree = "<group>"; };
73654C6B26C85FCF004BE38B /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
7369207C28D0D92100EA0584 /* SnapshotTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = SnapshotTests.xctestplan; sourceTree = "<group>"; };
738214EF271F49AB009847C7 /* appIcon-5.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "appIcon-5.png"; sourceTree = "<group>"; };
Expand All @@ -44,7 +46,7 @@
739C4980276733E20001466A /* Berlin:Germany.gpx */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "Berlin:Germany.gpx"; path = "App/Berlin:Germany.gpx"; sourceTree = "<group>"; };
73BABF82277B0A2900D9790F /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
73BABF83277B0A2900D9790F /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
73CA9806268DCC0F004D81FA /* UnitTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = UnitTests.xctestplan; path = App/UnitTests.xctestplan; sourceTree = "<group>"; };
73CA9806268DCC0F004D81FA /* UnitTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = UnitTests.xctestplan; sourceTree = "<group>"; };
73CF5FC2263EAF5B001925A3 /* Critical Maps.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Critical Maps.app"; sourceTree = BUILT_PRODUCTS_DIR; };
73CF5FF1263EB0A6001925A3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
73CF5FF6263EB0A6001925A3 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -121,6 +123,17 @@
path = TwitterFeaturePreview;
sourceTree = "<group>";
};
7347AB282A27C0CA00BCA949 /* Testplans */ = {
isa = PBXGroup;
children = (
7347AB272A27C0A900BCA949 /* MapFeature.xctestplan */,
7347AB262A27BE2A00BCA949 /* ChatFeature.xctestplan */,
7369207C28D0D92100EA0584 /* SnapshotTests.xctestplan */,
73CA9806268DCC0F004D81FA /* UnitTests.xctestplan */,
);
path = Testplans;
sourceTree = "<group>";
};
738214EE271F49AB009847C7 /* appicons */ = {
isa = PBXGroup;
children = (
Expand All @@ -141,8 +154,7 @@
73BABF83277B0A2900D9790F /* README.md */,
732734462771172C0007579E /* CriticalMapsKit */,
739C4980276733E20001466A /* Berlin:Germany.gpx */,
7369207C28D0D92100EA0584 /* SnapshotTests.xctestplan */,
73CA9806268DCC0F004D81FA /* UnitTests.xctestplan */,
7347AB282A27C0CA00BCA949 /* Testplans */,
73CF5FF0263EB0A6001925A3 /* iOS App */,
7327344C277118670007579E /* TwitterFeaturePreview */,
73238EBB27728043003DE01F /* ChatFeaturePreview */,
Expand Down Expand Up @@ -771,7 +783,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 5YLLXUZBZ2;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "$(SRCROOT)/App/iOS App/Info.plist";
Expand All @@ -780,7 +792,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 4.0.0;
MARKETING_VERSION = 4.2.0;
PRODUCT_BUNDLE_IDENTIFIER = de.pokuslabs.criticalmassberlin;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "Critical Maps Prov Profile";
Expand All @@ -797,7 +809,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 5YLLXUZBZ2;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "$(SRCROOT)/App/iOS App/Info.plist";
Expand All @@ -806,7 +818,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 4.0.0;
MARKETING_VERSION = 4.2.0;
PRODUCT_BUNDLE_IDENTIFIER = de.pokuslabs.criticalmassberlin;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "Critical Maps Prov Profile";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"revision" : "b690a617d1366bd36f047e5da5d3185f20daac71",
"version" : "0.50.1"
"revision" : "cd22f6a1b3a6210e1e365cbfa8706dbb1736ca27",
"version" : "0.51.0"
}
},
{
Expand All @@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections",
"state" : {
"revision" : "fd34c544ad27f3ba6b19142b348005bfa85b6005",
"version" : "0.6.0"
"revision" : "f52eee28bdc6065aa2f8424067e6f04c74bda6e6",
"version" : "0.7.1"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<TestPlanReference
reference = "container:App/UnitTests.xctestplan">
reference = "container:Testplans/UnitTests.xctestplan">
</TestPlanReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -39,11 +39,11 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:App/UnitTests.xctestplan"
reference = "container:Testplans/UnitTests.xctestplan"
default = "YES">
</TestPlanReference>
<TestPlanReference
reference = "container:SnapshotTests.xctestplan">
reference = "container:Testplans/SnapshotTests.xctestplan">
</TestPlanReference>
</TestPlans>
</TestAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ChatFeature"
BuildableName = "ChatFeature"
BlueprintName = "ChatFeature"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:../Testplans/ChatFeature.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ChatFeature"
BuildableName = "ChatFeature"
BlueprintName = "ChatFeature"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1330"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -27,18 +27,12 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "MapFeatureTests"
BuildableName = "MapFeatureTests"
BlueprintName = "MapFeatureTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
<TestPlans>
<TestPlanReference
reference = "container:../MapFeature.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
83 changes: 83 additions & 0 deletions CriticalMapsKit/Sources/ApiClient/APIService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import Foundation
import SharedModels

// MARK: Interface

/// A Service to send and fetch locations and chat messages from the Criticl Maps API
public struct APIService {
public var getRiders: @Sendable () async throws -> [Rider]
public var postRiderLocation: @Sendable (SendLocationPostBody) async throws -> ApiResponse
public var getChatMessages: @Sendable () async throws -> [ChatMessage]
public var postChatMessage: @Sendable (ChatMessagePost) async throws -> ApiResponse

public init(
postRiderLocation: @Sendable @escaping (SendLocationPostBody) async throws -> ApiResponse,
getRiders: @Sendable @escaping () async throws -> [Rider],
getChatMessages: @Sendable @escaping () async throws -> [ChatMessage],
postChatMessage: @Sendable @escaping (ChatMessagePost) async throws -> ApiResponse
) {
self.postRiderLocation = postRiderLocation
self.getRiders = getRiders
self.getChatMessages = getChatMessages
self.postChatMessage = postChatMessage
}
}

// MARK: Live

public extension APIService {
static func live(apiClient: APIClient = .live()) -> Self {
Self(
postRiderLocation: { body in
let request: Request = .put(.locations, body: try? body.encoded())
let (data, _) = try await apiClient.send(request)
return try data.decoded()
},
getRiders: {
let request: Request = .get(.locations)
let (data, _) = try await apiClient.send(request)
return try data.decoded()
},
getChatMessages: {
let request: Request = .get(.chatMessages)
let (data, _) = try await apiClient.send(request)
return try data.decoded()
},
postChatMessage: { body in
let request: Request = .post(.chatMessages, body: try? body.encoded())
let (data, _) = try await apiClient.send(request)
return try data.decoded()
}
)
}
}

// MARK: Mocks and failing used for previews and tests

public extension APIService {
static let noop = Self(
postRiderLocation: { _ in
ApiResponse(status: "ok")
},
getRiders: { [] },
getChatMessages: { [] },
postChatMessage: { _ in
ApiResponse(status: "ok")
}
)

static let failing = Self(
postRiderLocation: { _ in throw NSError(domain: "", code: 1) },
getRiders: { throw NSError(domain: "", code: 1) },
getChatMessages: { throw NSError(domain: "", code: 1) },
postChatMessage: { _ in throw NSError(domain: "", code: 1) }
)
}

public struct ApiResponse: Codable, Equatable {
public init(status: String?) {
self.status = status
}

public var status: String?
}
25 changes: 17 additions & 8 deletions CriticalMapsKit/Sources/ApiClient/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ import Foundation
/// A structure to define an endpoint on the Critical Maps API
public struct Endpoint {
public let baseUrl: String
public let path: String?
public let pathComponents: [String]

public init(baseUrl: String, path: String? = nil) {
public init(baseUrl: String, pathComponents: [String] = []) {
self.baseUrl = baseUrl
self.path = path
self.pathComponents = pathComponents
}

var url: String {
guard !pathComponents.isEmpty else {
return baseUrl
}
let path = pathComponents.joined(separator: "/")
return "\(baseUrl)/\(path)"
}
}

public extension Endpoint {
static let criticalmaps = Self(baseUrl: apiBaseUrl)
static let twitter = Self(baseUrl: apiBaseUrl, path: "/twitter")

static let criticalmass = Self(baseUrl: criticalmassInEndpoint, path: "/api/ride")
static let locations = Self(baseUrl: cdnBaseUrl, pathComponents: ["locations"])
static let chatMessages = Self(baseUrl: apiGWBaseUrl, pathComponents: ["messages"])
static let twitter = Self(baseUrl: apiGWBaseUrl, pathComponents: ["twitter"])
static let criticalmass = Self(baseUrl: criticalmassInEndpoint, pathComponents: ["api", "ride"])
}

let criticalmassInEndpoint = "criticalmass.in"
let apiBaseUrl = "api.criticalmaps.net"
let cdnBaseUrl = "api-cdn.criticalmaps.net"
let apiGWBaseUrl = "api-gw.criticalmaps.net"
Loading

0 comments on commit 5135607

Please sign in to comment.