Implemented the Service protocol in the Remote library and conformed the RemoteService service to it.

This commit is contained in:
Javier Cicchelli 2023-04-13 14:02:07 +02:00
parent 842c3e1a6c
commit 2b38e03094
4 changed files with 30 additions and 5 deletions

View File

@ -0,0 +1,19 @@
//
// Service.swift
// Remote
//
// Created by Javier Cicchelli on 13/04/2023.
// Copyright © 2023 Röck+Cöde. All rights reserved.
//
import Foundation
public protocol Service {
// MARK: Functions
/// Retrieve a set of locations.
/// - Returns: The set of locations represented as a `Location` instances.
func getLocations() async throws -> [Location]
}

View File

@ -21,6 +21,12 @@ public struct RemoteService {
self.client = RemoteClient(configuration: configuration) self.client = RemoteClient(configuration: configuration)
} }
}
// MARK: - Service
extension RemoteService: Service {
// MARK: Functions // MARK: Functions
public func getLocations() async throws -> [Location] { public func getLocations() async throws -> [Location] {
@ -29,7 +35,7 @@ public struct RemoteService {
for: Locations.self for: Locations.self
).locations ).locations
} }
} }
// MARK: - Models // MARK: - Models

View File

@ -18,7 +18,7 @@ extension DependencyService {
set { Self[PersistenceKey.self] = newValue } set { Self[PersistenceKey.self] = newValue }
} }
var remote: RemoteService { var remote: Remote.Service {
get { Self[RemoteKey.self] } get { Self[RemoteKey.self] }
set { Self[RemoteKey.self] = newValue } set { Self[RemoteKey.self] = newValue }
} }
@ -31,5 +31,5 @@ struct PersistenceKey: DependencyKey {
} }
struct RemoteKey: DependencyKey { struct RemoteKey: DependencyKey {
static var currentValue: RemoteService = .init() static var currentValue: Remote.Service = RemoteService()
} }

View File

@ -16,13 +16,13 @@ struct LoadRemoteLocationsUseCase {
// MARK: Properties // MARK: Properties
private let persistence: PersistenceService private let persistence: PersistenceService
private let remoteService: RemoteService private let remoteService: Remote.Service
// MARK: Initialisers // MARK: Initialisers
init( init(
persistence: PersistenceService, persistence: PersistenceService,
remoteService: RemoteService remoteService: Remote.Service
) { ) {
self.persistence = persistence self.persistence = persistence
self.remoteService = remoteService self.remoteService = remoteService