begin implementing Tables API

This commit is contained in:
2023-10-02 17:28:41 +02:00
parent 459660c35a
commit 549d284c54
17 changed files with 367 additions and 4 deletions

View File

@@ -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;

View File

@@ -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<ColumnSelectionOption> 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",
_ => ""
};
}
}
}

View File

@@ -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; }
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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<Column>
{
}
}

View File

@@ -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<RowData> Data { get; set; } = new();
}
}

View File

@@ -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; }
}
}

View File

@@ -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<object>
{
}
}

View File

@@ -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<Row>
{
}
}

View File

@@ -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<RowSimple>
{
}
}

View File

@@ -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<RowsSimple>(HttpMethod.Get, OCS_TABLES_TABLE_ROWS_SIMPLE.FillParameters(tableId));
}
public Rows? GetRows(long tableId)
{
return Manager.MakeRequest<Rows>(HttpMethod.Get, OCS_TABLES_TABLE_ROWS.FillParameters(tableId));
}
public Row? GetRow(long rowId)
{
return Manager.MakeRequest<Row>(HttpMethod.Get, OCS_TABLES_ROW.FillParameters(rowId));
}
public Columns? GetColumns(long tableId)
{
return Manager.MakeRequest<Columns>(HttpMethod.Get, OCS_TABLES_TABLE_COLUMNS.FillParameters(tableId));
}
public Column? GetColumn(long columnId)
{
return Manager.MakeRequest<Column>(HttpMethod.Get, OCS_TABLES_COLUMN.FillParameters(columnId));
}
}
}

View File

@@ -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)
{
}
}
}

View File

@@ -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<OcsApiTables>().GetRowsSimple(tableId);
}
public Rows? GetRows(long tableId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetRows(tableId);
}
public Row? GetRow(long rowId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetRow(rowId);
}
public Columns? GetColumns(long tableId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetColumns(tableId);
}
public Column? GetColumn(long columnId)
{
return Client.Ocs.GetApi<OcsApiTables>().GetColumn(columnId);
}
}
}

View File

@@ -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;

View File

@@ -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();
}
}
}

View File

@@ -9,7 +9,7 @@
<PropertyGroup>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<IncrementVersionOnBuild>1.yyyy.Mdd.Hmm</IncrementVersionOnBuild>
<Version>1.2023.1002.1538</Version>
<Version>1.2023.1002.1726</Version>
</PropertyGroup>
<ItemGroup>