iOS: Kaufpreis + Belege am Einzelstück
ItemEditView bekommt einen Kaufpreis (Betrag + CHF/EUR) und eine Beleg-Sektion: Rechnung/Garantieschein als Bild (Fotoauswahl) oder PDF (Datei-Import) hochladen, ansehen (QuickLook) und loeschen. Nach einem PDF-Upload schlaegt der Server "Garantie bis" und Kaufpreis vor – per Knopf uebernehmbar. Item-Model um priceCents/currency/documents erweitert; Client-Methoden fuer Upload, Download und Loeschen der Belege. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -182,6 +182,36 @@ actor APIClient {
|
||||
try await sendNoContent(request)
|
||||
}
|
||||
|
||||
func uploadItemDocument(itemId: Int, data: Data, filename: String,
|
||||
contentType: String) async throws -> ItemDocumentUpload {
|
||||
var request = try makeRequest("/items/\(itemId)/documents", method: "POST")
|
||||
let boundary = "Boundary-\(UUID().uuidString)"
|
||||
request.setValue("multipart/form-data; boundary=\(boundary)",
|
||||
forHTTPHeaderField: "Content-Type")
|
||||
let safeName = filename.replacingOccurrences(of: "\"", with: "")
|
||||
var body = Data()
|
||||
body.append("--\(boundary)\r\n".data(using: .utf8)!)
|
||||
body.append("Content-Disposition: form-data; name=\"file\"; filename=\"\(safeName)\"\r\n"
|
||||
.data(using: .utf8)!)
|
||||
body.append("Content-Type: \(contentType)\r\n\r\n".data(using: .utf8)!)
|
||||
body.append(data)
|
||||
body.append("\r\n--\(boundary)--\r\n".data(using: .utf8)!)
|
||||
request.httpBody = body
|
||||
return try await send(request, as: ItemDocumentUpload.self)
|
||||
}
|
||||
|
||||
func itemDocumentData(itemId: Int, docId: Int) async throws -> Data {
|
||||
let request = try makeRequest("/items/\(itemId)/documents/\(docId)")
|
||||
let (data, response) = try await URLSession.shared.data(for: request)
|
||||
try check(response, data: data)
|
||||
return data
|
||||
}
|
||||
|
||||
func deleteItemDocument(itemId: Int, docId: Int) async throws {
|
||||
try await sendNoContent(
|
||||
try makeRequest("/items/\(itemId)/documents/\(docId)", method: "DELETE"))
|
||||
}
|
||||
|
||||
func deleteItem(id: Int) async throws {
|
||||
try await sendNoContent(try makeRequest("/items/\(id)", method: "DELETE"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user