Skip to content

Commit 3da9877

Browse files
Juliane FerreiraJulianeGF
authored andcommitted
Finaliza implementacao da chamada para a API de login
1 parent 3f12235 commit 3da9877

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
import Foundation
22

3-
4-
53
public final class LoginAPIClient {
64

7-
func pegaloginmodel(completion: @escaping(LoginModel?, Error?) -> ()) {
8-
let url = URL(string: "https://raw.githubusercontent.com/devpass-tech/challenge-realestate-app/main/api/login.json")!
9-
var loginModel: LoginModel?
10-
11-
12-
let dataTask = URLSession.shared.dataTask(with: url) {(data, response, error) in
13-
guard let data = data else { return }
14-
let decoder = JSONDecoder()
15-
do {
16-
completion(try decoder.decode(LoginModel.self, from: data), nil)
17-
// loginModel = try decoder.decode(LoginModel.self, from: data)
18-
19-
} catch {
20-
completion(nil, error)
5+
func getLoginModel(completion: @escaping (Result<(Data, URLResponse), Error>) -> Void) {
6+
URLSession.shared.dataTask(with: URL(string: "https://raw.githubusercontent.com/devpass-tech/challenge-realestate-app/main/api/login.json")!) { data, response, error in
7+
if let error = error {
8+
completion(.failure(error))
9+
} else if let data = data, let response = response {
10+
completion(.success((data, response)))
2111
}
12+
13+
assertionFailure("Failure")
2214
}
23-
24-
dataTask.resume()
2515
}
26-
2716
}
28-

solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyList/PropertyListViewController.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import UIKit
99

1010
class PropertyListViewController: UIViewController {
11-
12-
let loginApiClient = LoginAPIClient()
1311

12+
let loginAPI = LoginAPIClient()
13+
1414
let propertyListView: PropertyListView = {
1515

1616
let propertyListView = PropertyListView()
@@ -28,8 +28,6 @@ class PropertyListViewController: UIViewController {
2828
self.view.backgroundColor = .white
2929

3030
fetchProperties()
31-
let logimodel = loginApiClient.pegaloginmodel()
32-
logimodel?.success
3331
}
3432

3533
override func loadView() {

0 commit comments

Comments
 (0)