From 6ef544c71e85ac6d86a40d2c68e7f0b5fd006025 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sun, 23 Jul 2023 13:32:43 +0200 Subject: [PATCH] Conformed the LastUpdated public model to the DTO namespace. --- Sources/Models/{ => DTO}/LastUpdated.swift | 20 ++++++++++++-------- Sources/Protocols/Service.swift | 2 +- Sources/Services/AmiiboService.swift | 8 ++++---- 3 files changed, 17 insertions(+), 13 deletions(-) rename Sources/Models/{ => DTO}/LastUpdated.swift (64%) diff --git a/Sources/Models/LastUpdated.swift b/Sources/Models/DTO/LastUpdated.swift similarity index 64% rename from Sources/Models/LastUpdated.swift rename to Sources/Models/DTO/LastUpdated.swift index 89cbaa4..94224d0 100644 --- a/Sources/Models/LastUpdated.swift +++ b/Sources/Models/DTO/LastUpdated.swift @@ -12,19 +12,23 @@ import Foundation -/// This model represents the latest date when the remote API has been updated. -public struct LastUpdated { - - // MARK: Properties - - /// The date of the latest update of the remote API. - public let timestamp: Date +public extension DTO { + + /// This model represents the latest date when the remote API has been updated. + struct LastUpdated { + + // MARK: Properties + + /// The date of the latest update of the remote API. + public let timestamp: Date + + } } // MARK: - Decodable -extension LastUpdated: Decodable { +extension DTO.LastUpdated: Decodable { enum CodingKeys: String, CodingKey { case timestamp = "lastUpdated" } diff --git a/Sources/Protocols/Service.swift b/Sources/Protocols/Service.swift index 4145f63..94a758c 100644 --- a/Sources/Protocols/Service.swift +++ b/Sources/Protocols/Service.swift @@ -21,6 +21,6 @@ protocol Service { func amiiboTypes(filter: AmiiboTypeFilter) async throws -> [AmiiboType] func gameSeries(filter: GameSeriesFilter) async throws -> [GameSeries] func characters(filter: CharacterFilter) async throws -> [Character] - func lastUpdated() async throws -> Date + func lastUpdated() async throws -> DTO.LastUpdated } diff --git a/Sources/Services/AmiiboService.swift b/Sources/Services/AmiiboService.swift index d50d608..2cf321c 100644 --- a/Sources/Services/AmiiboService.swift +++ b/Sources/Services/AmiiboService.swift @@ -119,13 +119,13 @@ extension AmiiboService: Service { /// Retrieves the date in which the remote API was last updated. /// - Returns: A `Date` instance that represents the date in which the remote API was last updated. /// - Throws: A ``AmiiboClientError`` is thrown in case a request failed, or a `DecodingError` is thrown in case the decoding of some object failed. - public func lastUpdated() async throws -> Date { + public func lastUpdated() async throws -> DTO.LastUpdated { client.setDateDecodingStrategy(.formatted(.dateAndTime)) return try await client.request( endpoint: GetLastUpdatedEndpoint(), - as: LastUpdated.self - ).timestamp + as: DTO.LastUpdated.self + ) } -} \ No newline at end of file +}