finish tables api

This commit is contained in:
2023-10-03 11:44:53 +02:00
parent 7ad077d0cf
commit ba069d56fd
8 changed files with 62 additions and 11 deletions

View File

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

View File

@@ -3,6 +3,7 @@ using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -54,5 +55,15 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables
{ {
return Manager.MakeRequest<Column>(HttpMethod.Delete, OCS_TABLES_COLUMN.FillParameters(columnId)); return Manager.MakeRequest<Column>(HttpMethod.Delete, OCS_TABLES_COLUMN.FillParameters(columnId));
} }
public Row? UpdateRow(long rowId, RowUpdate values)
{
return Manager.MakeRequest<Row>(HttpMethod.Put, OCS_TABLES_ROW.FillParameters(rowId), content: values);
}
public Row? CreateRow(long tableId, RowUpdate values)
{
return Manager.MakeRequest<Row>(HttpMethod.Post, OCS_TABLES_TABLE_ROWS.FillParameters(tableId), content: values);
}
} }
} }

View File

@@ -57,5 +57,15 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables
{ {
return Client.Ocs.GetApi<OcsApiTables>().DeleteColumn(columnId); return Client.Ocs.GetApi<OcsApiTables>().DeleteColumn(columnId);
} }
public Row? UpdateRow(long rowId, RowUpdate values)
{
return Client.Ocs.GetApi<OcsApiTables>().UpdateRow(rowId, values);
}
public Row? CreateRow(long tableId, RowUpdate values)
{
return Client.Ocs.GetApi<OcsApiTables>().CreateRow(tableId, values);
}
} }
} }

View File

@@ -12,7 +12,7 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Client
{ {
protected NextcloudClient Client { get; init; } protected NextcloudClient Client { get; init; }
public ClientBase(NextcloudClient client) protected ClientBase(NextcloudClient client)
{ {
Client = client; Client = client;
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Pilz.Networking.CloudProviders.Nextcloud.Client; using Pilz.Networking.CloudProviders.Nextcloud.Client;
@@ -62,6 +63,11 @@ namespace Pilz.Networking.CloudProviders.Nextcloud
} }
public UserInfo? Login(NextcloudLogin login) public UserInfo? Login(NextcloudLogin login)
{
return Login(login, true);
}
public UserInfo? Login(NextcloudLogin login, bool checkUser)
{ {
// Ensure we are logged out // Ensure we are logged out
Logout(false); Logout(false);
@@ -69,6 +75,8 @@ namespace Pilz.Networking.CloudProviders.Nextcloud
// Temporary set user login // Temporary set user login
CurrentLogin = login; CurrentLogin = login;
if (checkUser)
{
// Try get user info & check if user is enabled // Try get user info & check if user is enabled
var userInfo = Cloud.GetUserInfo(); var userInfo = Cloud.GetUserInfo();
var isValid = userInfo != null && userInfo.Enabled; var isValid = userInfo != null && userInfo.Enabled;
@@ -80,6 +88,9 @@ namespace Pilz.Networking.CloudProviders.Nextcloud
return userInfo; return userInfo;
} }
return null;
}
public NextcloudLogin? Login(string baseUrl, CancellationToken cancellationToken) public NextcloudLogin? Login(string baseUrl, CancellationToken cancellationToken)
{ {
// Ensure we are logged out // Ensure we are logged out

View File

@@ -175,8 +175,11 @@ namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs
// Create content // Create content
if (content is HttpContent contentHttp) if (content is HttpContent contentHttp)
httpContent = contentHttp; httpContent = contentHttp;
else if (content is OcsData) else if (content is OcsData || content is not null)
httpContent = new StringContent(JsonConvert.SerializeObject(content), null, CONTENT_TYPE_JSON); {
var stringContent = JsonConvert.SerializeObject(content);
httpContent = new StringContent(stringContent, null, CONTENT_TYPE_JSON);
}
else else
httpContent = null; httpContent = null;

View File

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

View File

@@ -0,0 +1 @@
# Nextcloud Client Api