From 9850823298ea49fa2373ef0917cde43121a3ff6f Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 8 Oct 2024 01:27:22 +0300 Subject: [PATCH] Fixed: Error updating providers with ID missing from JSON (cherry picked from commit c435fcd685cc97e98d14f747227eefd39e4d1164) --- src/Lidarr.Api.V1/ProviderControllerBase.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Lidarr.Api.V1/ProviderControllerBase.cs b/src/Lidarr.Api.V1/ProviderControllerBase.cs index 078276e06..8d0b88c4a 100644 --- a/src/Lidarr.Api.V1/ProviderControllerBase.cs +++ b/src/Lidarr.Api.V1/ProviderControllerBase.cs @@ -86,9 +86,16 @@ public ActionResult CreateProvider([FromBody] TProviderResour [RestPutById] [Consumes("application/json")] [Produces("application/json")] - public ActionResult UpdateProvider([FromBody] TProviderResource providerResource, [FromQuery] bool forceSave = false) + public ActionResult UpdateProvider([FromRoute] int id, [FromBody] TProviderResource providerResource, [FromQuery] bool forceSave = false) { - var existingDefinition = _providerFactory.Find(providerResource.Id); + // TODO: Remove fallback to Id from body in next API version bump + var existingDefinition = _providerFactory.Find(id) ?? _providerFactory.Find(providerResource.Id); + + if (existingDefinition == null) + { + return NotFound(); + } + var providerDefinition = GetDefinition(providerResource, existingDefinition, true, !forceSave, false); // Comparing via JSON string to eliminate the need for every provider implementation to implement equality checks. @@ -107,7 +114,7 @@ public ActionResult UpdateProvider([FromBody] TProviderResour _providerFactory.Update(providerDefinition); } - return Accepted(providerResource.Id); + return Accepted(existingDefinition.Id); } [HttpPut("bulk")]