From 7e2ae11be3957bc8613f226d3c4cd94f39e274e3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Sun, 12 May 2024 17:22:29 +0200 Subject: [PATCH] Fix service issues --- LeStorage/Services.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index 7a1cd65..9b0ebe0 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -129,6 +129,10 @@ public class Services { return try self._baseRequest(servicePath: servicePath, method: .post) } + fileprivate func _putRequest(servicePath: String) throws -> URLRequest { + return try self._baseRequest(servicePath: servicePath, method: .put) + } + fileprivate func _getRequest(servicePath: String) throws -> URLRequest { return try self._baseRequest(servicePath: servicePath, method: .get) } @@ -161,7 +165,13 @@ public class Services { } public func post(_ instance: T) async throws -> T { - var postRequest = try self._postRequest(servicePath: T.resourceName()) + var postRequest = try self._postRequest(servicePath: T.resourceName() + "/") + postRequest.httpBody = try jsonEncoder.encode(instance) + return try await self._runRequest(postRequest) + } + + public func put(_ instance: T) async throws -> T { + var postRequest = try self._putRequest(servicePath: T.resourceName() + "/" + instance.id + "/") postRequest.httpBody = try jsonEncoder.encode(instance) return try await self._runRequest(postRequest) }