From ba069d56fdc4e09e6fa6df133261e966181fe868 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Tue, 3 Oct 2023 11:44:53 +0200 Subject: [PATCH] finish tables api --- .../Client/Apps/Tables/Model/RowUpdate.cs | 15 +++++++++++ .../Client/Apps/Tables/OcsApiTables.cs | 11 ++++++++ .../Client/Apps/Tables/TablesClient.cs | 10 ++++++++ .../Client/ClientBase.cs | 2 +- .../NextcloudClient.cs | 25 +++++++++++++------ .../OCS/OcsApi.cs | 7 ++++-- ...Networking.CloudProviders.Nextcloud.csproj | 2 +- .../README.md | 1 + 8 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowUpdate.cs create mode 100644 Pilz.Networking.CloudProviders.Nextcloud/README.md diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowUpdate.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowUpdate.cs new file mode 100644 index 0000000..23a2f5b --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowUpdate.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model +{ + public class RowUpdate + { + [JsonProperty("data")] + public Dictionary Data { get; set; } = new(); + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/OcsApiTables.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/OcsApiTables.cs index 64483a4..a4cf758 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/OcsApiTables.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/OcsApiTables.cs @@ -3,6 +3,7 @@ using Pilz.Networking.CloudProviders.Nextcloud.Ocs; using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -54,5 +55,15 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables { return Manager.MakeRequest(HttpMethod.Delete, OCS_TABLES_COLUMN.FillParameters(columnId)); } + + public Row? UpdateRow(long rowId, RowUpdate values) + { + return Manager.MakeRequest(HttpMethod.Put, OCS_TABLES_ROW.FillParameters(rowId), content: values); + } + + public Row? CreateRow(long tableId, RowUpdate values) + { + return Manager.MakeRequest(HttpMethod.Post, OCS_TABLES_TABLE_ROWS.FillParameters(tableId), content: values); + } } } diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/TablesClient.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/TablesClient.cs index d88fcd2..73626ec 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/TablesClient.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/TablesClient.cs @@ -57,5 +57,15 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables { return Client.Ocs.GetApi().DeleteColumn(columnId); } + + public Row? UpdateRow(long rowId, RowUpdate values) + { + return Client.Ocs.GetApi().UpdateRow(rowId, values); + } + + public Row? CreateRow(long tableId, RowUpdate values) + { + return Client.Ocs.GetApi().CreateRow(tableId, values); + } } } diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/ClientBase.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/ClientBase.cs index 7c32dad..059170c 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/Client/ClientBase.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/ClientBase.cs @@ -12,7 +12,7 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Client { protected NextcloudClient Client { get; init; } - public ClientBase(NextcloudClient client) + protected ClientBase(NextcloudClient client) { Client = client; } diff --git a/Pilz.Networking.CloudProviders.Nextcloud/NextcloudClient.cs b/Pilz.Networking.CloudProviders.Nextcloud/NextcloudClient.cs index 03d5a84..96e5b41 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/NextcloudClient.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/NextcloudClient.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using Pilz.Networking.CloudProviders.Nextcloud.Client; @@ -62,6 +63,11 @@ namespace Pilz.Networking.CloudProviders.Nextcloud } public UserInfo? Login(NextcloudLogin login) + { + return Login(login, true); + } + + public UserInfo? Login(NextcloudLogin login, bool checkUser) { // Ensure we are logged out Logout(false); @@ -69,15 +75,20 @@ namespace Pilz.Networking.CloudProviders.Nextcloud // Temporary set user login CurrentLogin = login; - // Try get user info & check if user is enabled - var userInfo = Cloud.GetUserInfo(); - var isValid = userInfo != null && userInfo.Enabled; + if (checkUser) + { + // Try get user info & check if user is enabled + var userInfo = Cloud.GetUserInfo(); + var isValid = userInfo != null && userInfo.Enabled; - // If invalid, reset login credentials - if (!isValid) - CurrentLogin = null; + // If invalid, reset login credentials + if (!isValid) + CurrentLogin = null; - return userInfo; + return userInfo; + } + + return null; } public NextcloudLogin? Login(string baseUrl, CancellationToken cancellationToken) diff --git a/Pilz.Networking.CloudProviders.Nextcloud/OCS/OcsApi.cs b/Pilz.Networking.CloudProviders.Nextcloud/OCS/OcsApi.cs index 77100ae..102bcbc 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/OCS/OcsApi.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/OCS/OcsApi.cs @@ -175,8 +175,11 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs // Create content if (content is HttpContent contentHttp) httpContent = contentHttp; - else if (content is OcsData) - httpContent = new StringContent(JsonConvert.SerializeObject(content), null, CONTENT_TYPE_JSON); + else if (content is OcsData || content is not null) + { + var stringContent = JsonConvert.SerializeObject(content); + httpContent = new StringContent(stringContent, null, CONTENT_TYPE_JSON); + } else httpContent = null; diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Pilz.Networking.CloudProviders.Nextcloud.csproj b/Pilz.Networking.CloudProviders.Nextcloud/Pilz.Networking.CloudProviders.Nextcloud.csproj index 4728de8..80355fe 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/Pilz.Networking.CloudProviders.Nextcloud.csproj +++ b/Pilz.Networking.CloudProviders.Nextcloud/Pilz.Networking.CloudProviders.Nextcloud.csproj @@ -9,7 +9,7 @@ True 1.yyyy.Mdd.Hmm - 1.2023.1002.1726 + 1.2023.1003.1124 diff --git a/Pilz.Networking.CloudProviders.Nextcloud/README.md b/Pilz.Networking.CloudProviders.Nextcloud/README.md new file mode 100644 index 0000000..fc23525 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/README.md @@ -0,0 +1 @@ +# Nextcloud Client Api