Refactor: ContactUS - View Model / Async await / View Code#26
Refactor: ContactUS - View Model / Async await / View Code#26lfoliveir4 wants to merge 2 commits intoppedroam:mainfrom
Conversation
| import Foundation | ||
|
|
||
| protocol ContactUSServiceProtocol { | ||
| func fetch() async throws -> Data |
There was a problem hiding this comment.
fetch what?
usa um nome mais claro
|
|
||
| protocol ContactUSServiceProtocol { | ||
| func fetch() async throws -> Data | ||
| func send(with parameters: [String: String]) async throws |
There was a problem hiding this comment.
send what?
usar um nome mais claro tb
| final class ContactUSService: ContactUSServiceProtocol { | ||
| func fetch() async throws -> Data { | ||
| return try await withCheckedThrowingContinuation { continuation in | ||
| AF.shared.request( |
There was a problem hiding this comment.
ja chegou na parte de parar de usar singleton?
se sim, usar GoodNetworkLayer aqui tb
se n me engano o Jorge tem um PR em q ele usou
se n tiver chegado na parte de remover singlton, pode ignorar
|
|
||
| func send(with parameters: [String: String]) async throws { | ||
| return try await withCheckedThrowingContinuation { continuation in | ||
| AF.shared.request( |
| import UIKit | ||
|
|
||
| final class ContactUSView: UIView { | ||
| let symbolConfiguration = UIImage.SymbolConfiguration(pointSize: 36) |
There was a problem hiding this comment.
tem propriedade com essa e outras que poderiam ser privates
| return stackView | ||
| } | ||
|
|
||
| func createCTAStackView() -> UIStackView { |
There was a problem hiding this comment.
oq é CTA?
lembre que não é bom usar siglas (há raras exceções)
| } | ||
|
|
||
| func fetch() async throws { | ||
| guard let data = try? await serivce.fetch() else { return } |
There was a problem hiding this comment.
dar uma nome melhor para fetch
nao usar try? opcional, já que a funcao dispara erro
fazer protocol para viewModel (se estiver no contexto desse PR)
| } | ||
|
|
||
| func send(parameters: [String: String]) async throws { | ||
| try? await serivce.send(with: parameters) |
There was a problem hiding this comment.
melhorar nome e remover try opcional
| enum LuzContactUsFactory { | ||
| static func make() -> UIViewController { | ||
| let service = ContactUSService() | ||
| let viewModel = LuzContactUSViewModel(serivce: service) |
| button.backgroundColor = .systemGray4 | ||
| button.layer.cornerRadius = 10 | ||
| button.addTarget( | ||
| contactUSView.chatButton.addTarget( |
| @@ -192,34 +73,15 @@ final class LuzContactUsViewController: LoadingInheritageController { | |||
|
|
|||
| func fetch() { | |||
| guard | ||
| let message = contactUSView.textView.text, message.isEmpty == false | ||
| else { return } | ||
| let email = model?.mail ?? "" |
| "mensagem": message | ||
| ] | ||
|
|
||
| showLoadingView() |
There was a problem hiding this comment.
esconder loading ao final da Task
Separa as responsabilidades e tarefas que estavam faltando: