-
Notifications
You must be signed in to change notification settings - Fork 10
Added: nomes, funções e classe e OO - LoginViewController #17
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?
Added: nomes, funções e classe e OO - LoginViewController #17
Conversation
| return .lightContent | ||
| } | ||
|
|
||
| func verifyLogin() { |
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.
sobre essa logica de verificar se o usuario ta logado tenho 2 pontos:
1 - é interessante criar um useCase para isso, assim essa logica pode ser reaproveitada pelo projeto
2 - nao faz sentido essa logica estar dentro dessa controller, é uma logica que viria antes de login
ou seja, se o usuario estive logado, manda para hoje, senão, para login
logo sugiro criar um InitialRouter ou um InitalCoordinator para lidar com esse roteamento inicial, e chamar essa classe dentro desse case no SceneDelegate:

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.
salve salve @ppedroam !
essa função eu movi para a validateSession ! Faz sentido?
| Globals.alertMessage(title: "Ops..", message: "Houve um problema, tente novamente mais tarde.", targetVC: self) | ||
| } | ||
|
|
||
| AF.shared.request( |
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 viewModel ou service para chamada de api
|
|
||
|
|
||
| @IBAction func createAccountButton(_ sender: Any) { | ||
| @IBAction func createAccountDidTap(_ sender: Any) { |
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.
didTapCreateAccountButton*
o nomenclatura deve se assemelhar a forma inglesa de ler
| } | ||
|
|
||
| @IBAction func resetPasswordButton(_ sender: Any) { | ||
| @IBAction func resetPasswordDidTap(_ sender: Any) { |
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.
didTapResetPasswordButton
| } | ||
|
|
||
| // MARK: - IBActions | ||
| @IBAction func loginDidTap(_ sender: Any) { |
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.
didTapLoginButton
| let vc = storyboard.instantiateViewController(withIdentifier: "LuzResetPasswordViewController") as! LuzResetPasswordViewController | ||
| vc.modalPresentationStyle = .fullScreen | ||
| present(vc, animated: true) | ||
| let viewController = storyboard.instantiateViewController( |
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 factory para ResetViewController
| button.layer.borderColor = borderColor.cgColor | ||
| button.setTitleColor(borderColor, for: .normal) | ||
| button.backgroundColor = .white | ||
| } |
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.
normalmente os projeto adotam padrões de layout (DesignSystem)
logo podemos presumir que essa configuração de botao vai acontecer em varias telas
pode entao criar se uma extension de UIButton para configurar os botões
o certo mesmo seria criar uma classe do tipo UIButton que tivesse a configuração que queriamos
mas precisaríamos de viewCode
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.
salve salve @ppedroam !
Então, este PR ainda não contempla a refatoração para viewCode. Este ajuste pode ficar para o proximo PR que conterá view code? Como sugere?
| do { | ||
| let session = try JSONDecoder().decode(Session.self, from: data) | ||
| Task { @MainActor in self.setupHomeViewController() } | ||
| UserDefaultsManager.UserInfos.shared.save(session: session, user: nil) |
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.
no useCase de login teria uma funcao para salvar infos do usuario
ai vc chamaria esse useCase
| } | ||
|
|
||
| // MARK: - MakeParams | ||
| extension LuzLoginViewController { |
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.
passar para service ou viewmodel
| // MARK: - Setup HomeViewController | ||
| extension LuzLoginViewController { | ||
| func setupHomeViewController() { | ||
| let navigationController = UINavigationController(rootViewController: LuzHomeViewController()) |
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 Factory
e criar coordinator para essa viewcontroller
ppedroam
left a comment
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.
code review 1
| import UIKit | ||
|
|
||
| final class LuzLoginViewController: UIViewController { | ||
| private let viewModel: LuzLoginViewModel |
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.
fazer viewModel ser orientada a protocolo
| @IBOutlet weak var emailTextField: UITextField! | ||
| @IBOutlet weak var passwordTextField: UITextField! | ||
|
|
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.
aplicar private nas IBOutlet
| emailTextField.text = "clean.code@devpass.com" | ||
| passwordTextField.text = "111111" | ||
| #endif | ||
| viewModel.setupDebugConfiguration( |
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.
logica de controle em elementos UI devem ser feitas na viewController
| func validateSession() { | ||
| guard UserDefaultsManager.UserInfos.shared.readSesion() != nil else { return } | ||
| setupHomeViewController() | ||
| viewModel.validateSession { [weak self] 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.
essa logica deve ser feita antes de abrir a LoginViewController
igual eu te falei, cria um InitialCoordinatol que retorna a primeira controller que vai ser aberta
dentro do coordinator vai ter essa logica de validar sessao
se estiver logado, retorna HomeViewController
se nao, retorna sua Login
isso não é uma logica que é responsabilidade da login
assim o codigo fica acoplado
| self.handleError() | ||
| Task { | ||
| do { | ||
| let data = try await viewModel.login( |
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.
nao precisa chamar a funcao login na viewModel pare receber o dat aqui e novamente chamar uma funcao na viewModel
vc pode chamar só um método na viewModel (login) e la dentro, a própria viewModel, chama a funcao privada handleLoginSuccess
| ) as! LuzResetPasswordViewController | ||
|
|
||
| @IBAction func didTapResetPassword(_ sender: Any) { | ||
| let viewController = LuzResetPasswordFactory.make() |
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.
essa linha d baixo pode ficar na factory
| completion: @escaping (UIAlertController) -> Void | ||
| ) { | ||
| if !ConnectivityManager.shared.isConnected { | ||
| let alertController = UIAlertController( |
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.
a logica de alerta nao deve ficar na viewModel
viewModel é apenas regra de negocio
vc pode colocar no coordinator ou na própria viewController
| } | ||
| } | ||
|
|
||
| func makeParams( |
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.
funcao privada
| UserDefaultsManager.UserInfos.shared.save(session: session, user: nil) | ||
| } | ||
|
|
||
| func validateButton( |
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.
confesso que achei essa codigo complexo para uma logica simples
pq nao criar uma funcao de uma linha na viewModel assim:
func isEmailValid(email: String?) -> Bool { return LuzLoginEmailValidator.validate(email)
vc esta trabalhando com duas closures escaping apenas para validar uma string
isso é um caso de overEngineering
ppedroam
left a comment
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.
code review 2
ignora o comentario de fazer protocolo para viewModel pq essa tarefa nao abrange POP e DIP
Este PR contempla a refatoração de mais uma view controller:
tratar classe
tratar nome de funções
tratar nomes
um pouco do OO (encapsulamento)