33 lines
1.2 KiB
Swift
33 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
/// `/api/projects` — Pro-only folders. `list()` itself is not gated (a
|
|
/// downgraded Pro user can still see how their receipts were filed), but
|
|
/// create/rename/delete return `402 pro_required` for a free-plan account —
|
|
/// surface that as a paywall prompt, not a generic error.
|
|
enum ProjectsAPI {
|
|
static func list() async throws -> [Project] {
|
|
let response: ProjectListResponse = try await APIClient.shared.send(
|
|
APIRequest(path: "/api/projects", method: .get)
|
|
)
|
|
return response.projects
|
|
}
|
|
|
|
@discardableResult
|
|
static func create(name: String, color: String?) async throws -> Project {
|
|
struct Response: Decodable { let success: Bool; let project: Project }
|
|
let request = try APIRequest.json(
|
|
path: "/api/projects",
|
|
method: .post,
|
|
body: CreateProjectRequest(name: name, color: color)
|
|
)
|
|
let response: Response = try await APIClient.shared.send(request)
|
|
return response.project
|
|
}
|
|
|
|
static func delete(id: String) async throws {
|
|
try await APIClient.shared.sendDiscardingResponse(
|
|
APIRequest(path: "/api/projects/\(id)", method: .delete)
|
|
)
|
|
}
|
|
}
|