Add lead workflows, PDF signing, AR projects and photo gallery integration
This commit is contained in:
30
GasTankAR/Services/LoginUseCase.swift
Normal file
30
GasTankAR/Services/LoginUseCase.swift
Normal file
@ -0,0 +1,30 @@
|
||||
import Foundation
|
||||
|
||||
protocol LoginUseCase: Sendable {
|
||||
func execute(salesCode: String) async throws -> LoginSession
|
||||
}
|
||||
|
||||
/// Shared by the use case and the form so that both enforce the same rule.
|
||||
enum SalesCodeValidator {
|
||||
static func normalized(_ input: String) -> String {
|
||||
input.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
|
||||
}
|
||||
|
||||
static func isValid(_ input: String) -> Bool {
|
||||
normalized(input).count >= 3
|
||||
}
|
||||
}
|
||||
|
||||
struct DefaultLoginUseCase: LoginUseCase {
|
||||
let authenticationService: any AuthenticationService
|
||||
|
||||
func execute(salesCode: String) async throws -> LoginSession {
|
||||
guard SalesCodeValidator.isValid(salesCode) else {
|
||||
throw LoginError.invalidSalesCode
|
||||
}
|
||||
try Task.checkCancellation()
|
||||
return try await authenticationService.signIn(
|
||||
salesCode: SalesCodeValidator.normalized(salesCode)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user