Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented all documents endpoints #557

Merged
merged 22 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
64a05e4
Implemented List Documents
pingu2k4 Dec 7, 2024
d79b5ee
added server tests for list documents
pingu2k4 Dec 8, 2024
fe431be
Ensured that client operations don't require a login, but will pass i…
pingu2k4 Dec 8, 2024
3321755
added tests for client List Documents
pingu2k4 Dec 8, 2024
dfebe32
Added WithData to CreateDocumentRequiestBuilder
pingu2k4 Dec 9, 2024
6a73ee8
Implemented CreateDocument (untested)
pingu2k4 Dec 9, 2024
663ca32
Update App.cs
pingu2k4 Dec 10, 2024
2c07a4f
Completed manual testing of CreateDocument
pingu2k4 Dec 10, 2024
33ab94a
Added extra xml docs to instruct user on how to create a create docum…
pingu2k4 Dec 10, 2024
596a77e
Added tests for create document
pingu2k4 Dec 10, 2024
f301803
Updated tests that were missing WithJsonContent
pingu2k4 Dec 10, 2024
3735cd4
Implemented delete document
pingu2k4 Dec 10, 2024
766d117
added tests for delete document
pingu2k4 Dec 10, 2024
599eb45
Implemented GetDocument and made chances to support query limiting th…
pingu2k4 Dec 10, 2024
7c5b761
Fixed failing tests for Document
pingu2k4 Dec 10, 2024
dc6d9cd
added tests for get document
pingu2k4 Dec 10, 2024
0041e2b
Removed unused variable from some tests
pingu2k4 Dec 10, 2024
8a282db
Implemented Update Document
pingu2k4 Dec 10, 2024
0c86908
Testing the before / after builder pattern for update document
pingu2k4 Dec 10, 2024
0f600e8
added tests for update document
pingu2k4 Dec 10, 2024
c3202a7
Added tests to each documents client method, to check that when neede…
pingu2k4 Dec 10, 2024
7cb674e
Update README.md
pingu2k4 Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ string emailAddressOrErrorMessage = userResponse.Result.Match(

## ⌛ Progress
<!-- `red` for first third, `gold` for second third, `forestgreen` for final third, `blue` for 100% -->
![Server & Client - 162 / 317](https://img.shields.io/badge/Server_&_Client-162%20%2F%20317-gold?style=for-the-badge)
![Server & Client - 172 / 317](https://img.shields.io/badge/Server_&_Client-172%20%2F%20317-gold?style=for-the-badge)

![Server - 102 / 224](https://img.shields.io/badge/Server-102%20%2F%20224-gold?style=for-the-badge)
![Server - 107 / 224](https://img.shields.io/badge/Server-107%20%2F%20224-gold?style=for-the-badge)

![Client - 60 / 93](https://img.shields.io/badge/Client-60%20%2F%2093-gold?style=for-the-badge)
![Client - 65 / 93](https://img.shields.io/badge/Client-65%20%2F%2093-forestgreen?style=for-the-badge)

### 🔑 Key
| Icon | Definition |
Expand Down Expand Up @@ -275,7 +275,7 @@ string emailAddressOrErrorMessage = userResponse.Result.Match(
| [Update Preferences](https://appwrite.io/docs/references/1.6.x/client-rest/teams#updatePrefs) |||

### Databases
![Databases - 37 / 47](https://img.shields.io/badge/Databases-37%20%2F%2047-forestgreen?style=for-the-badge)
![Databases - 47 / 47](https://img.shields.io/badge/Databases-47%20%2F%2047-blue?style=for-the-badge)

| Endpoint | Client | Server |
|:-:|:-:|:-:|
Expand Down Expand Up @@ -312,11 +312,11 @@ string emailAddressOrErrorMessage = userResponse.Result.Match(
| [Get Attribute](https://appwrite.io/docs/references/1.6.x/server-rest/databases#getAttribute) |||
| [Delete Attribute](https://appwrite.io/docs/references/1.6.x/server-rest/databases#deleteAttribute) |||
| [Update Relationship Attribute](https://appwrite.io/docs/references/1.6.x/server-rest/databases#updateRelationshipAttribute) |||
| [List Documents](https://appwrite.io/docs/references/1.6.x/client-rest/databases#listDocuments) | | |
| [Create Document](https://appwrite.io/docs/references/1.6.x/client-rest/databases#createDocument) | | |
| [Get Document](https://appwrite.io/docs/references/1.6.x/client-rest/databases#getDocument) | | |
| [Update Document](https://appwrite.io/docs/references/1.6.x/client-rest/databases#updateDocument) | | |
| [Delete Document](https://appwrite.io/docs/references/1.6.x/client-rest/databases#deleteDocument) | | |
| [List Documents](https://appwrite.io/docs/references/1.6.x/client-rest/databases#listDocuments) | | |
| [Create Document](https://appwrite.io/docs/references/1.6.x/client-rest/databases#createDocument) | | |
| [Get Document](https://appwrite.io/docs/references/1.6.x/client-rest/databases#getDocument) | | |
| [Update Document](https://appwrite.io/docs/references/1.6.x/client-rest/databases#updateDocument) | | |
| [Delete Document](https://appwrite.io/docs/references/1.6.x/client-rest/databases#deleteDocument) | | |
| [List Indexes](https://appwrite.io/docs/references/1.6.x/server-rest/databases#listIndexes) |||
| [Create Index](https://appwrite.io/docs/references/1.6.x/server-rest/databases#createIndex) |||
| [Get Index](https://appwrite.io/docs/references/1.6.x/server-rest/databases#getIndex) |||
Expand Down
87 changes: 76 additions & 11 deletions src/PinguApps.Appwrite.Client/Clients/DatabasesClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using PinguApps.Appwrite.Client.Internals;
using PinguApps.Appwrite.Client.Utils;
using PinguApps.Appwrite.Shared;
using PinguApps.Appwrite.Shared.Requests.Databases;
using PinguApps.Appwrite.Shared.Responses;
Expand All @@ -18,23 +18,88 @@ internal DatabasesClient(IDatabasesApi databasesApi)
_databasesApi = databasesApi;
}

[ExcludeFromCodeCoverage]
/// <inheritdoc/>
public Task<AppwriteResult<DocumentsList>> ListDocuments(ListDocumentsRequest request) => throw new NotImplementedException();
public async Task<AppwriteResult<DocumentsList>> ListDocuments(ListDocumentsRequest request)
{
try
{
request.Validate(true);

var result = await _databasesApi.ListDocuments(GetCurrentSession(), request.DatabaseId, request.CollectionId, RequestUtils.GetQueryStrings(request.Queries));

return result.GetApiResponse();
}
catch (Exception e)
{
return e.GetExceptionResponse<DocumentsList>();
}
}

[ExcludeFromCodeCoverage]
/// <inheritdoc/>
public Task<AppwriteResult<Document>> CreateDocument(CreateDocumentRequest request) => throw new NotImplementedException();
public async Task<AppwriteResult<Document>> CreateDocument(CreateDocumentRequest request)
{
try
{
request.Validate(true);

var result = await _databasesApi.CreateDocument(GetCurrentSession(), request.DatabaseId, request.CollectionId, request);

return result.GetApiResponse();
}
catch (Exception e)
{
return e.GetExceptionResponse<Document>();
}
}

[ExcludeFromCodeCoverage]
/// <inheritdoc/>
public Task<AppwriteResult> DeleteDocument(DeleteDocumentRequest request) => throw new NotImplementedException();
public async Task<AppwriteResult> DeleteDocument(DeleteDocumentRequest request)
{
try
{
request.Validate(true);

var result = await _databasesApi.DeleteDocument(GetCurrentSession(), request.DatabaseId, request.CollectionId, request.DocumentId);

return result.GetApiResponse();
}
catch (Exception e)
{
return e.GetExceptionResponse();
}
}

[ExcludeFromCodeCoverage]
/// <inheritdoc/>
public Task<AppwriteResult<Document>> GetDocument(GetDocumentRequest request) => throw new NotImplementedException();
public async Task<AppwriteResult<Document>> GetDocument(GetDocumentRequest request)
{
try
{
request.Validate(true);

var result = await _databasesApi.GetDocument(GetCurrentSession(), request.DatabaseId, request.CollectionId, request.DocumentId, RequestUtils.GetQueryStrings(request.Queries));

return result.GetApiResponse();
}
catch (Exception e)
{
return e.GetExceptionResponse<Document>();
}
}

[ExcludeFromCodeCoverage]
/// <inheritdoc/>
public Task<AppwriteResult<Document>> UpdateDocument(UpdateDocumentRequest request) => throw new NotImplementedException();
public async Task<AppwriteResult<Document>> UpdateDocument(UpdateDocumentRequest request)
{
try
{
request.Validate(true);

var result = await _databasesApi.UpdateDocument(GetCurrentSession(), request.DatabaseId, request.CollectionId, request.DocumentId, request);

return result.GetApiResponse();
}
catch (Exception e)
{
return e.GetExceptionResponse<Document>();
}
}
}
44 changes: 34 additions & 10 deletions src/PinguApps.Appwrite.Client/Clients/IDatabasesClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using PinguApps.Appwrite.Shared;
using PinguApps.Appwrite.Shared.Requests.Databases;
using PinguApps.Appwrite.Shared.Responses;
Expand All @@ -11,22 +10,47 @@ namespace PinguApps.Appwrite.Client.Clients;
/// <para>All data returned by the Databases service are represented as structured JSON documents.</para>
/// <para>The Databases service can contain multiple databases, each database can contain multiple collections. A collection is a group of similarly structured documents. The accepted structure of documents is defined by <see href="https://appwrite.io/docs/products/databases/collections#attributes">collection attributes</see>. The collection attributes help you ensure all your user-submitted data is validated and stored according to the collection structure.</para>
/// <para>Using Appwrite permissions architecture, you can assign read or write access to each collection or document in your project for either a specific user, team, user role, or even grant it with public access (any). You can learn more about <see href="https://appwrite.io/docs/products/databases/permissions">how Appwrite handles permissions and access control</see>.</para>
/// <para><see href="https://appwrite.io/docs/references/1.6.x/server-rest/databases">Appwrite Docs</see></para>
/// <para><see href="https://appwrite.io/docs/references/1.6.x/client-rest/databases">Appwrite Docs</see></para>
/// </summary>
public interface IDatabasesClient
{
[Obsolete("Endpoint not yet implemented.")]
/// <summary>
/// Get a list of all the user's documents in a given collection. You can use the query params to filter your results.
/// <para><see href="https://appwrite.io/docs/references/cloud/client-rest/databases#listDocuments">Appwrite Docs</see></para>
/// </summary>
/// <param name="request">The request content</param>
/// <returns>The documents list</returns>
Task<AppwriteResult<DocumentsList>> ListDocuments(ListDocumentsRequest request);

/// <summary>
/// Create a new Document. Before using this route, you should create a new collection resource using either a <see href="https://appwrite.io/docs/server/databases#databasesCreateCollection">server integration</see> API or directly from your database console.
/// <para><see href="https://appwrite.io/docs/references/cloud/client-rest/databases#createDocument">Appwrite Docs</see></para>
/// </summary>
/// <param name="request">The request content</param>
/// <returns>The document</returns>
Task<AppwriteResult<Document>> CreateDocument(CreateDocumentRequest request);

[Obsolete("Endpoint not yet implemented.")]
/// <summary>
/// Delete a document by its unique ID.
/// <para><see href="https://appwrite.io/docs/references/cloud/client-rest/databases#deleteDocument">Appwrite Docs</see></para>
/// </summary>
/// <param name="request">The request content</param>
/// <returns>204 Success Code</returns>
Task<AppwriteResult> DeleteDocument(DeleteDocumentRequest request);

[Obsolete("Endpoint not yet implemented.")]
/// <summary>
/// Get a document by its unique ID. This endpoint response returns a JSON object with the document data. You can return select columns by passing in a Select query.
/// <para><see href="https://appwrite.io/docs/references/cloud/client-rest/databases#getDocument">Appwrite Docs</see></para>
/// </summary>
/// <param name="request">The request content</param>
/// <returns>The document</returns>
Task<AppwriteResult<Document>> GetDocument(GetDocumentRequest request);

[Obsolete("Endpoint not yet implemented.")]
Task<AppwriteResult<DocumentsList>> ListDocuments(ListDocumentsRequest request);

[Obsolete("Endpoint not yet implemented.")]
/// <summary>
/// Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.
/// <para><see href="https://appwrite.io/docs/references/cloud/client-rest/databases#updateDocument">Appwrite Docs</see></para>
/// </summary>
/// <param name="request">The request content</param>
/// <returns>The document</returns>
Task<AppwriteResult<Document>> UpdateDocument(UpdateDocumentRequest request);
}
10 changes: 5 additions & 5 deletions src/PinguApps.Appwrite.Client/Internals/IDatabasesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ internal interface IDatabasesApi : IBaseApi
{
[Get("/databases/{databaseId}/collections/{collectionId}/documents")]
[QueryUriFormat(UriFormat.Unescaped)]
Task<IApiResponse<DocumentsList>> ListDocuments(string databaseId, string collectionId, [Query(CollectionFormat.Multi), AliasAs("queries[]")] IEnumerable<string> queries);
Task<IApiResponse<DocumentsList>> ListDocuments([Header("x-appwrite-session")] string? session, string databaseId, string collectionId, [Query(CollectionFormat.Multi), AliasAs("queries[]")] IEnumerable<string> queries);

[Post("/databases/{databaseId}/collections/{collectionId}/documents")]
Task<IApiResponse<Document>> CreateDocument(string databaseId, string collectionId, CreateDocumentRequest request);
Task<IApiResponse<Document>> CreateDocument([Header("x-appwrite-session")] string? session, string databaseId, string collectionId, CreateDocumentRequest request);

[Delete("/databases/{databaseId}/collections/{collectionId}/documents/{documentId}")]
Task<IApiResponse> DeleteDocument(string databaseId, string collectionId, string documentId);
Task<IApiResponse> DeleteDocument([Header("x-appwrite-session")] string? session, string databaseId, string collectionId, string documentId);

[Get("/databases/{databaseId}/collections/{collectionId}/documents/{documentId}")]
[QueryUriFormat(UriFormat.Unescaped)]
Task<IApiResponse<Document>> GetDocument(string databaseId, string collectionId, string documentId, [Query(CollectionFormat.Multi), AliasAs("queries[]")] IEnumerable<string> queries);
Task<IApiResponse<Document>> GetDocument([Header("x-appwrite-session")] string? session, string databaseId, string collectionId, string documentId, [Query(CollectionFormat.Multi), AliasAs("queries[]")] IEnumerable<string> queries);

[Patch("/databases/{databaseId}/collections/{collectionId}/documents/{documentId}")]
Task<IApiResponse<Document>> UpdateDocument(string databaseId, string collectionId, string documentId, UpdateDocumentRequest request);
Task<IApiResponse<Document>> UpdateDocument([Header("x-appwrite-session")] string? session, string databaseId, string collectionId, string documentId, UpdateDocumentRequest request);
}
43 changes: 34 additions & 9 deletions src/PinguApps.Appwrite.Playground/App.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Configuration;
using PinguApps.Appwrite.Shared.Requests.Databases;

namespace PinguApps.Appwrite.Playground;
Expand All @@ -15,20 +16,44 @@ public App(Client.IAppwriteClient client, Server.Clients.IAppwriteClient server,
_session = config.GetValue<string>("Session");
}

private class Rec
{
[JsonPropertyName("test")]
public string Test { get; set; } = string.Empty;

[JsonPropertyName("boolAttribute")]
public bool BoolAttribute { get; set; }
}

public async Task Run(string[] args)
{
var request = new GetIndexRequest()
{
DatabaseId = "6748b44d000b2b0e73ac",
CollectionId = "6748bb30002a12d4708f",
Key = "index_1"
};
var before = new Rec { Test = "test", BoolAttribute = false };
var after = new Rec { Test = "test", BoolAttribute = true };

var request = UpdateDocumentRequest.CreateBuilder()
.WithDatabaseId("67541a2800221703e717")
.WithCollectionId("67541a37001514b81821")
.WithDocumentId("67541af9000055e59e59")
.WithChanges(before, after)
.Build();

var response = await _server.Databases.GetIndex(request);
var serverResponse = await _server.Databases.UpdateDocument(request);

Console.WriteLine(response.Result.Match(
Console.WriteLine(serverResponse.Result.Match(
result => result.ToString(),
appwriteError => appwriteError.Message,
internalError => internalError.Message));

Console.WriteLine("###############################################################################");

//Console.ReadKey();
//request.Data["test"] = "Client Update";

//var clientResponse = await _client.Databases.UpdateDocument(request);

//Console.WriteLine(clientResponse.Result.Match(
// result => result.ToString(),
// appwriteError => appwriteError.Message,
// internalError => internalError.Message));
}
}
Loading
Loading