diff --git a/Sources/NetworkApi/Interfaces/BaseNetworkService.swift b/Sources/NetworkApi/Interfaces/BaseNetworkService.swift index 0302317..640bbd8 100644 --- a/Sources/NetworkApi/Interfaces/BaseNetworkService.swift +++ b/Sources/NetworkApi/Interfaces/BaseNetworkService.swift @@ -4,12 +4,14 @@ import Alamofire import Foundation +//Класс для запросов public final class BaseNetworkService: BaseNetworkServiceProtocol { - public var baseURL: String? + public var baseURL: String? // standart url public init() {} + //func request public func execute(path: String, method: HTTPMethod, headers: HTTPHeaders, parameters: Parameters? = nil) async throws -> Data { guard let baseURL = baseURL else { fatalError("Error baseURL") diff --git a/Sources/NetworkApi/Interfaces/BaseNetworkServiceProtocol.swift b/Sources/NetworkApi/Interfaces/BaseNetworkServiceProtocol.swift index 1cce6fb..d99fb94 100644 --- a/Sources/NetworkApi/Interfaces/BaseNetworkServiceProtocol.swift +++ b/Sources/NetworkApi/Interfaces/BaseNetworkServiceProtocol.swift @@ -4,6 +4,7 @@ import Alamofire import Foundation +//protocol for BaseNetworkService public protocol BaseNetworkServiceProtocol { func execute(path: String, method: HTTPMethod, headers: HTTPHeaders, parameters: Parameters?) async throws -> Data func configure(baseURL: String) diff --git a/Sources/NetworkApi/NetworkLayer/Auth/NetworkUser.swift b/Sources/NetworkApi/NetworkLayer/Auth/NetworkUser.swift index 7d07e15..b97f1e4 100644 --- a/Sources/NetworkApi/NetworkLayer/Auth/NetworkUser.swift +++ b/Sources/NetworkApi/NetworkLayer/Auth/NetworkUser.swift @@ -7,15 +7,16 @@ import Foundation +//Main class for request for user public final class NetworkUser: NetworkUserProtocol { - let baseUrl: BaseNetworkServiceProtocol + let baseUrl: BaseNetworkServiceProtocol //Create request public init(baseUrl: BaseNetworkServiceProtocol) { self.baseUrl = baseUrl } - + //method login public func login(identity: String, password: String) async throws -> ServerResponseAuth { let data = try await baseUrl.execute(path: URLS.login, method: .post, headers: Headers.headers(), parameters: [ "identity": identity, @@ -23,7 +24,7 @@ public final class NetworkUser: NetworkUserProtocol { ]) return try JSONDecoder().decode(ServerResponseAuth.self, from: data) } - + //method register public func register(email: String, password: String, passwordConfirm: String, firstname: String, lastname: String, secondname: String, datebirthday: String, gender: String) async throws -> ServerResponseRegister { let data = try await baseUrl.execute(path: URLS.register, method: .post, headers: Headers.headers(), parameters: [ "email": email, @@ -32,11 +33,11 @@ public final class NetworkUser: NetworkUserProtocol { ]) let result = try JSONDecoder().decode(ServerResponseRegister.self, from: data) let login = try await login(identity: email, password: password) - print("TOKEN: \(login.token)") + UserDefaults.standard.set(login.token, forKey: "token") let addUserResult = try await addUser(idUser: result.id, email: email, firstname: firstname, lastname: lastname, secondname: secondname, datebirthday: datebirthday, gender: gender, token: login.token) return addUserResult } - + //method addUser public func addUser(idUser: String, email: String, firstname: String, lastname: String, secondname: String, datebirthday: String, gender: String, token: String) async throws -> ServerResponseRegister { let path = URLS.updateUserInfo+idUser print(path)