diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/FileRetention/OcsApiFilesRetention.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/FileRetention/OcsApiFilesRetention.cs index 46ec563..215c839 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/FileRetention/OcsApiFilesRetention.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/FileRetention/OcsApiFilesRetention.cs @@ -1,6 +1,5 @@ using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs; using Pilz.Networking.CloudProviders.Nextcloud.Ocs; -using Pilz.Networking.CloudProviders.Nextcloud.OCS.Responses; using System; using System.Collections.Generic; using System.Data; diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Column.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Column.cs new file mode 100644 index 0000000..65921f4 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Column.cs @@ -0,0 +1,116 @@ +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 Column + { + [JsonProperty("type")] + private string? type; + + [JsonProperty("subtype")] + private string? subtype; + + [JsonProperty("id")] + public long ColumnId { get; set; } + + [JsonProperty("tableId")] + public long TableId { get; set; } + + [JsonProperty("title")] + public string? Title { get; set; } + + [JsonProperty("createdBy")] + public string? CreatedBy { get; set; } + + [JsonProperty("createdAt")] + public DateTime CreatedAt { get; set; } + + [JsonProperty("lastEditBy")] + public string? LastEditBy { get; set; } + + [JsonProperty("lastEditAt")] + public DateTime LastEditAt { get; set; } + + [JsonProperty("mandatory")] + public bool Mandatory { get; set; } + + [JsonProperty("description")] + public string? Description { get; set; } + + [JsonProperty("numberDefault")] + public float? NumberDefault { get; set; } + + [JsonProperty("numberMin")] + public float? NumberMin { get; set; } + + [JsonProperty("numberMax")] + public float? NumberMax { get; set; } + + [JsonProperty("numberDecimals")] + public float NumberDecimals { get; set; } + + [JsonProperty("numberPrefix")] + public string? NumberPrefix { get; set; } + + [JsonProperty("numberSuffix")] + public string? NumberSuffix { get; set; } + + [JsonProperty("textDefault")] + public string? TextDefault { get; set; } + + [JsonProperty("textAllowedPattern")] + public string? TextAllowedPattern { get; set; } + + [JsonProperty("textMaxLength")] + public int? TextMaxLength { get; set; } + + [JsonProperty("selectionOptions")] + public List SelectionOptions { get; } = new(); + + [JsonProperty("selectionDefault")] + public int? SelectionDefault { get; set; } + + [JsonProperty("datetimeDefault")] + public DateTime? DatetimeDefault { get; set; } + + [JsonIgnore] + public ColumnType Type + { + get => type switch + { + "text" => ColumnType.Text, + "selection" => ColumnType.Selection, + "datetime" => ColumnType.DateTime, + _ => ColumnType.Unknown, + }; + set => type = value switch + { + ColumnType.Text => "text", + ColumnType.Selection => "selection", + ColumnType.DateTime => "datetime", + _ => "text" + }; + } + + [JsonIgnore] + public ColumnSubtype Subtype + { + get => subtype switch + { + "line" => ColumnSubtype.Line, + "" => ColumnSubtype.None, + _ => ColumnSubtype.Unknown, + }; + set => subtype = value switch + { + ColumnSubtype.Line => "line", + _ => "" + }; + } + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnSelectionOption.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnSelectionOption.cs new file mode 100644 index 0000000..f3bcc89 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnSelectionOption.cs @@ -0,0 +1,18 @@ +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 ColumnSelectionOption + { + [JsonProperty("id")] + public long Id { get; set; } + + [JsonProperty("label")] + public string? Label { get; set; } + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnSubtype.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnSubtype.cs new file mode 100644 index 0000000..19a04e6 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnSubtype.cs @@ -0,0 +1,15 @@ +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 enum ColumnSubtype + { + None, + Unknown, + Line + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnType.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnType.cs new file mode 100644 index 0000000..1ec8a9b --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/ColumnType.cs @@ -0,0 +1,16 @@ +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 enum ColumnType + { + Unknown, + Text, + Selection, + DateTime + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Columns.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Columns.cs new file mode 100644 index 0000000..634b174 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Columns.cs @@ -0,0 +1,12 @@ +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 Columns : List + { + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Row.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Row.cs new file mode 100644 index 0000000..d1e3b13 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Row.cs @@ -0,0 +1,33 @@ +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 Row + { + [JsonProperty("id")] + public long RowId { get; set; } = -1; + + [JsonProperty("tableId")] + public long TableId { get; set; } = -1; + + [JsonProperty("createdBy")] + public string? CreatedBy { get; set; } + + [JsonProperty("createdAt")] + public DateTime CreatedAt { get; set; } + + [JsonProperty("lastEditBy")] + public string? LastEditBy { get; set; } + + [JsonProperty("lastEditAt")] + public DateTime LastEditAt { get; set; } + + [JsonProperty("data")] + public List Data { get; set; } = new(); + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowData.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowData.cs new file mode 100644 index 0000000..d44ba67 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowData.cs @@ -0,0 +1,18 @@ +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 RowData + { + [JsonProperty("columnId")] + public long ColumnId { get; set; } + + [JsonProperty("value")] + public object? Value { get; set; } + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowSimple.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowSimple.cs new file mode 100644 index 0000000..ed18a6c --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowSimple.cs @@ -0,0 +1,12 @@ +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 RowSimple : List + { + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Rows.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Rows.cs new file mode 100644 index 0000000..4286dd6 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/Rows.cs @@ -0,0 +1,12 @@ +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 Rows : List + { + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowsSimple.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowsSimple.cs new file mode 100644 index 0000000..b11d546 --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/Model/RowsSimple.cs @@ -0,0 +1,12 @@ +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 RowsSimple : List + { + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/OcsApiTables.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/OcsApiTables.cs new file mode 100644 index 0000000..ac1bdcb --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/OcsApiTables.cs @@ -0,0 +1,48 @@ +using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; +using Pilz.Networking.CloudProviders.Nextcloud.Ocs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables +{ + public class OcsApiTables : OcsApiBase + { + public static readonly OcsApiUrlPath OCS_TABLES_TABLE_ROWS = new("/apps/tables/api/1/tables/{0}/rows"); + public static readonly OcsApiUrlPath OCS_TABLES_TABLE_ROWS_SIMPLE = new("/apps/tables/api/1/tables/{0}/rows/simple"); + public static readonly OcsApiUrlPath OCS_TABLES_TABLE_COLUMNS = new("/apps/tables/api/1/tables/{0}/columns"); + public static readonly OcsApiUrlPath OCS_TABLES_ROW = new("/apps/tables/api/1/rows/{0}"); + public static readonly OcsApiUrlPath OCS_TABLES_COLUMN = new("/apps/tables/api/1/column/{0}"); + + public OcsApiTables(OcsApi manager) : base(manager) + { + } + + public RowsSimple? GetRowsSimple(long tableId) + { + return Manager.MakeRequest(HttpMethod.Get, OCS_TABLES_TABLE_ROWS_SIMPLE.FillParameters(tableId)); + } + + public Rows? GetRows(long tableId) + { + return Manager.MakeRequest(HttpMethod.Get, OCS_TABLES_TABLE_ROWS.FillParameters(tableId)); + } + + public Row? GetRow(long rowId) + { + return Manager.MakeRequest(HttpMethod.Get, OCS_TABLES_ROW.FillParameters(rowId)); + } + + public Columns? GetColumns(long tableId) + { + return Manager.MakeRequest(HttpMethod.Get, OCS_TABLES_TABLE_COLUMNS.FillParameters(tableId)); + } + + public Column? GetColumn(long columnId) + { + return Manager.MakeRequest(HttpMethod.Get, OCS_TABLES_COLUMN.FillParameters(columnId)); + } + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/TablesClient.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/TablesClient.cs new file mode 100644 index 0000000..4b2fdea --- /dev/null +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Apps/Tables/TablesClient.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables +{ + public class TablesClient : ClientBase + { + public TablesClient(NextcloudClient client) : base(client) + { + } + } +} diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/ClientBase.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/ClientBase.cs index 33cd7e0..f1c9d9b 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/Client/ClientBase.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/ClientBase.cs @@ -1,4 +1,6 @@ -using System; +using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables; +using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,5 +16,30 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Client { Client = client; } + + public RowsSimple? GetRowsSimple(long tableId) + { + return Client.Ocs.GetApi().GetRowsSimple(tableId); + } + + public Rows? GetRows(long tableId) + { + return Client.Ocs.GetApi().GetRows(tableId); + } + + public Row? GetRow(long rowId) + { + return Client.Ocs.GetApi().GetRow(rowId); + } + + public Columns? GetColumns(long tableId) + { + return Client.Ocs.GetApi().GetColumns(tableId); + } + + public Column? GetColumn(long columnId) + { + return Client.Ocs.GetApi().GetColumn(columnId); + } } } diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Client/Cloud/Model/UserInfo.cs b/Pilz.Networking.CloudProviders.Nextcloud/Client/Cloud/Model/UserInfo.cs index fecf7f9..7a7d1a8 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/Client/Cloud/Model/UserInfo.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/Client/Cloud/Model/UserInfo.cs @@ -99,7 +99,7 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model Enabled = Convert.ToBoolean(responseData.Enabled); StorageLocation = responseData.StorageLocation; ID = responseData.ID; - LastLogin = DateTimeOffset.FromUnixTimeMilliseconds(responseData.LastLogin ?? 0).LocalDateTime; + LastLogin = responseData.LastLogin.UnixTimeMillisecondsToDateTime(); Backend = responseData.Backend; Email = responseData.Email; Displayname = responseData.Displayname; diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Extensions.cs b/Pilz.Networking.CloudProviders.Nextcloud/Extensions.cs index 1b19d8b..dc687b4 100644 --- a/Pilz.Networking.CloudProviders.Nextcloud/Extensions.cs +++ b/Pilz.Networking.CloudProviders.Nextcloud/Extensions.cs @@ -32,5 +32,15 @@ namespace Pilz.Networking.CloudProviders.Nextcloud { return (OcsApiUrlPath)string.Format(path, @params); } + + public static DateTime UnixTimeMillisecondsToDateTime(this long? value) + { + return DateTimeOffset.FromUnixTimeMilliseconds(value ?? 0).DateTime; + } + + public static long ToUnixTimeMilliseconds(this DateTime value) + { + return new DateTimeOffset(value).ToUnixTimeMilliseconds(); + } } } diff --git a/Pilz.Networking.CloudProviders.Nextcloud/Pilz.Networking.CloudProviders.Nextcloud.csproj b/Pilz.Networking.CloudProviders.Nextcloud/Pilz.Networking.CloudProviders.Nextcloud.csproj index 8d2123e..4728de8 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.1538 + 1.2023.1002.1726