From 7166a6c019fb1ad531863c22763029f9ea54f114 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 28 Apr 2024 23:14:10 +0300 Subject: [PATCH] Parameter binding for API requests --- src/Sonarr.Api.V3/AutoTagging/AutoTaggingController.cs | 4 ++-- src/Sonarr.Api.V3/Commands/CommandController.cs | 2 +- src/Sonarr.Api.V3/Config/ConfigController.cs | 2 +- src/Sonarr.Api.V3/Config/HostConfigController.cs | 2 +- src/Sonarr.Api.V3/Config/NamingConfigController.cs | 2 +- src/Sonarr.Api.V3/Config/UiConfigController.cs | 2 +- src/Sonarr.Api.V3/CustomFilters/CustomFilterController.cs | 4 ++-- src/Sonarr.Api.V3/CustomFormats/CustomFormatController.cs | 4 ++-- src/Sonarr.Api.V3/EpisodeFiles/EpisodeFileController.cs | 2 +- .../ImportLists/ImportListExclusionController.cs | 4 ++-- src/Sonarr.Api.V3/Indexers/ReleaseController.cs | 2 +- src/Sonarr.Api.V3/Indexers/ReleasePushController.cs | 2 +- src/Sonarr.Api.V3/Profiles/Delay/DelayProfileController.cs | 6 +++--- .../Profiles/Languages/LanguageProfileController.cs | 4 ++-- .../Profiles/Quality/QualityProfileController.cs | 4 ++-- .../Profiles/Release/ReleaseProfileController.cs | 4 ++-- src/Sonarr.Api.V3/ProviderControllerBase.cs | 2 +- src/Sonarr.Api.V3/Qualities/QualityDefinitionController.cs | 2 +- src/Sonarr.Api.V3/Queue/QueueActionController.cs | 2 +- .../RemotePathMappings/RemotePathMappingController.cs | 4 ++-- src/Sonarr.Api.V3/RootFolders/RootFolderController.cs | 2 +- src/Sonarr.Api.V3/SeasonPass/SeasonPassController.cs | 2 +- src/Sonarr.Api.V3/Series/SeriesController.cs | 4 ++-- src/Sonarr.Api.V3/System/Backup/BackupController.cs | 2 +- src/Sonarr.Api.V3/Tags/TagController.cs | 4 ++-- 25 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Sonarr.Api.V3/AutoTagging/AutoTaggingController.cs b/src/Sonarr.Api.V3/AutoTagging/AutoTaggingController.cs index a74c20c34..02cfbf9d5 100644 --- a/src/Sonarr.Api.V3/AutoTagging/AutoTaggingController.cs +++ b/src/Sonarr.Api.V3/AutoTagging/AutoTaggingController.cs @@ -51,7 +51,7 @@ namespace Sonarr.Api.V3.AutoTagging [RestPostById] [Consumes("application/json")] - public ActionResult Create(AutoTaggingResource autoTagResource) + public ActionResult Create([FromBody] AutoTaggingResource autoTagResource) { var model = autoTagResource.ToModel(_specifications); @@ -62,7 +62,7 @@ namespace Sonarr.Api.V3.AutoTagging [RestPutById] [Consumes("application/json")] - public ActionResult Update(AutoTaggingResource resource) + public ActionResult Update([FromBody] AutoTaggingResource resource) { var model = resource.ToModel(_specifications); diff --git a/src/Sonarr.Api.V3/Commands/CommandController.cs b/src/Sonarr.Api.V3/Commands/CommandController.cs index 1b17916de..980a6f875 100644 --- a/src/Sonarr.Api.V3/Commands/CommandController.cs +++ b/src/Sonarr.Api.V3/Commands/CommandController.cs @@ -51,7 +51,7 @@ namespace Sonarr.Api.V3.Commands [RestPostById] [Consumes("application/json")] [Produces("application/json")] - public ActionResult StartCommand(CommandResource commandResource) + public ActionResult StartCommand([FromBody] CommandResource commandResource) { var commandType = _knownTypes.GetImplementations(typeof(Command)) diff --git a/src/Sonarr.Api.V3/Config/ConfigController.cs b/src/Sonarr.Api.V3/Config/ConfigController.cs index 9d170e720..0506496a9 100644 --- a/src/Sonarr.Api.V3/Config/ConfigController.cs +++ b/src/Sonarr.Api.V3/Config/ConfigController.cs @@ -34,7 +34,7 @@ namespace Sonarr.Api.V3.Config [RestPutById] [Consumes("application/json")] - public virtual ActionResult SaveConfig(TResource resource) + public virtual ActionResult SaveConfig([FromBody] TResource resource) { var dictionary = resource.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public) diff --git a/src/Sonarr.Api.V3/Config/HostConfigController.cs b/src/Sonarr.Api.V3/Config/HostConfigController.cs index 50ef5c900..38fab24e7 100644 --- a/src/Sonarr.Api.V3/Config/HostConfigController.cs +++ b/src/Sonarr.Api.V3/Config/HostConfigController.cs @@ -122,7 +122,7 @@ namespace Sonarr.Api.V3.Config } [RestPutById] - public ActionResult SaveHostConfig(HostConfigResource resource) + public ActionResult SaveHostConfig([FromBody] HostConfigResource resource) { var dictionary = resource.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public) diff --git a/src/Sonarr.Api.V3/Config/NamingConfigController.cs b/src/Sonarr.Api.V3/Config/NamingConfigController.cs index f940519aa..a05894f45 100644 --- a/src/Sonarr.Api.V3/Config/NamingConfigController.cs +++ b/src/Sonarr.Api.V3/Config/NamingConfigController.cs @@ -53,7 +53,7 @@ namespace Sonarr.Api.V3.Config } [RestPutById] - public ActionResult UpdateNamingConfig(NamingConfigResource resource) + public ActionResult UpdateNamingConfig([FromBody] NamingConfigResource resource) { var nameSpec = resource.ToModel(); ValidateFormatResult(nameSpec); diff --git a/src/Sonarr.Api.V3/Config/UiConfigController.cs b/src/Sonarr.Api.V3/Config/UiConfigController.cs index 8aa83588a..c52479bda 100644 --- a/src/Sonarr.Api.V3/Config/UiConfigController.cs +++ b/src/Sonarr.Api.V3/Config/UiConfigController.cs @@ -32,7 +32,7 @@ namespace Sonarr.Api.V3.Config } [RestPutById] - public override ActionResult SaveConfig(UiConfigResource resource) + public override ActionResult SaveConfig([FromBody] UiConfigResource resource) { var dictionary = resource.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public) diff --git a/src/Sonarr.Api.V3/CustomFilters/CustomFilterController.cs b/src/Sonarr.Api.V3/CustomFilters/CustomFilterController.cs index 51f46d100..8fe7a62c0 100644 --- a/src/Sonarr.Api.V3/CustomFilters/CustomFilterController.cs +++ b/src/Sonarr.Api.V3/CustomFilters/CustomFilterController.cs @@ -31,7 +31,7 @@ namespace Sonarr.Api.V3.CustomFilters [RestPostById] [Consumes("application/json")] - public ActionResult AddCustomFilter(CustomFilterResource resource) + public ActionResult AddCustomFilter([FromBody] CustomFilterResource resource) { var customFilter = _customFilterService.Add(resource.ToModel()); @@ -40,7 +40,7 @@ namespace Sonarr.Api.V3.CustomFilters [RestPutById] [Consumes("application/json")] - public ActionResult UpdateCustomFilter(CustomFilterResource resource) + public ActionResult UpdateCustomFilter([FromBody] CustomFilterResource resource) { _customFilterService.Update(resource.ToModel()); return Accepted(resource.Id); diff --git a/src/Sonarr.Api.V3/CustomFormats/CustomFormatController.cs b/src/Sonarr.Api.V3/CustomFormats/CustomFormatController.cs index 0a5915452..4b560cd7e 100644 --- a/src/Sonarr.Api.V3/CustomFormats/CustomFormatController.cs +++ b/src/Sonarr.Api.V3/CustomFormats/CustomFormatController.cs @@ -49,7 +49,7 @@ namespace Sonarr.Api.V3.CustomFormats [RestPostById] [Consumes("application/json")] - public ActionResult Create(CustomFormatResource customFormatResource) + public ActionResult Create([FromBody] CustomFormatResource customFormatResource) { var model = customFormatResource.ToModel(_specifications); @@ -60,7 +60,7 @@ namespace Sonarr.Api.V3.CustomFormats [RestPutById] [Consumes("application/json")] - public ActionResult Update(CustomFormatResource resource) + public ActionResult Update([FromBody] CustomFormatResource resource) { var model = resource.ToModel(_specifications); diff --git a/src/Sonarr.Api.V3/EpisodeFiles/EpisodeFileController.cs b/src/Sonarr.Api.V3/EpisodeFiles/EpisodeFileController.cs index b1e9dd1fb..a9dc40f13 100644 --- a/src/Sonarr.Api.V3/EpisodeFiles/EpisodeFileController.cs +++ b/src/Sonarr.Api.V3/EpisodeFiles/EpisodeFileController.cs @@ -90,7 +90,7 @@ namespace Sonarr.Api.V3.EpisodeFiles [RestPutById] [Consumes("application/json")] - public ActionResult SetQuality(EpisodeFileResource episodeFileResource) + public ActionResult SetQuality([FromBody] EpisodeFileResource episodeFileResource) { var episodeFile = _mediaFileService.Get(episodeFileResource.Id); episodeFile.Quality = episodeFileResource.Quality; diff --git a/src/Sonarr.Api.V3/ImportLists/ImportListExclusionController.cs b/src/Sonarr.Api.V3/ImportLists/ImportListExclusionController.cs index d9cd55c03..58742ad79 100644 --- a/src/Sonarr.Api.V3/ImportLists/ImportListExclusionController.cs +++ b/src/Sonarr.Api.V3/ImportLists/ImportListExclusionController.cs @@ -49,7 +49,7 @@ namespace Sonarr.Api.V3.ImportLists [RestPostById] [Consumes("application/json")] - public ActionResult AddImportListExclusion(ImportListExclusionResource resource) + public ActionResult AddImportListExclusion([FromBody] ImportListExclusionResource resource) { var importListExclusion = _importListExclusionService.Add(resource.ToModel()); @@ -58,7 +58,7 @@ namespace Sonarr.Api.V3.ImportLists [RestPutById] [Consumes("application/json")] - public ActionResult UpdateImportListExclusion(ImportListExclusionResource resource) + public ActionResult UpdateImportListExclusion([FromBody] ImportListExclusionResource resource) { _importListExclusionService.Update(resource.ToModel()); return Accepted(resource.Id); diff --git a/src/Sonarr.Api.V3/Indexers/ReleaseController.cs b/src/Sonarr.Api.V3/Indexers/ReleaseController.cs index e1d9c9f50..6de121914 100644 --- a/src/Sonarr.Api.V3/Indexers/ReleaseController.cs +++ b/src/Sonarr.Api.V3/Indexers/ReleaseController.cs @@ -68,7 +68,7 @@ namespace Sonarr.Api.V3.Indexers [HttpPost] [Consumes("application/json")] - public async Task DownloadRelease(ReleaseResource release) + public async Task DownloadRelease([FromBody] ReleaseResource release) { var remoteEpisode = _remoteEpisodeCache.Find(GetCacheKey(release)); diff --git a/src/Sonarr.Api.V3/Indexers/ReleasePushController.cs b/src/Sonarr.Api.V3/Indexers/ReleasePushController.cs index 1b2f22417..96bcaf6c2 100644 --- a/src/Sonarr.Api.V3/Indexers/ReleasePushController.cs +++ b/src/Sonarr.Api.V3/Indexers/ReleasePushController.cs @@ -49,7 +49,7 @@ namespace Sonarr.Api.V3.Indexers [HttpPost] [Consumes("application/json")] - public ActionResult> Create(ReleaseResource release) + public ActionResult> Create([FromBody] ReleaseResource release) { _logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl ?? release.MagnetUrl); diff --git a/src/Sonarr.Api.V3/Profiles/Delay/DelayProfileController.cs b/src/Sonarr.Api.V3/Profiles/Delay/DelayProfileController.cs index 03b357d62..b632bdf08 100644 --- a/src/Sonarr.Api.V3/Profiles/Delay/DelayProfileController.cs +++ b/src/Sonarr.Api.V3/Profiles/Delay/DelayProfileController.cs @@ -35,7 +35,7 @@ namespace Sonarr.Api.V3.Profiles.Delay [RestPostById] [Consumes("application/json")] - public ActionResult Create(DelayProfileResource resource) + public ActionResult Create([FromBody] DelayProfileResource resource) { var model = resource.ToModel(); model = _delayProfileService.Add(model); @@ -56,7 +56,7 @@ namespace Sonarr.Api.V3.Profiles.Delay [RestPutById] [Consumes("application/json")] - public ActionResult Update(DelayProfileResource resource) + public ActionResult Update([FromBody] DelayProfileResource resource) { var model = resource.ToModel(); _delayProfileService.Update(model); @@ -76,7 +76,7 @@ namespace Sonarr.Api.V3.Profiles.Delay } [HttpPut("reorder/{id}")] - public List Reorder([FromRoute] int id, int? after) + public List Reorder([FromRoute] int id, [FromQuery] int? after) { ValidateId(id); diff --git a/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileController.cs b/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileController.cs index 0b2751597..aba003004 100644 --- a/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileController.cs +++ b/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileController.cs @@ -15,7 +15,7 @@ namespace Sonarr.Api.V3.Profiles.Languages [RestPostById] [Produces("application/json")] [Consumes("application/json")] - public ActionResult Create(LanguageProfileResource resource) + public ActionResult Create([FromBody] LanguageProfileResource resource) { return Accepted(resource); } @@ -28,7 +28,7 @@ namespace Sonarr.Api.V3.Profiles.Languages [RestPutById] [Produces("application/json")] [Consumes("application/json")] - public ActionResult Update(LanguageProfileResource resource) + public ActionResult Update([FromBody] LanguageProfileResource resource) { return Accepted(resource); } diff --git a/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileController.cs b/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileController.cs index 87f39b5ad..46a1c6730 100644 --- a/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileController.cs +++ b/src/Sonarr.Api.V3/Profiles/Quality/QualityProfileController.cs @@ -46,7 +46,7 @@ namespace Sonarr.Api.V3.Profiles.Quality [RestPostById] [Consumes("application/json")] - public ActionResult Create(QualityProfileResource resource) + public ActionResult Create([FromBody] QualityProfileResource resource) { var model = resource.ToModel(); model = _profileService.Add(model); @@ -61,7 +61,7 @@ namespace Sonarr.Api.V3.Profiles.Quality [RestPutById] [Consumes("application/json")] - public ActionResult Update(QualityProfileResource resource) + public ActionResult Update([FromBody] QualityProfileResource resource) { var model = resource.ToModel(); diff --git a/src/Sonarr.Api.V3/Profiles/Release/ReleaseProfileController.cs b/src/Sonarr.Api.V3/Profiles/Release/ReleaseProfileController.cs index eb53716d3..3d33c3b25 100644 --- a/src/Sonarr.Api.V3/Profiles/Release/ReleaseProfileController.cs +++ b/src/Sonarr.Api.V3/Profiles/Release/ReleaseProfileController.cs @@ -36,7 +36,7 @@ namespace Sonarr.Api.V3.Profiles.Release } [RestPostById] - public ActionResult Create(ReleaseProfileResource resource) + public ActionResult Create([FromBody] ReleaseProfileResource resource) { var model = resource.ToModel(); model = _profileService.Add(model); @@ -50,7 +50,7 @@ namespace Sonarr.Api.V3.Profiles.Release } [RestPutById] - public ActionResult Update(ReleaseProfileResource resource) + public ActionResult Update([FromBody] ReleaseProfileResource resource) { var model = resource.ToModel(); diff --git a/src/Sonarr.Api.V3/ProviderControllerBase.cs b/src/Sonarr.Api.V3/ProviderControllerBase.cs index 2622b9b02..c80c41981 100644 --- a/src/Sonarr.Api.V3/ProviderControllerBase.cs +++ b/src/Sonarr.Api.V3/ProviderControllerBase.cs @@ -245,7 +245,7 @@ namespace Sonarr.Api.V3 [HttpPost("action/{name}")] [Consumes("application/json")] [Produces("application/json")] - public IActionResult RequestAction(string name, [FromBody] TProviderResource providerResource) + public IActionResult RequestAction([FromRoute] string name, [FromBody] TProviderResource providerResource) { var existingDefinition = providerResource.Id > 0 ? _providerFactory.Find(providerResource.Id) : null; var providerDefinition = GetDefinition(providerResource, existingDefinition, false, false, false); diff --git a/src/Sonarr.Api.V3/Qualities/QualityDefinitionController.cs b/src/Sonarr.Api.V3/Qualities/QualityDefinitionController.cs index 93fed5288..5910ee896 100644 --- a/src/Sonarr.Api.V3/Qualities/QualityDefinitionController.cs +++ b/src/Sonarr.Api.V3/Qualities/QualityDefinitionController.cs @@ -23,7 +23,7 @@ namespace Sonarr.Api.V3.Qualities } [RestPutById] - public ActionResult Update(QualityDefinitionResource resource) + public ActionResult Update([FromBody] QualityDefinitionResource resource) { var model = resource.ToModel(); _qualityDefinitionService.Update(model); diff --git a/src/Sonarr.Api.V3/Queue/QueueActionController.cs b/src/Sonarr.Api.V3/Queue/QueueActionController.cs index f4fe953e7..b54f968de 100644 --- a/src/Sonarr.Api.V3/Queue/QueueActionController.cs +++ b/src/Sonarr.Api.V3/Queue/QueueActionController.cs @@ -21,7 +21,7 @@ namespace Sonarr.Api.V3.Queue } [HttpPost("grab/{id:int}")] - public async Task Grab(int id) + public async Task Grab([FromRoute] int id) { var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id); diff --git a/src/Sonarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs b/src/Sonarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs index 251b51e3f..ffdb318d2 100644 --- a/src/Sonarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs +++ b/src/Sonarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs @@ -41,7 +41,7 @@ namespace Sonarr.Api.V3.RemotePathMappings [RestPostById] [Consumes("application/json")] - public ActionResult CreateMapping(RemotePathMappingResource resource) + public ActionResult CreateMapping([FromBody] RemotePathMappingResource resource) { var model = resource.ToModel(); @@ -62,7 +62,7 @@ namespace Sonarr.Api.V3.RemotePathMappings } [RestPutById] - public ActionResult UpdateMapping(RemotePathMappingResource resource) + public ActionResult UpdateMapping([FromBody] RemotePathMappingResource resource) { var mapping = resource.ToModel(); diff --git a/src/Sonarr.Api.V3/RootFolders/RootFolderController.cs b/src/Sonarr.Api.V3/RootFolders/RootFolderController.cs index 87abcb067..de05cb4f1 100644 --- a/src/Sonarr.Api.V3/RootFolders/RootFolderController.cs +++ b/src/Sonarr.Api.V3/RootFolders/RootFolderController.cs @@ -50,7 +50,7 @@ namespace Sonarr.Api.V3.RootFolders [RestPostById] [Consumes("application/json")] - public ActionResult CreateRootFolder(RootFolderResource rootFolderResource) + public ActionResult CreateRootFolder([FromBody] RootFolderResource rootFolderResource) { var model = rootFolderResource.ToModel(); diff --git a/src/Sonarr.Api.V3/SeasonPass/SeasonPassController.cs b/src/Sonarr.Api.V3/SeasonPass/SeasonPassController.cs index be45658b0..cf699ddff 100644 --- a/src/Sonarr.Api.V3/SeasonPass/SeasonPassController.cs +++ b/src/Sonarr.Api.V3/SeasonPass/SeasonPassController.cs @@ -19,7 +19,7 @@ namespace Sonarr.Api.V3.SeasonPass [HttpPost] [Consumes("application/json")] - public IActionResult UpdateAll(SeasonPassResource resource) + public IActionResult UpdateAll([FromBody] SeasonPassResource resource) { var seriesToUpdate = _seriesService.GetSeries(resource.Series.Select(s => s.Id)); diff --git a/src/Sonarr.Api.V3/Series/SeriesController.cs b/src/Sonarr.Api.V3/Series/SeriesController.cs index e1d50ec0f..57ff76bc4 100644 --- a/src/Sonarr.Api.V3/Series/SeriesController.cs +++ b/src/Sonarr.Api.V3/Series/SeriesController.cs @@ -156,7 +156,7 @@ namespace Sonarr.Api.V3.Series [RestPostById] [Consumes("application/json")] - public ActionResult AddSeries(SeriesResource seriesResource) + public ActionResult AddSeries([FromBody] SeriesResource seriesResource) { var series = _addSeriesService.AddSeries(seriesResource.ToModel()); @@ -165,7 +165,7 @@ namespace Sonarr.Api.V3.Series [RestPutById] [Consumes("application/json")] - public ActionResult UpdateSeries(SeriesResource seriesResource, bool moveFiles = false) + public ActionResult UpdateSeries([FromBody] SeriesResource seriesResource, [FromQuery] bool moveFiles = false) { var series = _seriesService.GetSeries(seriesResource.Id); diff --git a/src/Sonarr.Api.V3/System/Backup/BackupController.cs b/src/Sonarr.Api.V3/System/Backup/BackupController.cs index bb2554c03..23d499b4e 100644 --- a/src/Sonarr.Api.V3/System/Backup/BackupController.cs +++ b/src/Sonarr.Api.V3/System/Backup/BackupController.cs @@ -70,7 +70,7 @@ namespace Sonarr.Api.V3.System.Backup } [HttpPost("restore/{id:int}")] - public object Restore(int id) + public object Restore([FromRoute] int id) { var backup = GetBackup(id); diff --git a/src/Sonarr.Api.V3/Tags/TagController.cs b/src/Sonarr.Api.V3/Tags/TagController.cs index 04f76989d..46da11ce9 100644 --- a/src/Sonarr.Api.V3/Tags/TagController.cs +++ b/src/Sonarr.Api.V3/Tags/TagController.cs @@ -36,14 +36,14 @@ namespace Sonarr.Api.V3.Tags [RestPostById] [Consumes("application/json")] - public ActionResult Create(TagResource resource) + public ActionResult Create([FromBody] TagResource resource) { return Created(_tagService.Add(resource.ToModel()).Id); } [RestPutById] [Consumes("application/json")] - public ActionResult Update(TagResource resource) + public ActionResult Update([FromBody] TagResource resource) { _tagService.Update(resource.ToModel()); return Accepted(resource.Id);