updated for paging
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
7e0c2fd310
commit
68ab23aefd
@ -11,14 +11,14 @@ public struct Employees: Codable {
|
|||||||
|
|
||||||
/// Array of Employees
|
/// Array of Employees
|
||||||
public var employees: [Employee]
|
public var employees: [Employee]
|
||||||
public let total: Int?
|
public let total: Int
|
||||||
public let page: Int?
|
public let page: Int
|
||||||
public let perPage: Int?
|
public let perPage: Int
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case employees
|
case employees
|
||||||
case total
|
case total
|
||||||
case page
|
case page
|
||||||
case perPage
|
case perPage = "per_page"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class MockEmployeeService: EmployeeServiceProtocol {
|
|||||||
guard startIndex < totalUsers else {
|
guard startIndex < totalUsers else {
|
||||||
return .init(employees: [], total: totalUsers, page: page, perPage: perPage) // Return empty if out of bounds
|
return .init(employees: [], total: totalUsers, page: page, perPage: perPage) // Return empty if out of bounds
|
||||||
}
|
}
|
||||||
|
print("Fetching Page", page, "of", totalUsers)
|
||||||
let paginatedUsers = Array(employees.employees[startIndex..<endIndex])
|
let paginatedUsers = Array(employees.employees[startIndex..<endIndex])
|
||||||
return .init(employees: paginatedUsers, total: totalUsers, page: page, perPage: perPage)
|
return .init(employees: paginatedUsers, total: totalUsers, page: page, perPage: perPage)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"total": 1000,
|
||||||
|
"page": 100,
|
||||||
|
"per_page": 10,
|
||||||
"employees": [
|
"employees": [
|
||||||
{
|
{
|
||||||
"uuid": "2851dc6c-b5e4-4033-baad-6b62e9e10f72",
|
"uuid": "2851dc6c-b5e4-4033-baad-6b62e9e10f72",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user