From c5701a4881558ae4a0bc54a833ddea0673d58a9b Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sun, 23 Jul 2023 13:37:36 +0200 Subject: [PATCH] Conformed the KeyName public model and its type aliases to the DTO namespace. --- Sources/Models/DTO/KeyName.swift | 50 ++++++++++++++++++++++++++++ Sources/Models/KeyName.swift | 42 ----------------------- Sources/Protocols/Service.swift | 8 ++--- Sources/Services/AmiiboService.swift | 16 ++++----- 4 files changed, 62 insertions(+), 54 deletions(-) create mode 100644 Sources/Models/DTO/KeyName.swift delete mode 100644 Sources/Models/KeyName.swift diff --git a/Sources/Models/DTO/KeyName.swift b/Sources/Models/DTO/KeyName.swift new file mode 100644 index 0000000..73e7fee --- /dev/null +++ b/Sources/Models/DTO/KeyName.swift @@ -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 {} diff --git a/Sources/Models/KeyName.swift b/Sources/Models/KeyName.swift deleted file mode 100644 index 03bc50d..0000000 --- a/Sources/Models/KeyName.swift +++ /dev/null @@ -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 {} diff --git a/Sources/Protocols/Service.swift b/Sources/Protocols/Service.swift index 94a758c..3e04350 100644 --- a/Sources/Protocols/Service.swift +++ b/Sources/Protocols/Service.swift @@ -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 } diff --git a/Sources/Services/AmiiboService.swift b/Sources/Services/AmiiboService.swift index 2cf321c..82108da 100644 --- a/Sources/Services/AmiiboService.swift +++ b/Sources/Services/AmiiboService.swift @@ -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.self + as: Result.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.self + as: Result.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.self + as: Result.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.self + as: Result.self ).items }