From 4aa696410c25ac459dae7eda6e02d1b13614160f Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 13 Sep 2024 14:38:09 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20Generische=20Methoden=20f=C3=BCr=20?= =?UTF-8?q?R=C3=BCckgabetypen=20in=20DocumentsRouteService=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Refaktorierte CreateAsync-, UploadAsync-, UpdateAsync-, DownloadAsync- und DeleteAsync-Methoden, um generische TData- und TError-Typen zu unterstützen. - Dynamische Overloads für Create-, Upload-, Update-, Download- und Delete-Methoden hinzugefügt für flexible Anwendungsfälle. - Methoden-Signaturen aktualisiert, um bessere Typinferenz und Handhabung verschiedener Rückgabetypen zu ermöglichen. --- .../Routes/DocumentsRouteService.cs | 61 +++++++++++++------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs b/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs index cb8b486..ab06f92 100644 --- a/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs +++ b/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs @@ -21,15 +21,17 @@ namespace WindreamHub.Legacy.Client.Routes { } - public async Task> CreateAsync(HttpContent docCreateBody) - => await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody) - .ThenAsync(res => res.Simplify()); - - public async Task> CreateAsync(DocBody docCreateBody) + //Create + public async Task> CreateAsync(DocBody docCreateBody) => await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody.Stringify()) - .ThenAsync(res => res.Simplify()); + .ThenAsync(res => res.Simplify()); + + public Task> CreateDynamicAsync(DocBody docCreateBody) => CreateAsync(docCreateBody); - public async Task> UploadAsync(string path, long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params Flag[] flags) + public Task> CreateAsync(DocBody docCreateBody) => CreateAsync(docCreateBody); + + //Upload + public async Task> UploadAsync(string path, long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params Flag[] flags) { using (var fileStream = File.OpenRead(path)) { @@ -54,19 +56,31 @@ namespace WindreamHub.Legacy.Client.Routes query["parameter.flags"] = string.Join(",", flags.Select(flag => (int)flag)); if (stream_identity != null) - query["parameter.stream.__identity"] = stream_identity.ToString(); - - + query["parameter.stream.__identity"] = stream_identity.ToString(); - return await FetchAsync(route: $"/Upload?{query}", method: HttpMethod.Post, body: fileContent).ThenAsync(res => res.Simplify()); + return await FetchAsync(route: $"/Upload?{query}", method: HttpMethod.Post, body: fileContent).ThenAsync(res => res.Simplify()); } } - public async Task> UpdateAsync(DocBody docUpdateBody) + public Task> UploadDynamicAsync(string path, long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params Flag[] flags) + => UploadAsync(path: path, item_id: item_id, item_location: item_location, item_name: item_name, stream_identity: stream_identity, flags: flags); + + public Task> UploadAsync(string path, long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params Flag[] flags) + => UploadAsync(path: path, item_id: item_id, item_location: item_location, item_name: item_name, stream_identity: stream_identity, flags: flags); + + //Update + public async Task> UpdateAsync(DocBody docUpdateBody) => await FetchAsync(route: "/Update", method: HttpMethod.Post, body: docUpdateBody.Stringify()) - .ThenAsync(res => res.Simplify()); + .ThenAsync(res => res.Simplify()); + + public Task> UpdateDynamicAsync(DocBody docUpdateBody) + => UpdateAsync(docUpdateBody); + + public Task> UpdateAsync(DocBody docUpdateBody) + => UpdateAsync(docUpdateBody); - public async Task> DownloadAsync(long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params Flag[] flags) + //Download + public async Task> DownloadAsync(long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params Flag[] flags) { var query = HttpUtility.ParseQueryString(string.Empty); @@ -85,11 +99,24 @@ namespace WindreamHub.Legacy.Client.Routes if (stream_identity != null) query["parameter.stream.__identity"] = stream_identity.ToString(); - return await FetchAsync(route: $"/Download?{query}", method: HttpMethod.Get).ThenAsync(res => res.Simplify()); + return await FetchAsync(route: $"/Download?{query}", method: HttpMethod.Get).ThenAsync(res => res.Simplify()); } - public async Task> DeleteAsync(DocDeleteBody docDeleteBody) + public Task> DownloadDynamicAsync(long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params Flag[] flags) + => DownloadAsync(item_id: item_id, item_location: item_location, item_name: item_name, stream_identity: stream_identity, flags: flags); + + public Task> DownloadAsync(long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params Flag[] flags) + => DownloadAsync(item_id: item_id, item_location: item_location, item_name: item_name, stream_identity: stream_identity, flags: flags); + + //Delete + public async Task> DeleteAsync(DocDeleteBody docDeleteBody) => await FetchAsync(route: "/Delete", HttpMethod.Post, body: docDeleteBody.Stringify()) - .ThenAsync(res => res.Simplify()); + .ThenAsync(res => res.Simplify()); + + public async Task> DeleteDynamicAsync(DocDeleteBody docDeleteBody) + => await DeleteAsync(docDeleteBody: docDeleteBody); + + public async Task> DeleteAsync(DocDeleteBody docDeleteBody) + => await DeleteAsync(docDeleteBody: docDeleteBody); } } \ No newline at end of file