Fix iOS list response decoding to match plain-array backend responses
GET /clients and GET /projects return bare arrays, not wrapped objects. Remove ClientListResponse and ProjectListResponse wrapper structs and update ClientsViewModel, ProjectsViewModel, and TimerViewModel to decode [Client] and [Project] directly.
This commit is contained in:
@@ -15,11 +15,10 @@ final class ClientsViewModel: ObservableObject {
|
|||||||
error = nil
|
error = nil
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let response: ClientListResponse = try await apiClient.request(
|
clients = try await apiClient.request(
|
||||||
endpoint: APIEndpoint.clients,
|
endpoint: APIEndpoint.clients,
|
||||||
authenticated: true
|
authenticated: true
|
||||||
)
|
)
|
||||||
clients = response.clients
|
|
||||||
|
|
||||||
try await database.saveClients(clients)
|
try await database.saveClients(clients)
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,15 @@ final class ProjectsViewModel: ObservableObject {
|
|||||||
error = nil
|
error = nil
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let clientsResponse: ClientListResponse = try await apiClient.request(
|
clients = try await apiClient.request(
|
||||||
endpoint: APIEndpoint.clients,
|
endpoint: APIEndpoint.clients,
|
||||||
authenticated: true
|
authenticated: true
|
||||||
)
|
)
|
||||||
clients = clientsResponse.clients
|
|
||||||
|
|
||||||
let projectsResponse: ProjectListResponse = try await apiClient.request(
|
projects = try await apiClient.request(
|
||||||
endpoint: APIEndpoint.projects,
|
endpoint: APIEndpoint.projects,
|
||||||
authenticated: true
|
authenticated: true
|
||||||
)
|
)
|
||||||
projects = projectsResponse.projects
|
|
||||||
|
|
||||||
try await database.saveProjects(projects)
|
try await database.saveProjects(projects)
|
||||||
|
|
||||||
|
|||||||
@@ -37,11 +37,10 @@ final class TimerViewModel: ObservableObject {
|
|||||||
try await database.cacheTimer(activeTimer)
|
try await database.cacheTimer(activeTimer)
|
||||||
|
|
||||||
// Fetch projects
|
// Fetch projects
|
||||||
let response: ProjectListResponse = try await apiClient.request(
|
projects = try await apiClient.request(
|
||||||
endpoint: APIEndpoint.projects,
|
endpoint: APIEndpoint.projects,
|
||||||
authenticated: true
|
authenticated: true
|
||||||
)
|
)
|
||||||
projects = response.projects
|
|
||||||
|
|
||||||
// Set selected project if timer has one
|
// Set selected project if timer has one
|
||||||
if let timerProject = activeTimer?.project {
|
if let timerProject = activeTimer?.project {
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ struct Client: Codable, Identifiable, Equatable, Hashable {
|
|||||||
let updatedAt: String
|
let updatedAt: String
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ClientListResponse: Codable {
|
|
||||||
let clients: [Client]
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CreateClientInput: Codable {
|
struct CreateClientInput: Codable {
|
||||||
let name: String
|
let name: String
|
||||||
let description: String?
|
let description: String?
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ struct ClientReference: Codable, Equatable, Hashable {
|
|||||||
let name: String
|
let name: String
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProjectListResponse: Codable {
|
|
||||||
let projects: [Project]
|
|
||||||
}
|
|
||||||
|
|
||||||
struct CreateProjectInput: Codable {
|
struct CreateProjectInput: Codable {
|
||||||
let name: String
|
let name: String
|
||||||
let description: String?
|
let description: String?
|
||||||
|
|||||||
Reference in New Issue
Block a user