From 2b38e03094650e145f340d3086e22033378cea65 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 13 Apr 2023 14:02:07 +0200 Subject: [PATCH] Implemented the Service protocol in the Remote library and conformed the RemoteService service to it. --- .../Sources/Remote/Protocols/Service.swift | 19 +++++++++++++++++++ .../Remote/Services/RemoteService.swift | 8 +++++++- .../Extensions/DependencyService+Keys.swift | 4 ++-- .../LoadRemoteLocationsUseCase.swift | 4 ++-- 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 Apps/Locations/Libraries/Sources/Remote/Protocols/Service.swift diff --git a/Apps/Locations/Libraries/Sources/Remote/Protocols/Service.swift b/Apps/Locations/Libraries/Sources/Remote/Protocols/Service.swift new file mode 100644 index 0000000..1da2d50 --- /dev/null +++ b/Apps/Locations/Libraries/Sources/Remote/Protocols/Service.swift @@ -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] + +} diff --git a/Apps/Locations/Libraries/Sources/Remote/Services/RemoteService.swift b/Apps/Locations/Libraries/Sources/Remote/Services/RemoteService.swift index b9bca95..ee71790 100644 --- a/Apps/Locations/Libraries/Sources/Remote/Services/RemoteService.swift +++ b/Apps/Locations/Libraries/Sources/Remote/Services/RemoteService.swift @@ -21,6 +21,12 @@ public struct RemoteService { self.client = RemoteClient(configuration: configuration) } +} + +// MARK: - Service + +extension RemoteService: Service { + // MARK: Functions public func getLocations() async throws -> [Location] { @@ -29,7 +35,7 @@ public struct RemoteService { for: Locations.self ).locations } - + } // MARK: - Models diff --git a/Apps/Locations/Sources/Extensions/DependencyService+Keys.swift b/Apps/Locations/Sources/Extensions/DependencyService+Keys.swift index b1286d0..aed48af 100644 --- a/Apps/Locations/Sources/Extensions/DependencyService+Keys.swift +++ b/Apps/Locations/Sources/Extensions/DependencyService+Keys.swift @@ -18,7 +18,7 @@ extension DependencyService { set { Self[PersistenceKey.self] = newValue } } - var remote: RemoteService { + var remote: Remote.Service { get { Self[RemoteKey.self] } set { Self[RemoteKey.self] = newValue } } @@ -31,5 +31,5 @@ struct PersistenceKey: DependencyKey { } struct RemoteKey: DependencyKey { - static var currentValue: RemoteService = .init() + static var currentValue: Remote.Service = RemoteService() } diff --git a/Apps/Locations/Sources/Use Cases/LoadRemoteLocationsUseCase.swift b/Apps/Locations/Sources/Use Cases/LoadRemoteLocationsUseCase.swift index 50c3cc1..fd436c3 100644 --- a/Apps/Locations/Sources/Use Cases/LoadRemoteLocationsUseCase.swift +++ b/Apps/Locations/Sources/Use Cases/LoadRemoteLocationsUseCase.swift @@ -16,13 +16,13 @@ struct LoadRemoteLocationsUseCase { // MARK: Properties private let persistence: PersistenceService - private let remoteService: RemoteService + private let remoteService: Remote.Service // MARK: Initialisers init( persistence: PersistenceService, - remoteService: RemoteService + remoteService: Remote.Service ) { self.persistence = persistence self.remoteService = remoteService