diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp.xcodeproj/project.pbxproj b/solutions/devsprint-andre-nogueira-1/RealEstateApp.xcodeproj/project.pbxproj index 3d9a6ab..fb9a02c 100644 --- a/solutions/devsprint-andre-nogueira-1/RealEstateApp.xcodeproj/project.pbxproj +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp.xcodeproj/project.pbxproj @@ -22,6 +22,9 @@ 54C4595928077D03004DD3DF /* UIViewController+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54C4595828077D03004DD3DF /* UIViewController+Extensions.swift */; }; 54E204C92804EB8C009FFEDC /* AccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E204C82804EB8C009FFEDC /* AccountView.swift */; }; 54E204CB28051E0A009FFEDC /* AccountViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E204CA28051E0A009FFEDC /* AccountViewModel.swift */; }; + 8B5548A728061AB400714870 /* LoginModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B5548A628061AB400714870 /* LoginModel.swift */; }; + 8B5548A928061B8000714870 /* LoginAPIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B5548A828061B8000714870 /* LoginAPIClient.swift */; }; + 8BD13BF3281868DF001756F4 /* PropertyInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BD13BF2281868DF001756F4 /* PropertyInfoView.swift */; }; 980789CB275E8FAF00CED39A /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980789CA275E8FAF00CED39A /* SettingsViewController.swift */; }; 980789CE275E943D00CED39A /* FavoritesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980789CD275E943C00CED39A /* FavoritesViewController.swift */; }; 980789D9275EA3C900CED39A /* AccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980789D8275EA3C900CED39A /* AccountViewController.swift */; }; @@ -77,6 +80,9 @@ 54C4595828077D03004DD3DF /* UIViewController+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extensions.swift"; sourceTree = ""; }; 54E204C82804EB8C009FFEDC /* AccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountView.swift; sourceTree = ""; }; 54E204CA28051E0A009FFEDC /* AccountViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountViewModel.swift; sourceTree = ""; }; + 8B5548A628061AB400714870 /* LoginModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginModel.swift; sourceTree = ""; }; + 8B5548A828061B8000714870 /* LoginAPIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginAPIClient.swift; sourceTree = ""; }; + 8BD13BF2281868DF001756F4 /* PropertyInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyInfoView.swift; sourceTree = ""; }; 980789CA275E8FAF00CED39A /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; 980789CD275E943C00CED39A /* FavoritesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesViewController.swift; sourceTree = ""; }; 980789D8275EA3C900CED39A /* AccountViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountViewController.swift; sourceTree = ""; }; @@ -141,6 +147,14 @@ path = Utils; sourceTree = ""; }; + 8BD13BF1281868C1001756F4 /* PropertyInfo */ = { + isa = PBXGroup; + children = ( + 8BD13BF2281868DF001756F4 /* PropertyInfoView.swift */, + ); + path = PropertyInfo; + sourceTree = ""; + }; 980789C9275E8F8E00CED39A /* Settings */ = { isa = PBXGroup; children = ( @@ -183,6 +197,7 @@ children = ( 980C0C0A2704F1C700F8100A /* RealEstateAPIClientProperty.swift */, B0D7AA932805BFA8006177F8 /* RealEstateAPIFavorites.swift */, + 8B5548A828061B8000714870 /* LoginAPIClient.swift */, ); path = APIClient; sourceTree = ""; @@ -190,6 +205,7 @@ 980C0C172704F1D500F8100A /* Screens */ = { isa = PBXGroup; children = ( + 8BD13BF1281868C1001756F4 /* PropertyInfo */, 54C4595528077B4B004DD3DF /* Utils */, B0D7AA952805F05B006177F8 /* TabBar */, 980C0C182704F1DE00F8100A /* PropertyList */, @@ -239,6 +255,7 @@ A50AC3F928089F4900873216 /* Address.swift */, A50AC3FB28089FEA00873216 /* Pricing.swift */, B0D7AA912805BBB7006177F8 /* Favorites.swift */, + 8B5548A628061AB400714870 /* LoginModel.swift */, ); path = Models; sourceTree = ""; @@ -466,17 +483,20 @@ 543091792811EB4100BDC903 /* UIView+Extensions.swift in Sources */, 54309171281094F900BDC903 /* BaseView.swift in Sources */, 980789CE275E943D00CED39A /* FavoritesViewController.swift in Sources */, + 8BD13BF3281868DF001756F4 /* PropertyInfoView.swift in Sources */, 986153D02704EE2B00838CA6 /* AppDelegate.swift in Sources */, 986153D22704EE2B00838CA6 /* SceneDelegate.swift in Sources */, A50AC3FC28089FEA00873216 /* Pricing.swift in Sources */, 5498E3B52814DF14002BD1C4 /* PropertyListFactory.swift in Sources */, 54E204CB28051E0A009FFEDC /* AccountViewModel.swift in Sources */, + 8B5548A728061AB400714870 /* LoginModel.swift in Sources */, 980789CB275E8FAF00CED39A /* SettingsViewController.swift in Sources */, B0D7AA942805BFA8006177F8 /* RealEstateAPIFavorites.swift in Sources */, 980C0C1C2704F23E00F8100A /* PropertyDetailsViewController.swift in Sources */, A50AC4062808BEC000873216 /* PropertyImageView.swift in Sources */, E9FE07EC28076C6C00B2752F /* AccountFactory.swift in Sources */, 980C0C112704F1C700F8100A /* RealEstateAPIClientProperty.swift in Sources */, + 8B5548A928061B8000714870 /* LoginAPIClient.swift in Sources */, 54E204C92804EB8C009FFEDC /* AccountView.swift in Sources */, 5446FD1128178A1200640269 /* Bindable.swift in Sources */, 980789D9275EA3C900CED39A /* AccountViewController.swift in Sources */, diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/DataManager/APIClient/LoginAPIClient.swift b/solutions/devsprint-andre-nogueira-1/RealEstateApp/DataManager/APIClient/LoginAPIClient.swift new file mode 100644 index 0000000..b4e6f3d --- /dev/null +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/DataManager/APIClient/LoginAPIClient.swift @@ -0,0 +1,32 @@ +import Foundation + +protocol LoginAPIClientProtocol: AnyObject { + func fetchProperties(completion: @escaping (Result<[Property], ErrorRequest>) -> Void) +} + +public final class LoginAPIClient { + func fetchProperties(completion: @escaping (Result) -> Void) { + let urlString = ManagerGetURL.getLoginURL() + guard let url = URL(string: urlString) else { + completion(.failure(ErrorRequest.urlNotValid)) + return + } + + let task = URLSession.shared.dataTask(with: url) { data, response, error in + guard let response = response as? HTTPURLResponse, response.statusCode == 200, let data = data else { + completion(.failure(ErrorRequest.invalidJson)) + return + } + do { + let decoder = JSONDecoder() + let result = try decoder.decode(LoginModel.self, from: data) + completion(.success(result)) + } catch { + print(error) + completion(.failure(ErrorRequest.noData)) + } + } + + task.resume() + } +} diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/DataManager/APIClient/RealEstateAPIClientProperty.swift b/solutions/devsprint-andre-nogueira-1/RealEstateApp/DataManager/APIClient/RealEstateAPIClientProperty.swift index b33a6a1..aa2b221 100644 --- a/solutions/devsprint-andre-nogueira-1/RealEstateApp/DataManager/APIClient/RealEstateAPIClientProperty.swift +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/DataManager/APIClient/RealEstateAPIClientProperty.swift @@ -40,3 +40,4 @@ public final class RealEstateAPIClientProperty: RealEstateAPIPropertyProtocol { task.resume() } } + \ No newline at end of file diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Models/LoginModel.swift b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Models/LoginModel.swift new file mode 100644 index 0000000..9b4e75e --- /dev/null +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Models/LoginModel.swift @@ -0,0 +1,3 @@ +public struct LoginModel: Decodable { + let success: Bool +} diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Models/PerformLoginModel.swift b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Models/PerformLoginModel.swift new file mode 100644 index 0000000..350c82f --- /dev/null +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Models/PerformLoginModel.swift @@ -0,0 +1,2 @@ + +import Foundation diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Plist-URL/ManagerGetURL.swift b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Plist-URL/ManagerGetURL.swift index 0959864..916025f 100644 --- a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Plist-URL/ManagerGetURL.swift +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Plist-URL/ManagerGetURL.swift @@ -27,4 +27,12 @@ struct ManagerGetURL { return urlString } + public static func getLoginURL() -> String { + + let baseURL = InfoPlistBaseURL.getStringValue(forKey: "BaseURL") + let login = InfoPlistBaseURL.getStringValue(forKey: "LoginRequestEndPoint") + let urlString = baseURL + login + + return urlString + } } diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Resources/Info.plist b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Resources/Info.plist index 0ab1d77..02b6a66 100644 --- a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Resources/Info.plist +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Resources/Info.plist @@ -8,6 +8,8 @@ favorites.json PropertyRequestEndPoint listings.json + LoginRequestEndPoint + login.json NSAppTransportSecurity NSAllowsArbitraryLoads diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyDetails/PropertyDetailsViewController.swift b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyDetails/PropertyDetailsViewController.swift index e547f0b..7b65afd 100644 --- a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyDetails/PropertyDetailsViewController.swift +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyDetails/PropertyDetailsViewController.swift @@ -9,6 +9,8 @@ import UIKit class PropertyDetailsViewController: UIViewController { + let propertyInfoView = PropertyInfoView() + private lazy var propertyDetailsView: PropertyDetailsView = { let view = PropertyDetailsView() view.sendContactButton.addTarget(self, action: #selector(sendContactForm), for: .touchUpInside) diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyInfo/PropertyInfoView.swift b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyInfo/PropertyInfoView.swift new file mode 100644 index 0000000..1109003 --- /dev/null +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyInfo/PropertyInfoView.swift @@ -0,0 +1,68 @@ +import UIKit + +class PropertyInfoView: BaseView, ViewCodable { + + private lazy var priceLabel: UILabel = { + let label = UILabel() + label.text = " R$ 405.000" + label.font = .systemFont(ofSize: 20) + label.tintColor = .black + label.font = .boldSystemFont(ofSize: 20) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + private lazy var buildingLabel: UILabel = { + let label = UILabel() + label.text = "Condomínio R$ 495 IPTU R$ 0" + label.tintColor = .black + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + private lazy var infoLabel: UILabel = { + let label = UILabel() + label.text = "69 m² 3 quartos 2 banheiros 1 vaga" + label.font = UIFont.systemFont(ofSize: 14) + label.textColor = UIColor.lightGray.withAlphaComponent(0.9) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + private lazy var addressLabel: UILabel = { + let label = UILabel() + label.text = "Sem endereço" + label.font = UIFont.systemFont(ofSize: 14) + label.textColor = UIColor.lightGray.withAlphaComponent(0.9) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + func setUpHierarchy() { + [priceLabel, buildingLabel, infoLabel, addressLabel].forEach { + addSubview($0) + } + } + + func setUpConstraints() { + NSLayoutConstraint.activate([ + priceLabel.topAnchor.constraint(equalTo: bottomAnchor, constant: 10), + priceLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -16), + priceLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 16), + + buildingLabel.topAnchor.constraint(equalTo: priceLabel.bottomAnchor, constant: 10), + buildingLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -16), + buildingLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 16), + + infoLabel.topAnchor.constraint(equalTo: buildingLabel.bottomAnchor, constant: 10), + infoLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -16), + infoLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 16), + + addressLabel.topAnchor.constraint(equalTo: infoLabel.bottomAnchor, constant: 10), + addressLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -16), + addressLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 16), + + bottomAnchor.constraint(equalTo: addressLabel.bottomAnchor, constant: 10) + ]) + } +} diff --git a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyList/PropertyListViewController.swift b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyList/PropertyListViewController.swift index af10d1a..fbab49e 100644 --- a/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyList/PropertyListViewController.swift +++ b/solutions/devsprint-andre-nogueira-1/RealEstateApp/Screens/PropertyList/PropertyListViewController.swift @@ -10,7 +10,7 @@ import UIKit class PropertyListViewController: UIViewController { private let viewModel: PropertyListViewModelProtocol - + private let propertyListView: PropertyListView = { let propertyListView = PropertyListView() return propertyListView @@ -52,4 +52,3 @@ class PropertyListViewController: UIViewController { } } } -