Skip to content

Chamada da api de login #6

Open
JulianeGF wants to merge 3 commits intodevpass-tech:mainfrom
JulianeGF:LoginAPIClient
Open

Chamada da api de login #6
JulianeGF wants to merge 3 commits intodevpass-tech:mainfrom
JulianeGF:LoginAPIClient

Conversation

@JulianeGF
Copy link
Copy Markdown

@JulianeGF JulianeGF commented Apr 12, 2022

  • Cria chamada para a API de Login de forma nativa.


public final class LoginAPIClient {

func pegaloginmodel(completion: @escaping(LoginModel?, Error?) -> ()) {
Copy link
Copy Markdown
Contributor

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")!
Copy link
Copy Markdown
Contributor

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

@JulianeGF JulianeGF marked this pull request as ready for review April 14, 2022 13:07
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
Copy link
Copy Markdown
Contributor

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... }

Copy link
Copy Markdown
Author

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")
Copy link
Copy Markdown
Contributor

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 {
Copy link
Copy Markdown
Contributor

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"


class PropertyListViewController: UIViewController {

let loginAPI = LoginAPIClient()
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Author

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.

@JulianeGF JulianeGF changed the title inicia implementacao da chamada api de login - WIP Chamada da api de login Apr 26, 2022
} else if let data = data, let response = response {
completion(.success((data, response)))
func fetchProperties(completion: @escaping (Result<LoginModel, ErrorRequest>) -> Void) {
let urlString = ManagerGetURL.getLoginURL()
Copy link
Copy Markdown
Contributor

@andrevinic andrevinic Apr 26, 2022

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

Copy link
Copy Markdown
Contributor

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.

import Foundation

protocol LoginAPIClientProtocol: AnyObject {
func fetchProperties(completion: @escaping (Result<[Property], ErrorRequest>) -> Void)
Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants