diff --git a/Libraries/Sources/APIService/Protocols/Service.swift b/Libraries/Sources/APIService/Protocols/Service.swift new file mode 100644 index 0000000..0f559f3 --- /dev/null +++ b/Libraries/Sources/APIService/Protocols/Service.swift @@ -0,0 +1,30 @@ +// +// Service.swift +// APIService +// +// Created by Javier Cicchelli on 04/12/2022. +// Copyright © 2022 Röck+Cöde. All rights reserved. +// + +import Foundation + +public protocol Service { + func getUser(credentials: Credentials) async throws -> Me + func getItems(id: String, credentials: Credentials) async throws -> [Item] + func getData(id: String, credentials: Credentials) async throws -> Data + func createFolder(id: String, name: String, credentials: Credentials) async throws -> Item + func uploadFile(id: String, file: File, credentials: Credentials) async throws -> Item + func deleteItem(id: String, credentials: Credentials) async throws +} + +// MARK: - Structs + +public struct Credentials { + let username: String + let password: String +} + +public struct File { + let name: String + let data: Data +} diff --git a/Libraries/Sources/APIService/Structs/APIClient.swift b/Libraries/Sources/APIService/Structs/APIClient.swift index ca7c67f..2295426 100644 --- a/Libraries/Sources/APIService/Structs/APIClient.swift +++ b/Libraries/Sources/APIService/Structs/APIClient.swift @@ -49,7 +49,7 @@ extension APIClient: Client { case .noContent: throw APIClientError.notSupported case .badRequest: - throw APIClientError.itemAlreadyExist + throw APIClientError.itemNameInvalidOrDefined case .unauthorized, .forbidden: throw APIClientError.authenticationFailed @@ -114,7 +114,7 @@ public enum APIClientError: Error { case responseNotReturned case authenticationFailed case itemIsNotFile - case itemAlreadyExist + case itemNameInvalidOrDefined case itemDoesNotExist case notSupported } diff --git a/Libraries/Tests/APIServiceTests/Cases/Structs/APIClient+RequestTests.swift b/Libraries/Tests/APIServiceTests/Cases/Structs/APIClient+RequestTests.swift index 40851f0..0949ea0 100644 --- a/Libraries/Tests/APIServiceTests/Cases/Structs/APIClient+RequestTests.swift +++ b/Libraries/Tests/APIServiceTests/Cases/Structs/APIClient+RequestTests.swift @@ -35,6 +35,10 @@ final class APIClientRequestTests: XCTestCase { client = .init(configuration: sessionConfiguration) } + override func tearDown() async throws { + client = nil + } + // MARK: Request cases func test_withSomeEndpoint_andSomeModel_whenResponseStatusOk() async throws { @@ -150,7 +154,7 @@ final class APIClientRequestTests: XCTestCase { // WHEN & THEN do { _ = try await client.request(endpoint: endpoint, model: Me.self) - } catch APIClientError.itemAlreadyExist { + } catch APIClientError.itemNameInvalidOrDefined { XCTAssertTrue(true) } catch { XCTAssertTrue(false)