diff --git a/src/Kyoo.Authentication/Views/AuthApi.cs b/src/Kyoo.Authentication/Views/AuthApi.cs
index e3899eba..10dbdccb 100644
--- a/src/Kyoo.Authentication/Views/AuthApi.cs
+++ b/src/Kyoo.Authentication/Views/AuthApi.cs
@@ -200,23 +200,48 @@ namespace Kyoo.Authentication.Views
/// Edit information about the currently authenticated user.
///
/// The new data for the current user.
- ///
- /// Should old properties of the resource be discarded or should null values considered as not changed?
- ///
/// The currently authenticated user after modifications.
/// The given access token is invalid.
[HttpPut("me")]
[UserOnly]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
- public async Task> EditMe(User user, [FromQuery] bool resetOld = true)
+ public async Task> EditMe(User user)
{
if (!int.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out int userID))
return Forbid();
try
{
user.ID = userID;
- return await _users.Edit(user, resetOld);
+ return await _users.Edit(user, true);
+ }
+ catch (ItemNotFoundException)
+ {
+ return Forbid();
+ }
+ }
+
+ ///
+ /// Patch self
+ ///
+ ///
+ /// Edit only provided informations about the currently authenticated user.
+ ///
+ /// The new data for the current user.
+ /// The currently authenticated user after modifications.
+ /// The given access token is invalid.
+ [HttpPut("me")]
+ [UserOnly]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status403Forbidden)]
+ public async Task> PatchMe(User user)
+ {
+ if (!int.TryParse(User.FindFirstValue(ClaimTypes.NameIdentifier), out int userID))
+ return Forbid();
+ try
+ {
+ user.ID = userID;
+ return await _users.Edit(user, false);
}
catch (ItemNotFoundException)
{
diff --git a/src/Kyoo.Core/Views/Helper/CrudApi.cs b/src/Kyoo.Core/Views/Helper/CrudApi.cs
index 3aa3cc01..d452eeb0 100644
--- a/src/Kyoo.Core/Views/Helper/CrudApi.cs
+++ b/src/Kyoo.Core/Views/Helper/CrudApi.cs
@@ -181,10 +181,7 @@ namespace Kyoo.Core.Api
/// If not, the slug will be used to identify it.
///
/// The resource to edit.
- ///
- /// Should old properties of the resource be discarded or should null values considered as not changed?
- ///
- /// The created resource.
+ /// The edited resource.
/// The resource in the request body is invalid.
/// No item found with the specified ID (or slug).
[HttpPut]
@@ -192,16 +189,49 @@ namespace Kyoo.Core.Api
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(RequestError))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
- public async Task> Edit([FromBody] T resource, [FromQuery] bool resetOld = true)
+ public async Task> Edit([FromBody] T resource)
{
try
{
if (resource.ID > 0)
- return await Repository.Edit(resource, resetOld);
+ return await Repository.Edit(resource, true);
T old = await Repository.Get(resource.Slug);
resource.ID = old.ID;
- return await Repository.Edit(resource, resetOld);
+ return await Repository.Edit(resource, true);
+ }
+ catch (ItemNotFoundException)
+ {
+ return NotFound();
+ }
+ }
+
+ ///
+ /// Patch
+ ///
+ ///
+ /// Edit only specified properties of an item. If the ID is specified it will be used to identify the resource.
+ /// If not, the slug will be used to identify it.
+ ///
+ /// The resource to patch.
+ /// The edited resource.
+ /// The resource in the request body is invalid.
+ /// No item found with the specified ID (or slug).
+ [HttpPatch]
+ [PartialPermission(Kind.Write)]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(RequestError))]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
+ public async Task> Patch([FromBody] T resource)
+ {
+ try
+ {
+ if (resource.ID > 0)
+ return await Repository.Edit(resource, false);
+
+ T old = await Repository.Get(resource.Slug);
+ resource.ID = old.ID;
+ return await Repository.Edit(resource, false);
}
catch (ItemNotFoundException)
{