-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
994 additions
and
802 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
CriticalMapsKit/.swiftpm/xcode/xcshareddata/xcschemes/ChatFeature.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.