Conformed the Amiibo public model and its child models to the DTO namespace.

This commit is contained in:
Javier Cicchelli 2023-07-23 13:46:39 +02:00
parent c5701a4881
commit 31edafee3e
8 changed files with 62 additions and 52 deletions

View File

@ -10,6 +10,8 @@
//
//===----------------------------------------------------------------------===//
extension DTO {
/// This model struct represents an amiibo that is retrieved from the respective [remote API endpoint](https://www.amiiboapi.com/docs/#amiibo).
public struct Amiibo {
@ -46,9 +48,11 @@ public struct Amiibo {
public let games: Games?
}
}
// MARK: - Structs
extension Amiibo {
extension DTO.Amiibo {
/// This model represents the list of games related to a particular amiibo, grouped by system.
public struct Games: Decodable {
@ -67,7 +71,7 @@ extension Amiibo {
// MARK: - Decodable
extension Amiibo: Decodable {
extension DTO.Amiibo: Decodable {
// MARK: Enumerations

View File

@ -10,7 +10,8 @@
//
//===----------------------------------------------------------------------===//
extension Amiibo {
extension DTO.Amiibo {
/// This model structs represents a game that is related to an amiibo, when requested to the respective [remote API endpoint](https://www.amiiboapi.com/docs/#showGames).
public struct Game {
@ -26,11 +27,12 @@ extension Amiibo {
public let usage: [Usage]?
}
}
// MARK: - Decodable
extension Amiibo.Game: Decodable {
extension DTO.Amiibo.Game: Decodable {
enum CodingKeys: String, CodingKey {
case ids = "gameID"
case name = "gameName"

View File

@ -10,7 +10,8 @@
//
//===----------------------------------------------------------------------===//
extension Amiibo.Game {
extension DTO.Amiibo.Game {
/// This model struct represents how an amiibo is used with a particular game, when requested to the respective [remote API endpoint](https://www.amiiboapi.com/docs/#showUsage).
public struct Usage {
@ -23,11 +24,12 @@ extension Amiibo.Game {
public let isWritable: Bool
}
}
// MARK: - Decodable
extension Amiibo.Game.Usage: Decodable {
extension DTO.Amiibo.Game.Usage: Decodable {
enum CodingKeys: String, CodingKey {
case explanation = "Usage"
case isWritable = "write"

View File

@ -12,7 +12,8 @@
import Foundation
extension Amiibo {
extension DTO.Amiibo {
/// This model struct represents a collection of official release dates (if released) of an amiibo in different markets around the world.
public struct Release {
@ -31,11 +32,12 @@ extension Amiibo {
public let america: Date?
}
}
// MARK: - Decodable
extension Amiibo.Release: Decodable {
extension DTO.Amiibo.Release: Decodable {
enum CodingKeys: String, CodingKey {
case australia = "au"
case europe = "eu"

View File

@ -10,10 +10,10 @@
//
//===----------------------------------------------------------------------===//
public extension DTO {
extension DTO {
/// This model is a concrete genetic definition that represents the following models: ``AmiiboSeries``, ``AmiiboType``, ``Character`` and ``GameSeries``.
struct KeyName {
public struct KeyName {
// MARK: Properties
@ -29,19 +29,19 @@ public extension DTO {
// MARK: - Type aliases
public extension DTO {
extension DTO {
/// This model represents the series an amiibo belongs to.
typealias AmiiboSeries = DTO.KeyName
public typealias AmiiboSeries = DTO.KeyName
/// This model represents the type an amiibo belongs to.
typealias AmiiboType = KeyName
public typealias AmiiboType = KeyName
/// This model represents the character an amiibo is associated to.
typealias Character = KeyName
public typealias Character = KeyName
/// This model represents the games series an amiibo is associated to.
typealias GameSeries = KeyName
public typealias GameSeries = KeyName
}

View File

@ -12,10 +12,10 @@
import Foundation
public extension DTO {
extension DTO {
/// This model represents the latest date when the remote API has been updated.
struct LastUpdated {
public struct LastUpdated {
// MARK: Properties

View File

@ -16,7 +16,7 @@ protocol Service {
// MARK: Functions
func amiibos(filter: AmiiboFilter) async throws -> [Amiibo]
func amiibos(filter: AmiiboFilter) async throws -> [DTO.Amiibo]
func amiiboSeries(filter: AmiiboSeriesFilter) async throws -> [DTO.AmiiboSeries]
func amiiboTypes(filter: AmiiboTypeFilter) async throws -> [DTO.AmiiboType]
func gameSeries(filter: GameSeriesFilter) async throws -> [DTO.GameSeries]

View File

@ -47,12 +47,12 @@ extension AmiiboService: Service {
/// - 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 amiibos(
filter: AmiiboFilter = .init()
) async throws -> [Amiibo] {
) async throws -> [DTO.Amiibo] {
client.setDateDecodingStrategy(.formatted(.dateOnly))
return try await client.request(
endpoint: GetAmiiboEndpoint(parameters: filter.makeParameters()),
as: Result<Amiibo>.self
as: Result<DTO.Amiibo>.self
).items
}