-
Notifications
You must be signed in to change notification settings - Fork 6
Chamada da api de login #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
||
public final class LoginAPIClient { | ||
|
||
func pegaloginmodel(completion: @escaping(LoginModel?, Error?) -> ()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utilizar camel case no metodo
pegaLoginModel
trocar por ingles
getLoginModel
public final class LoginAPIClient { | ||
|
||
func pegaloginmodel(completion: @escaping(LoginModel?, Error?) -> ()) { | ||
let url = URL(string: "https://raw.githubusercontent.com/devpass-tech/challenge-realestate-app/main/api/login.json")! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alinhar com Douglas e Bruno para encapsular o endpoint num plist e obter de um Manager o resultado
public final class LoginAPIClient { | ||
|
||
func getLoginModel(completion: @escaping (Result<(Data, URLResponse), Error>) -> Void) { | ||
URLSession.shared.dataTask(with: URL(string: "https://raw.githubusercontent.com/devpass-tech/challenge-realestate-app/main/api/login.json")!) { data, response, error in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Criar URL em uma propriedade local, usando guard let, caso de falha pode usar assertionFailure("mensagem sobre erro")
guard let urlLogin = URL(...) else { assertionFail... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tentei seguir o mesmo padrao de outras chamadas
completion(.success((data, response))) | ||
} | ||
|
||
assertionFailure("Failure") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remover assertionFailure desta linha
public struct LoginModel: Decodable { | ||
let success: Bool | ||
|
||
enum CodingKeys: String, CodingKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aqui podemos remover coding keys, tem o mesmo valor da variavel.
este CodingKeys utilizamos apenas para valor diferente da raiz do da propriedade declarada.
Exemplo: let sucessO: Bool
CodingKeys... successo = "success"
@@ -9,6 +9,8 @@ import UIKit | |||
|
|||
class PropertyListViewController: UIViewController { | |||
|
|||
let loginAPI = LoginAPIClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Utilizar a chamada do login na cena do Login, que ja subiu na master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Não encontrei a cena do Login.
7d87939
to
896e675
Compare
896e675
to
3da9877
Compare
} else if let data = data, let response = response { | ||
completion(.success((data, response))) | ||
func fetchProperties(completion: @escaping (Result<LoginModel, ErrorRequest>) -> Void) { | ||
let urlString = ManagerGetURL.getLoginURL() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Injetar no init do LoginAPIClient a propriedade ManagerGetURL
@@ -1,16 +1,32 @@ | |||
import Foundation | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Utilizar Account ViewModel para integrar o LoginAPIClient
Renomear AccountViewModel para LoginViewModel
Criar Factory da funcionalidade, olhar exemplo na master, ja temos a Factory la.
@@ -1,16 +1,32 @@ | |||
import Foundation | |||
|
|||
protocol LoginAPIClientProtocol: AnyObject { | |||
func fetchProperties(completion: @escaping (Result<[Property], ErrorRequest>) -> Void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integrar a chama do APIClient na ViewModel
E esse dado na ViewModel integrado com a ViewController correspondente.
Uh oh!
There was an error while loading. Please reload this page.