feat: Flag-Enum für Dokumentoperationen eingeführt

- Ein `Flag`-Enum erstellt, um dokumentbezogene Operationen zu repräsentieren (z.B. `CreateObject`, `CheckIn` usw.).
- Die Verwendung von Integer-Flags in `DocumentsRouteService` durch das neue Enum ersetzt, um die Lesbarkeit und Wartbarkeit des Codes zu verbessern.
- Die `Upload`-Methode aktualisiert, um Flags als Array von `Flag`-Enum-Werten zu verarbeiten.
This commit is contained in:
Developer 02 2024-09-13 11:18:24 +02:00
parent d9784115ce
commit 18b3a7dfff
3 changed files with 27 additions and 9 deletions

View File

@ -0,0 +1,13 @@
namespace WindreamHub.Legacy.Client.Models.Documents
{
public enum Flag
{
CreateObject = 1,
CheckIn = 2,
CreateNewVersion = 4,
UseDefaultLocation = 8,
ReturnIndexingDetails = 16,
ForceOverwrite = 32,
CreateTree = 64
}
}

View File

@ -8,6 +8,9 @@ using WindreamHub.Legacy.Client.Models.Documents.Response;
using WindreamHub.Legacy.Client.Models.Documents.Create.Request;
using System.IO;
using System.Web;
using WindreamHub.Legacy.Client.Models.Documents;
using System.Linq;
using System;
namespace WindreamHub.Legacy.Client.Routes
{
@ -17,22 +20,22 @@ namespace WindreamHub.Legacy.Client.Routes
{
}
public async Task<SimplifiedResponse<DocResponse, object>> Create(HttpContent docCreateBody)
public async Task<SimplifiedResponse<DocResponse, DocResponse>> Create(HttpContent docCreateBody)
=> await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody)
.ThenAsync(res => res.Simplify<DocResponse, object>());
.ThenAsync(res => res.Simplify<DocResponse, DocResponse>());
public async Task<SimplifiedResponse<DocResponse, object>> Create(DocCreateBody docCreateBody)
public async Task<SimplifiedResponse<DocResponse, DocResponse>> Create(DocCreateBody docCreateBody)
=> await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody.Stringify())
.ThenAsync(res => res.Simplify<DocResponse, object>());
.ThenAsync(res => res.Simplify<DocResponse, DocResponse>());
public async Task<SimplifiedResponse<DocResponse, object>> Upload(string path, long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params int[] flags)
public async Task<SimplifiedResponse<DocResponse, DocResponse>> Upload(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))
{
var fileContent = new StreamContent(fileStream);
var formData = new MultipartFormDataContent
{
{ fileContent, "file", "filename.pdf" }
{ fileContent, "file" },
};
var query = HttpUtility.ParseQueryString(string.Empty);
@ -47,13 +50,14 @@ namespace WindreamHub.Legacy.Client.Routes
query["parameter.item.name"] = item_name;
if (flags != null && flags.Length > 0)
query["parameter.flags"] = string.Join(",", flags);
query["parameter.flags"] = string.Join(",", flags.Select(flag => (int)flag));
if (stream_identity != null)
query["parameter.stream.__identity"] = stream_identity.ToString();
return await FetchAsync(route: "/Upload", method: HttpMethod.Post, body: fileContent)
.ThenAsync(res => res.Simplify<DocResponse, object>());
return await FetchAsync(route: $"/Upload?{query}", method: HttpMethod.Post, body: fileContent).ThenAsync(res => res.Simplify<DocResponse, DocResponse>());
}
}
}

View File

@ -85,6 +85,7 @@
<ItemGroup>
<Compile Include="DIExtensions.cs" />
<Compile Include="Models\Authentication\ErrorDetails.cs" />
<Compile Include="Models\Documents\Flag.cs" />
<Compile Include="Models\Documents\Response\Error.cs" />
<Compile Include="Models\Shared\ErrorItem.cs" />
<Compile Include="Models\Authentication\ICredential.cs" />