This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Combine | |
import Alamofire | |
protocol RepoAPIProtocol { | |
func getRepos(quary: String, perPage: Int, page: Int) -> AnyPublisher<Repos, AFError> | |
} | |
struct RepoAPI: RepoAPIProtocol { | |
func getRepos(quary: String, perPage: Int, page: Int) -> AnyPublisher<Repos, AFError> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Combine | |
final class SearchRepoViewModel: ObservableObject { | |
// MARK: - Published properties | |
@Published var searchQuery = "" | |
@Published private(set) var state = PageState.idle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct SearchRepoView: View { | |
@ObservedObject var viewModel: SearchRepoViewModel | |
var body: some View { | |
NavigationView { | |
VStack { | |
switch viewModel.state { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
enum ErrorType { | |
case decoding | |
case noInternet | |
case backend(Int) | |
} | |
struct ErrorView: View { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
SearchRepoViewDI().searchRepoView | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Post | |
func fetchToken(reqBody: TokenRequest) -> AnyPublisher<TokenResponse, AFError> { | |
let url = URL(string: baseURL + Endpoints.start.makeURL)! | |
let headers: HTTPHeaders = [ | |
"Content-Type" : "application/json" | |
] | |
return AF.request(url, method: .post, parameters: reqBody, encoder: JSONParameterEncoder.default, headers: headers) | |
.validate() |