Skip to content

Commit

Permalink
Merge pull request #230 from PinguApps/226-create-base-for-users-api
Browse files Browse the repository at this point in the history
Created base for users api
  • Loading branch information
pingu2k4 authored Oct 5, 2024
2 parents cd0ff55 + 1d5f6ad commit 2bfdc38
Show file tree
Hide file tree
Showing 310 changed files with 6,515 additions and 274 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ string emailAddressOrErrorMessage = userResponse.Result.Match(
| [Get User](https://appwrite.io/docs/references/1.6.x/server-rest/users#get) |||
| [Delete User](https://appwrite.io/docs/references/1.6.x/server-rest/users#delete) |||
| [Update Email](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateEmail) |||
| [Create User JWT](https://appwrite.io/docs/references/1.6.x/server-rest/users#createJWT) |||
| [Update User Labels](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateLabels) |||
| [List User Logs](https://appwrite.io/docs/references/1.6.x/server-rest/users#listLogs) |||
| [List User Memberships](https://appwrite.io/docs/references/1.6.x/server-rest/users#listMemberships) |||
Expand Down
15 changes: 9 additions & 6 deletions src/PinguApps.Appwrite.Client/Clients/AccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
using PinguApps.Appwrite.Client.Internals;
using PinguApps.Appwrite.Client.Utils;
using PinguApps.Appwrite.Shared;
using PinguApps.Appwrite.Shared.Requests;
using PinguApps.Appwrite.Shared.Requests.Account;
using PinguApps.Appwrite.Shared.Responses;
using PinguApps.Appwrite.Shared.Utils;

namespace PinguApps.Appwrite.Client;

Expand Down Expand Up @@ -97,11 +96,13 @@ public async Task<AppwriteResult<User>> UpdateEmail(UpdateEmailRequest request)
}

/// <inheritdoc/>
public async Task<AppwriteResult<IdentitiesList>> ListIdentities(List<Query>? queries = null)
public async Task<AppwriteResult<IdentitiesList>> ListIdentities(ListIdentitiesRequest request)
{
try
{
var queryStrings = queries?.Select(x => x.GetQueryString()) ?? [];
request.Validate(true);

var queryStrings = request.Queries?.Select(x => x.GetQueryString()) ?? [];

var result = await _accountApi.ListIdentities(GetCurrentSessionOrThrow(), queryStrings);

Expand Down Expand Up @@ -146,11 +147,13 @@ public async Task<AppwriteResult<Jwt>> CreateJwt()
}

/// <inheritdoc/>
public async Task<AppwriteResult<LogsList>> ListLogs(List<Query>? queries = null)
public async Task<AppwriteResult<LogsList>> ListLogs(ListLogsRequest request)
{
try
{
var queryStrings = queries?.Select(x => x.GetQueryString()) ?? [];
request.Validate(true);

var queryStrings = request.Queries?.Select(x => x.GetQueryString()) ?? [];

var result = await _accountApi.ListLogs(GetCurrentSessionOrThrow(), queryStrings);

Expand Down
7 changes: 3 additions & 4 deletions src/PinguApps.Appwrite.Client/Clients/IAccountClient.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using PinguApps.Appwrite.Shared;
using PinguApps.Appwrite.Shared.Requests;
using PinguApps.Appwrite.Shared.Requests.Account;
using PinguApps.Appwrite.Shared.Responses;
using PinguApps.Appwrite.Shared.Utils;

namespace PinguApps.Appwrite.Client;

Expand Down Expand Up @@ -44,7 +43,7 @@ public interface IAccountClient
/// </summary>
/// <param name="queries">Array of query strings generated using the Query class provided by the SDK. <see href="https://appwrite.io/docs/queries">Learn more about queries</see>. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: <c>userId</c>, <c>provider</c>, <c>providerUid</c>, <c>providerEmail</c>, <c>providerAccessTokenExpiry</c></param>
/// <returns>The Identities List</returns>
Task<AppwriteResult<IdentitiesList>> ListIdentities(List<Query>? queries = null);
Task<AppwriteResult<IdentitiesList>> ListIdentities(ListIdentitiesRequest request);

/// <summary>
/// Delete an identity by its unique ID
Expand All @@ -67,7 +66,7 @@ public interface IAccountClient
/// </summary>
/// <param name="queries">Array of query strings generated using the Query class provided by the SDK. <see href="https://appwrite.io/docs/queries">Learn more about queries</see>. Only supported methods are limit and offset</param>
/// <returns>The Logs List</returns>
Task<AppwriteResult<LogsList>> ListLogs(List<Query>? queries = null);
Task<AppwriteResult<LogsList>> ListLogs(ListLogsRequest request);

/// <summary>
/// Enable or disable MFA on an account
Expand Down
5 changes: 3 additions & 2 deletions src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using PinguApps.Appwrite.Shared;

namespace PinguApps.Appwrite.Client.Handlers;
internal class HeaderHandler : DelegatingHandler
{
private readonly string _projectId;

public HeaderHandler(string projectId)
public HeaderHandler(Config config)
{
_projectId = projectId;
_projectId = config.ProjectId;
}

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion src/PinguApps.Appwrite.Client/Internals/IAccountApi.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using PinguApps.Appwrite.Shared.Requests;
using PinguApps.Appwrite.Shared.Requests.Account;
using PinguApps.Appwrite.Shared.Responses;
using Refit;

Expand Down
12 changes: 5 additions & 7 deletions src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ public static class ServiceCollectionExtensions
/// <returns>The service collection, enabling chaining</returns>
public static IServiceCollection AddAppwriteClient(this IServiceCollection services, string projectId, string endpoint = "https://cloud.appwrite.io/v1", RefitSettings? refitSettings = null)
{
services.AddSingleton(x => new HeaderHandler(projectId));
services.AddSingleton<ClientCookieSessionHandler>();
services.AddSingleton(new Config(endpoint, projectId));
services.AddTransient<HeaderHandler>();
services.AddTransient<ClientCookieSessionHandler>();

services.AddRefitClient<IAccountApi>(refitSettings)
.ConfigureHttpClient(x => x.BaseAddress = new Uri(endpoint))
.AddHttpMessageHandler<HeaderHandler>()
.AddHttpMessageHandler<ClientCookieSessionHandler>();

services.AddSingleton(new Config(endpoint, projectId));

services.AddSingleton<IAccountClient, AccountClient>();
services.AddSingleton<IAppwriteClient, AppwriteClient>();
services.AddSingleton(x => new Lazy<IAppwriteClient>(() => x.GetRequiredService<IAppwriteClient>()));
Expand All @@ -50,7 +49,8 @@ public static IServiceCollection AddAppwriteClient(this IServiceCollection servi
/// <returns>The service collection, enabling chaining</returns>
public static IServiceCollection AddAppwriteClientForServer(this IServiceCollection services, string projectId, string endpoint = "https://cloud.appwrite.io/v1", RefitSettings? refitSettings = null)
{
services.AddSingleton(sp => new HeaderHandler(projectId));
services.AddSingleton(new Config(endpoint, projectId));
services.AddTransient<HeaderHandler>();

services.AddRefitClient<IAccountApi>(refitSettings)
.ConfigureHttpClient(x => x.BaseAddress = new Uri(endpoint))
Expand All @@ -63,8 +63,6 @@ public static IServiceCollection AddAppwriteClientForServer(this IServiceCollect
}
});

services.AddSingleton(new Config(endpoint, projectId));

services.AddSingleton<IAccountClient, AccountClient>();
services.AddSingleton<IAppwriteClient, AppwriteClient>();

Expand Down
13 changes: 4 additions & 9 deletions src/PinguApps.Appwrite.Playground/App.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using Microsoft.Extensions.Configuration;
using PinguApps.Appwrite.Client;
using PinguApps.Appwrite.Server.Servers;
using PinguApps.Appwrite.Shared.Requests;
using PinguApps.Appwrite.Shared.Requests.Account;

namespace PinguApps.Appwrite.Playground;
internal class App
{
private readonly IAppwriteClient _client;
private readonly IAppwriteServer _server;
private readonly Client.IAppwriteClient _client;
private readonly Server.Clients.IAppwriteClient _server;
private readonly string? _session;

public App(IAppwriteClient client, IAppwriteServer server, IConfiguration config)
public App(Client.IAppwriteClient client, Server.Clients.IAppwriteClient server, IConfiguration config)
{
_client = client;
_server = server;
Expand All @@ -19,9 +17,6 @@ public App(IAppwriteClient client, IAppwriteServer server, IConfiguration config

public async Task Run(string[] args)
{
_client.SetSession(_session);

//var response = await _client.Account.CreatePhoneVerification();
var response = await _client.Account.UpdatePhoneVerificationConfirmation(new UpdatePhoneVerificationConfirmationRequest
{
UserId = "664aac1a00113f82e620",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
using PinguApps.Appwrite.Server.Internals;
using PinguApps.Appwrite.Server.Utils;
using PinguApps.Appwrite.Shared;
using PinguApps.Appwrite.Shared.Requests;
using PinguApps.Appwrite.Shared.Requests.Account;
using PinguApps.Appwrite.Shared.Responses;

namespace PinguApps.Appwrite.Server.Servers;
public class AccountServer : IAccountServer
namespace PinguApps.Appwrite.Server.Clients;
public class AccountClient : IAccountClient
{
private readonly IAccountApi _accountApi;

private readonly Config _config;

public AccountServer(IServiceProvider services, Config config)
public AccountClient(IServiceProvider services, Config config)
{
_accountApi = services.GetRequiredService<IAccountApi>();
_config = config;
Expand Down
12 changes: 12 additions & 0 deletions src/PinguApps.Appwrite.Server/Clients/AppwriteClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace PinguApps.Appwrite.Server.Clients;
public class AppwriteClient : IAppwriteClient
{
public IAccountClient Account { get; }
public IUsersClient Users { get; }

public AppwriteClient(IAccountClient accountClient, IUsersClient usersClient)
{
Account = accountClient;
Users = usersClient;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System.Threading.Tasks;
using PinguApps.Appwrite.Shared;
using PinguApps.Appwrite.Shared.Requests;
using PinguApps.Appwrite.Shared.Requests.Account;
using PinguApps.Appwrite.Shared.Responses;

namespace PinguApps.Appwrite.Server.Servers;
namespace PinguApps.Appwrite.Server.Clients;

/// <summary>
/// <para>The Account service allows you to authenticate and manage a user account. You can use the account service to update user information, retrieve the user sessions across different devices, and fetch the user security logs with his or her recent activity.</para>
/// <para>Register new user accounts with the Create Account, Create Magic URL session, or Create Phone session endpoint.You can authenticate the user account by using multiple sign-in methods available.Once the user is authenticated, a new session object will be created to allow the user to access his or her private data and settings.</para>
/// <para>This service also exposes an endpoint to save and read the user preferences as a key-value object. This feature is handy if you want to allow extra customization in your app.Common usage for this feature may include saving the user's preferred locale, timezone, or custom app theme.</para>
/// <para><see href="https://appwrite.io/docs/references/1.6.x/server-rest/account">Appwrite Docs</see></para>
/// </summary>
public interface IAccountServer
public interface IAccountClient
{
/// <summary>
/// Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the /account/verfication route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new account session.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
namespace PinguApps.Appwrite.Server.Servers;
namespace PinguApps.Appwrite.Server.Clients;

/// <summary>
/// The root of the Client SDK. Access all API sections from here
/// </summary>
public interface IAppwriteServer
public interface IAppwriteClient
{
/// <summary>
/// <para>The Account service allows you to authenticate and manage a user account. You can use the account service to update user information, retrieve the user sessions across different devices, and fetch the user security logs with his or her recent activity.</para>
/// <para>Register new user accounts with the Create Account, Create Magic URL session, or Create Phone session endpoint.You can authenticate the user account by using multiple sign-in methods available.Once the user is authenticated, a new session object will be created to allow the user to access his or her private data and settings.</para>
/// <para>This service also exposes an endpoint to save and read the user preferences as a key-value object. This feature is handy if you want to allow extra customization in your app.Common usage for this feature may include saving the user's preferred locale, timezone, or custom app theme.</para>
/// <para><see href="https://appwrite.io/docs/references/1.6.x/server-rest/account">Appwrite Docs</see></para>
/// </summary>
IAccountServer Account { get; }
IAccountClient Account { get; }

/// <summary>
/// The Users service allows you to manage your project users. Use this service to search, block, and view your users' info, current sessions, and latest activity logs. You can also use the Users service to edit your users' preferences and personal info.
/// <para><see href="https://appwrite.io/docs/references/1.6.x/server-rest/users">Appwrite Docs</see></para>
/// </summary>
IUsersClient Users { get; }
}
Loading

0 comments on commit 2bfdc38

Please sign in to comment.