updated to select endpoint

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2025-01-20 17:39:52 -06:00
parent e4268fd22f
commit dc25bd490d
2 changed files with 21 additions and 5 deletions

View File

@ -6,5 +6,5 @@
// //
public protocol EmployeeServiceProtocol { public protocol EmployeeServiceProtocol {
func getEmployees() async throws -> [Employee] func getEmployees(_ serviceMode: EmployeeServiceMode) async throws -> Employees
} }

View File

@ -6,14 +6,30 @@
// //
import Foundation import Foundation
/// These are the testing URL Endpoints for different states
public enum EmployeeServiceMode {
case production
case malformed
case empty
public var endpoint: String {
switch self {
case .production:
return "https://s3.amazonaws.com/sq-mobile-interview/employees.json"
case .malformed:
return "https://s3.amazonaws.com/sq-mobile-interview/employees_malformed.json"
case .empty:
return "https://s3.amazonaws.com/sq-mobile-interview/employees_empty.json"
}
}
}
/// Service Layer for Employees /// Service Layer for Employees
public class EmployeeService: EmployeeServiceProtocol { public class EmployeeService: EmployeeServiceProtocol {
/// Service to get Employees /// Service to get Employees
/// - Returns: Array of Employee Structs /// - Returns: Array of Employee Structs
public func getEmployees() async throws -> [Employee] { public func getEmployees(_ serviceMode: EmployeeServiceMode = .production) async throws -> Employees {
let endpoint = "https://s3.amazonaws.com/sq-mobile-interview/employees.json" return try await NetworkService.shared.fetchData(from: serviceMode.endpoint, as: Employees.self)
let employees: Employees = try await NetworkService.shared.fetchData(from: endpoint, as: Employees.self)
return employees.employees
} }
} }