From 9edb121c1cdb90ad6298f97d132876cf8804b477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Salata?= Date: Sat, 30 Oct 2021 14:01:05 -0300 Subject: [PATCH] Refactor --- Counters/Counters/Model/Counter.swift | 4 ++-- Counters/Counters/Service/CountersService.swift | 10 +++++----- .../ViewModel/CreateCounterViewModel.swift | 1 - Counters/Network/APIClient.swift | 1 - Counters/Network/Protocols/URLSessionProtocol.swift | 2 -- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Counters/Counters/Model/Counter.swift b/Counters/Counters/Model/Counter.swift index 64b99c8..422e769 100644 --- a/Counters/Counters/Model/Counter.swift +++ b/Counters/Counters/Model/Counter.swift @@ -14,6 +14,6 @@ struct Counter: Decodable, Equatable { } struct CounterPayload: Codable, Equatable { - let id: String? - let title: String? + var id: String? + var title: String? } diff --git a/Counters/Counters/Service/CountersService.swift b/Counters/Counters/Service/CountersService.swift index 7f4c23a..1235759 100644 --- a/Counters/Counters/Service/CountersService.swift +++ b/Counters/Counters/Service/CountersService.swift @@ -6,7 +6,6 @@ // import Foundation -import Combine final class CountersService { private let client: APIClient @@ -20,22 +19,23 @@ final class CountersService { } func increment(id: String, completion: @escaping (Result<[Counter], APIError>, URLResponse?) -> Void) { - let payload = CounterPayload(id: id, title: nil) + let payload = CounterPayload(id: id) client.request(target: CounterServiceTarget.increment(payload: payload), completion: completion) } func decrement(id: String, completion: @escaping (Result<[Counter], APIError>, URLResponse?) -> Void) { - let payload = CounterPayload(id: id, title: nil) + let payload = CounterPayload(id: id) client.request(target: CounterServiceTarget.decrement(payload: payload), completion: completion) } func save(title: String, completion: @escaping (Result<[Counter], APIError>, URLResponse?) -> Void) { - let payload = CounterPayload(id: nil, title: title) + let payload = CounterPayload(title: title) client.request(target: CounterServiceTarget.save(payload: payload), completion: completion) } func delete(id: String, completion: @escaping (Result<[Counter], APIError>, URLResponse?) -> Void) { - client.request(target: CounterServiceTarget.delete(payload: CounterPayload(id: id, title: nil)), + let payload = CounterPayload(id: id) + client.request(target: CounterServiceTarget.delete(payload: payload), completion: completion) } } diff --git a/Counters/Create Counter/ViewModel/CreateCounterViewModel.swift b/Counters/Create Counter/ViewModel/CreateCounterViewModel.swift index 8fbfe74..26b4a36 100644 --- a/Counters/Create Counter/ViewModel/CreateCounterViewModel.swift +++ b/Counters/Create Counter/ViewModel/CreateCounterViewModel.swift @@ -6,7 +6,6 @@ // import Foundation -import Combine final class CreateCounterViewModel { private let service: CountersService diff --git a/Counters/Network/APIClient.swift b/Counters/Network/APIClient.swift index 6f937a1..430517c 100755 --- a/Counters/Network/APIClient.swift +++ b/Counters/Network/APIClient.swift @@ -4,7 +4,6 @@ // import Foundation -import Combine class APIClient { private var session: URLSessionProtocol diff --git a/Counters/Network/Protocols/URLSessionProtocol.swift b/Counters/Network/Protocols/URLSessionProtocol.swift index 8d85821..0891f64 100644 --- a/Counters/Network/Protocols/URLSessionProtocol.swift +++ b/Counters/Network/Protocols/URLSessionProtocol.swift @@ -5,8 +5,6 @@ import Foundation -typealias APIResponse = URLSession.DataTaskPublisher.Output - protocol URLSessionProtocol { func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask