Defined the Service protocol.
This commit is contained in:
parent
7670d5b7a0
commit
f748c11886
30
Libraries/Sources/APIService/Protocols/Service.swift
Normal file
30
Libraries/Sources/APIService/Protocols/Service.swift
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user