diff --git a/README.md b/README.md
index 34a36706..b41e2ba0 100644
--- a/README.md
+++ b/README.md
@@ -140,10 +140,10 @@ string emailAddressOrErrorMessage = userResponse.Result.Match(
```
## ⌛ Progress
-
-![Server & Client - 93 / 291](https://img.shields.io/badge/Server_&_Client-93%20%2F%20291-red?style=for-the-badge)
+
+![Server & Client - 94 / 291](https://img.shields.io/badge/Server_&_Client-94%20%2F%20291-red?style=for-the-badge)
-![Server - 49 / 201](https://img.shields.io/badge/Server-49%20%2F%20201-red?style=for-the-badge)
+![Server - 50 / 201](https://img.shields.io/badge/Server-50%20%2F%20201-red?style=for-the-badge)
![Client - 44 / 90](https://img.shields.io/badge/Client-44%20%2F%2090-gold?style=for-the-badge)
@@ -155,7 +155,7 @@ string emailAddressOrErrorMessage = userResponse.Result.Match(
| ❌ | There is currently no intention to implement the endpoint for the given SDK type (client or server) |
### Account
-![Account - 55 / 55](https://img.shields.io/badge/Account-55%20%2F%2055-forestgreen?style=for-the-badge)
+![Account - 55 / 55](https://img.shields.io/badge/Account-55%20%2F%2055-blue?style=for-the-badge)
| Endpoint | Client | Server | Notes |
|:-:|:-:|:-:|:-:|
@@ -208,7 +208,7 @@ string emailAddressOrErrorMessage = userResponse.Result.Match(
| [Create Phone Verification (Confirmation)](https://appwrite.io/docs/references/1.6.x/client-rest/account#updatePhoneVerification) | ✅ | ❌ | |
### Users
-![Account - 38 / 41](https://img.shields.io/badge/Users-38%20%2F%2041-forestgreen?style=for-the-badge)
+![Account - 39 / 41](https://img.shields.io/badge/Users-39%20%2F%2041-forestgreen?style=for-the-badge)
| Endpoint | Client | Server |
|:-:|:-:|:-:|
@@ -249,7 +249,7 @@ string emailAddressOrErrorMessage = userResponse.Result.Match(
| [List User Targets](https://appwrite.io/docs/references/1.6.x/server-rest/users#listTargets) | ❌ | ✅ |
| [Create User Target](https://appwrite.io/docs/references/1.6.x/server-rest/users#createTarget) | ❌ | ✅ |
| [Get User Target](https://appwrite.io/docs/references/1.6.x/server-rest/users#getTarget) | ❌ | ✅ |
-| [Update User Target](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateTarget) | ❌ | ⬛ |
+| [Update User Target](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateTarget) | ❌ | ✅ |
| [Delete User Target](https://appwrite.io/docs/references/1.6.x/server-rest/users#deleteTarget) | ❌ | ✅ |
| [Create Token](https://appwrite.io/docs/references/1.6.x/server-rest/users#createToken) | ❌ | ⬛ |
| [Update Email Verification](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateEmailVerification) | ❌ | ⬛ |
diff --git a/src/PinguApps.Appwrite.Playground/App.cs b/src/PinguApps.Appwrite.Playground/App.cs
index 8acb9a89..7e13d69e 100644
--- a/src/PinguApps.Appwrite.Playground/App.cs
+++ b/src/PinguApps.Appwrite.Playground/App.cs
@@ -17,13 +17,14 @@ public App(Client.IAppwriteClient client, Server.Clients.IAppwriteClient server,
public async Task Run(string[] args)
{
- var request = new GetUserTargetRequest()
+ var request = new UpdateUserTargertRequest()
{
UserId = "664aac1a00113f82e620",
- TargetId = "def"
+ TargetId = "def",
+ Name = "New Name"
};
- var response = await _server.Users.GetUserTarget(request);
+ var response = await _server.Users.UpdateUserTarget(request);
Console.WriteLine(response.Result.Match(
result => result.ToString(),
diff --git a/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs b/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs
index d1c8dc0c..80953898 100644
--- a/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs
+++ b/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs
@@ -318,7 +318,13 @@ public interface IUsersClient
/// The request content
/// The target
Task> GetUserTarget(GetUserTargetRequest request);
- [Obsolete("This method hasn't yet been implemented.", true)]
+
+ ///
+ /// Update a messaging target
+ /// Appwrite Docs
+ ///
+ /// The request content
+ /// The target
Task> UpdateUserTarget(UpdateUserTargertRequest request);
[Obsolete("This method hasn't yet been implemented.", true)]
Task> CreateToken(CreateTokenRequest request);
diff --git a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs
index 1c754804..92f2bcda 100644
--- a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs
+++ b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs
@@ -667,9 +667,22 @@ public async Task> GetUserTarget(GetUserTargetRequest req
}
}
- [ExcludeFromCodeCoverage]
///
- public Task> UpdateUserTarget(UpdateUserTargertRequest request) => throw new NotImplementedException();
+ public async Task> UpdateUserTarget(UpdateUserTargertRequest request)
+ {
+ try
+ {
+ request.Validate(true);
+
+ var result = await _usersApi.UpdateUserTarget(request.UserId, request.TargetId, request);
+
+ return result.GetApiResponse();
+ }
+ catch (Exception e)
+ {
+ return e.GetExceptionResponse();
+ }
+ }
[ExcludeFromCodeCoverage]
///
diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserTargertRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserTargertRequest.cs
index 83f4ee60..573763ed 100644
--- a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserTargertRequest.cs
+++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserTargertRequest.cs
@@ -18,17 +18,20 @@ public class UpdateUserTargertRequest : UserIdBaseRequest
[JsonPropertyName("identifier")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Identifier { get; set; }
///
/// Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used
///
[JsonPropertyName("providerId")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? ProviderId { get; set; }
///
/// Target name. Max length: 128 chars. For example: My Awesome App Galaxy S23.
///
[JsonPropertyName("name")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Name { get; set; }
}
diff --git a/tests/PinguApps.Appwrite.Server.Tests/Clients/Users/UsersClientTests.UpdateUserTarget.cs b/tests/PinguApps.Appwrite.Server.Tests/Clients/Users/UsersClientTests.UpdateUserTarget.cs
new file mode 100644
index 00000000..559962dc
--- /dev/null
+++ b/tests/PinguApps.Appwrite.Server.Tests/Clients/Users/UsersClientTests.UpdateUserTarget.cs
@@ -0,0 +1,78 @@
+using System.Net;
+using PinguApps.Appwrite.Shared.Requests.Users;
+using PinguApps.Appwrite.Shared.Tests;
+using PinguApps.Appwrite.Shared.Utils;
+using RichardSzalay.MockHttp;
+
+namespace PinguApps.Appwrite.Server.Tests.Clients.Users;
+public partial class UsersClientTests
+{
+ [Fact]
+ public async Task UpdateUserTarget_ShouldReturnSuccess_WhenApiCallSucceeds()
+ {
+ // Arrange
+ var request = new UpdateUserTargertRequest
+ {
+ UserId = IdUtils.GenerateUniqueId(),
+ TargetId = IdUtils.GenerateUniqueId(),
+ // Add other properties as needed
+ };
+
+ _mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/users/{request.UserId}/targets/{request.TargetId}")
+ .ExpectedHeaders()
+ .Respond(Constants.AppJson, Constants.TargetResponse);
+
+ // Act
+ var result = await _appwriteClient.Users.UpdateUserTarget(request);
+
+ // Assert
+ Assert.True(result.Success);
+ }
+
+ [Fact]
+ public async Task UpdateUserTarget_ShouldHandleException_WhenApiCallFails()
+ {
+ // Arrange
+ var request = new UpdateUserTargertRequest
+ {
+ UserId = IdUtils.GenerateUniqueId(),
+ TargetId = IdUtils.GenerateUniqueId(),
+ // Add other properties as needed
+ };
+
+ _mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/users/{request.UserId}/targets/{request.TargetId}")
+ .ExpectedHeaders()
+ .Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError);
+
+ // Act
+ var result = await _appwriteClient.Users.UpdateUserTarget(request);
+
+ // Assert
+ Assert.True(result.IsError);
+ Assert.True(result.IsAppwriteError);
+ }
+
+ [Fact]
+ public async Task UpdateUserTarget_ShouldReturnErrorResponse_WhenExceptionOccurs()
+ {
+ // Arrange
+ var request = new UpdateUserTargertRequest
+ {
+ UserId = IdUtils.GenerateUniqueId(),
+ TargetId = IdUtils.GenerateUniqueId(),
+ // Add other properties as needed
+ };
+
+ _mockHttp.Expect(HttpMethod.Patch, $"{Constants.Endpoint}/users/{request.UserId}/targets/{request.TargetId}")
+ .ExpectedHeaders()
+ .Throw(new HttpRequestException("An error occurred"));
+
+ // Act
+ var result = await _appwriteClient.Users.UpdateUserTarget(request);
+
+ // Assert
+ Assert.False(result.Success);
+ Assert.True(result.IsInternalError);
+ Assert.Equal("An error occurred", result.Result.AsT2.Message);
+ }
+}