[Improvement] DTOs #19
@ -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"
|
||||
}
|
@ -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
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user