updated protocol for paging
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
13de040621
commit
801830e5b8
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
/// This will be the interface for the API for Employees
|
/// This will be the interface for the API for Employees
|
||||||
public protocol EmployeeServiceProtocol {
|
public protocol EmployeeServiceProtocol {
|
||||||
|
|
||||||
/// This will get a list of all employees
|
/// This will get a list of all employees
|
||||||
/// - Parameter serviceMode: Mode in which to hit.
|
/// - Parameter serviceMode: Mode in which to hit.
|
||||||
/// - Returns: An Employees struct
|
/// - Returns: An Employees struct
|
||||||
func getEmployees(_ serviceMode: EmployeeServiceMode) async throws -> Employees
|
func getEmployees(_ serviceMode: EmployeeServiceMode) async throws -> Employees
|
||||||
|
func getEmployees(_ serviceMode: EmployeeServiceMode, page: Int, perPage: Int) async throws -> Employees
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,4 +42,28 @@ public class EmployeeService: EmployeeServiceProtocol {
|
|||||||
public func getEmployees(_ serviceMode: EmployeeServiceMode = .production) async throws -> Employees {
|
public func getEmployees(_ serviceMode: EmployeeServiceMode = .production) async throws -> Employees {
|
||||||
return try await NetworkService.shared.fetchData(from: serviceMode.endpoint, as: Employees.self)
|
return try await NetworkService.shared.fetchData(from: serviceMode.endpoint, as: Employees.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetch employees with pagination support
|
||||||
|
/// - Parameters:
|
||||||
|
/// - page: The page number to fetch.
|
||||||
|
/// - perPage: The number of employees per page.
|
||||||
|
/// - Returns: A paginated Employees object.
|
||||||
|
public func getEmployees(_ serviceMode: EmployeeServiceMode = .production, page: Int, perPage: Int) async throws -> Employees {
|
||||||
|
guard var urlComponents = URLComponents(string: serviceMode.endpoint) else {
|
||||||
|
throw NetworkServiceError.invalidURL
|
||||||
|
}
|
||||||
|
|
||||||
|
urlComponents.queryItems = [
|
||||||
|
URLQueryItem(name: "page", value: "\(page)"),
|
||||||
|
URLQueryItem(name: "perPage", value: "\(perPage)")
|
||||||
|
]
|
||||||
|
|
||||||
|
guard let url = urlComponents.url else {
|
||||||
|
throw NetworkServiceError.invalidURL
|
||||||
|
}
|
||||||
|
|
||||||
|
let request = RequestBuilder(url: url, method: .get).build()
|
||||||
|
|
||||||
|
return try await NetworkService.shared.fetchData(with: request, as: Employees.self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user