Moved the Amiibo API implementation to its own package #2

Merged
javier merged 12 commits from migration/api-work into main 2024-09-14 22:26:39 +00:00
Showing only changes of commit 4a8f402036 - Show all commits

View File

@ -19,6 +19,7 @@ public struct AmiiboMockClient {
private let amiibos: [Amiibo]?
private let amiiboSeries: [AmiiboSeries]?
private let amiiboTypes: [AmiiboType]?
private let error: AmiiboServiceError?
private let gameCharacters: [GameCharacter]?
private let gameSeries: [GameSeries]?
private let lastUpdated: Date?
@ -31,11 +32,13 @@ public struct AmiiboMockClient {
amiiboTypes: [AmiiboType]? = nil,
gameCharacters: [GameCharacter]? = nil,
gameSeries: [GameSeries]? = nil,
lastUpdated: Date? = nil
lastUpdated: Date? = nil,
error: AmiiboServiceError? = nil
) {
self.amiibos = amiibos
self.amiiboSeries = amiiboSeries
self.amiiboTypes = amiiboTypes
self.error = error
self.gameCharacters = gameCharacters
self.gameSeries = gameSeries
self.lastUpdated = lastUpdated
@ -50,6 +53,8 @@ extension AmiiboMockClient: APIClient {
// MARK: Functions
public func getAmiibos(by filter: AmiiboFilter) async throws -> [Amiibo] {
try throwErrorIfExists()
guard let amiibos else {
throw AmiiboServiceError.notFound
}
@ -58,6 +63,8 @@ extension AmiiboMockClient: APIClient {
}
public func getAmiiboSeries(by filter: AmiiboSeriesFilter) async throws -> [AmiiboSeries] {
try throwErrorIfExists()
guard let amiiboSeries else {
throw AmiiboServiceError.notFound
}
@ -66,6 +73,8 @@ extension AmiiboMockClient: APIClient {
}
public func getAmiiboTypes(by filter: AmiiboTypeFilter) async throws -> [AmiiboType] {
try throwErrorIfExists()
guard let amiiboTypes else {
throw AmiiboServiceError.notFound
}
@ -74,6 +83,8 @@ extension AmiiboMockClient: APIClient {
}
public func getGameCharacters(by filter: GameCharacterFilter) async throws -> [GameCharacter] {
try throwErrorIfExists()
guard let gameCharacters else {
throw AmiiboServiceError.notFound
}
@ -82,6 +93,8 @@ extension AmiiboMockClient: APIClient {
}
public func getGameSeries(by filter: GameSeriesFilter) async throws -> [GameSeries] {
try throwErrorIfExists()
guard let gameSeries else {
throw AmiiboServiceError.notFound
}
@ -90,6 +103,8 @@ extension AmiiboMockClient: APIClient {
}
public func getLastUpdated() async throws -> Date {
try throwErrorIfExists()
guard let lastUpdated else {
throw AmiiboServiceError.notFound
}
@ -99,3 +114,17 @@ extension AmiiboMockClient: APIClient {
}
// MARK: - Helpers
private extension AmiiboMockClient {
// MARK: Functions
func throwErrorIfExists() throws {
if let error {
throw error
}
}
}