Skip to content

Conversation

@lfoliveir4
Copy link
Contributor

@lfoliveir4 lfoliveir4 commented Feb 12, 2025

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)

@lfoliveir4 lfoliveir4 changed the title Added: LoginViewController Added: nomes, funções e classe - LoginViewController Feb 12, 2025
@lfoliveir4 lfoliveir4 changed the title Added: nomes, funções e classe - LoginViewController Added: nomes, funções e classe e OO - LoginViewController Feb 12, 2025
return .lightContent
}

func verifyLogin() {
Copy link
Owner

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:
image

Copy link
Contributor Author

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(
Copy link
Owner

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) {
Copy link
Owner

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) {
Copy link
Owner

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) {
Copy link
Owner

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(
Copy link
Owner

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
}
Copy link
Owner

@ppedroam ppedroam Feb 13, 2025

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

Copy link
Contributor Author

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)
Copy link
Owner

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 {
Copy link
Owner

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())
Copy link
Owner

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

Copy link
Owner

@ppedroam ppedroam left a 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
Copy link
Owner

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!

Copy link
Owner

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(
Copy link
Owner

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
Copy link
Owner

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(
Copy link
Owner

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()
Copy link
Owner

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(
Copy link
Owner

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(
Copy link
Owner

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(
Copy link
Owner

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

Copy link
Owner

@ppedroam ppedroam left a 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

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