From becc567ff792463f8a2738d91c842548bbda9dbf Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 28 Nov 2022 20:26:38 -0600 Subject: [PATCH] Fixed: Use route Id for PUT requests if not passed in body --- src/Sonarr.Api.V3/Episodes/EpisodeController.cs | 5 +++-- src/Sonarr.Http/REST/RestController.cs | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Sonarr.Api.V3/Episodes/EpisodeController.cs b/src/Sonarr.Api.V3/Episodes/EpisodeController.cs index 19b542638..349a0e679 100644 --- a/src/Sonarr.Api.V3/Episodes/EpisodeController.cs +++ b/src/Sonarr.Api.V3/Episodes/EpisodeController.cs @@ -8,6 +8,7 @@ using NzbDrone.SignalR; using Sonarr.Http; using Sonarr.Http.Extensions; using Sonarr.Http.REST; +using Sonarr.Http.REST.Attributes; namespace Sonarr.Api.V3.Episodes { @@ -47,9 +48,9 @@ namespace Sonarr.Api.V3.Episodes throw new BadRequestException("seriesId or episodeIds must be provided"); } - [HttpPut("{id}")] + [RestPutById] [Consumes("application/json")] - public IActionResult SetEpisodeMonitored([FromBody] EpisodeResource resource, [FromRoute] int id) + public ActionResult SetEpisodeMonitored([FromRoute] int id, [FromBody] EpisodeResource resource) { _episodeService.SetEpisodeMonitored(id, resource.Monitored); diff --git a/src/Sonarr.Http/REST/RestController.cs b/src/Sonarr.Http/REST/RestController.cs index 71c951c9e..03f615ffb 100644 --- a/src/Sonarr.Http/REST/RestController.cs +++ b/src/Sonarr.Http/REST/RestController.cs @@ -70,6 +70,12 @@ namespace Sonarr.Http.REST foreach (var resource in resourceArgs) { + // Map route Id to body resource if not set in request + if (Request.Method == "PUT" && resource.Id == 0 && context.RouteData.Values.TryGetValue("id", out var routeId)) + { + resource.Id = Convert.ToInt32(routeId); + } + ValidateResource(resource, skipValidate, skipShared); } }