Conformed the KeyName public model and its type aliases to the DTO namespace.

This commit is contained in:
Javier Cicchelli 2023-07-23 13:37:36 +02:00
parent 6ef544c71e
commit c5701a4881
4 changed files with 62 additions and 54 deletions

View File

@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the AmiiboService open source project
//
// Copyright (c) 2023 Röck+Cöde VoF. and the AmiiboService project authors
// Licensed under the EUPL 1.2 or later.
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of AmiiboService project authors
//
//===----------------------------------------------------------------------===//
public extension DTO {
/// This model is a concrete genetic definition that represents the following models: ``AmiiboSeries``, ``AmiiboType``, ``Character`` and ``GameSeries``.
struct KeyName {
// MARK: Properties
/// The key of the model.
public let key: String
/// The name of the model.
public let name: String
}
}
// MARK: - Type aliases
public extension DTO {
/// This model represents the series an amiibo belongs to.
typealias AmiiboSeries = DTO.KeyName
/// This model represents the type an amiibo belongs to.
typealias AmiiboType = KeyName
/// This model represents the character an amiibo is associated to.
typealias Character = KeyName
/// This model represents the games series an amiibo is associated to.
typealias GameSeries = KeyName
}
// MARK: - Decodable
extension DTO.KeyName: Decodable {}

View File

@ -1,42 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the AmiiboService open source project
//
// Copyright (c) 2023 Röck+Cöde VoF. and the AmiiboService project authors
// Licensed under the EUPL 1.2 or later.
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of AmiiboService project authors
//
//===----------------------------------------------------------------------===//
/// This model is a concrete genetic definition that represents the following models: ``AmiiboSeries``, ``AmiiboType``, ``Character`` and ``GameSeries``.
public struct KeyName {
// MARK: Properties
/// The key of the model.
public let key: String
/// The name of the model.
public let name: String
}
// MARK: - Type aliases
/// This model represents the series an amiibo belongs to.
public typealias AmiiboSeries = KeyName
/// This model represents the type an amiibo belongs to.
public typealias AmiiboType = KeyName
/// This model represents the character an amiibo is associated to.
public typealias Character = KeyName
/// This model represents the games series an amiibo is associated to.
public typealias GameSeries = KeyName
// MARK: - Decodable
extension KeyName: Decodable {}

View File

@ -17,10 +17,10 @@ protocol Service {
// MARK: Functions
func amiibos(filter: AmiiboFilter) async throws -> [Amiibo]
func amiiboSeries(filter: AmiiboSeriesFilter) async throws -> [AmiiboSeries]
func amiiboTypes(filter: AmiiboTypeFilter) async throws -> [AmiiboType]
func gameSeries(filter: GameSeriesFilter) async throws -> [GameSeries]
func characters(filter: CharacterFilter) async throws -> [Character]
func amiiboSeries(filter: AmiiboSeriesFilter) async throws -> [DTO.AmiiboSeries]
func amiiboTypes(filter: AmiiboTypeFilter) async throws -> [DTO.AmiiboType]
func gameSeries(filter: GameSeriesFilter) async throws -> [DTO.GameSeries]
func characters(filter: CharacterFilter) async throws -> [DTO.Character]
func lastUpdated() async throws -> DTO.LastUpdated
}

View File

@ -62,12 +62,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 amiiboSeries(
filter: AmiiboSeriesFilter = .init()
) async throws -> [AmiiboSeries] {
) async throws -> [DTO.AmiiboSeries] {
client.setDateDecodingStrategy(.deferredToDate)
return try await client.request(
endpoint: GetSeriesEndpoint(parameters: filter.makeParameters()),
as: Result<AmiiboSeries>.self
as: Result<DTO.AmiiboSeries>.self
).items
}
@ -77,12 +77,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 amiiboTypes(
filter: AmiiboTypeFilter = .init()
) async throws -> [AmiiboType] {
) async throws -> [DTO.AmiiboType] {
client.setDateDecodingStrategy(.deferredToDate)
return try await client.request(
endpoint: GetTypeEndpoint(parameters: filter.makeParameters()),
as: Result<AmiiboType>.self
as: Result<DTO.AmiiboType>.self
).items
}
@ -92,12 +92,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 characters(
filter: CharacterFilter = .init()
) async throws -> [Character] {
) async throws -> [DTO.Character] {
client.setDateDecodingStrategy(.deferredToDate)
return try await client.request(
endpoint: GetCharacterEndpoint(parameters: filter.makeParameters()),
as: Result<Character>.self
as: Result<DTO.Character>.self
).items
}
@ -107,12 +107,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 gameSeries(
filter: GameSeriesFilter = .init()
) async throws -> [GameSeries] {
) async throws -> [DTO.GameSeries] {
client.setDateDecodingStrategy(.deferredToDate)
return try await client.request(
endpoint: GetGameSeriesEndpoint(parameters: filter.makeParameters()),
as: Result<GameSeries>.self
as: Result<DTO.GameSeries>.self
).items
}