Fixed: Use route Id for PUT requests if not passed in body

This commit is contained in:
Qstick 2022-11-28 20:26:38 -06:00
parent 528feb14c9
commit becc567ff7
2 changed files with 9 additions and 2 deletions

View File

@ -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<EpisodeResource> SetEpisodeMonitored([FromRoute] int id, [FromBody] EpisodeResource resource)
{
_episodeService.SetEpisodeMonitored(id, resource.Monitored);

View File

@ -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);
}
}