[Improvement] DTOs #19

Merged
javier merged 6 commits from improvement/dtos into main 2023-07-23 13:51:26 +00:00
3 changed files with 17 additions and 13 deletions
Showing only changes of commit 6ef544c71e - Show all commits

View File

@ -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"
}

View File

@ -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
}

View File

@ -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
)
}
}
}