1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-26 12:42:31 +01:00

Parameter binding for API requests

This commit is contained in:
Bogdan 2024-04-28 23:14:10 +03:00 committed by Mark McDowall
parent 3fbe436138
commit 7166a6c019
25 changed files with 37 additions and 37 deletions

View File

@ -51,7 +51,7 @@ namespace Sonarr.Api.V3.AutoTagging
[RestPostById]
[Consumes("application/json")]
public ActionResult<AutoTaggingResource> Create(AutoTaggingResource autoTagResource)
public ActionResult<AutoTaggingResource> Create([FromBody] AutoTaggingResource autoTagResource)
{
var model = autoTagResource.ToModel(_specifications);
@ -62,7 +62,7 @@ namespace Sonarr.Api.V3.AutoTagging
[RestPutById]
[Consumes("application/json")]
public ActionResult<AutoTaggingResource> Update(AutoTaggingResource resource)
public ActionResult<AutoTaggingResource> Update([FromBody] AutoTaggingResource resource)
{
var model = resource.ToModel(_specifications);

View File

@ -51,7 +51,7 @@ namespace Sonarr.Api.V3.Commands
[RestPostById]
[Consumes("application/json")]
[Produces("application/json")]
public ActionResult<CommandResource> StartCommand(CommandResource commandResource)
public ActionResult<CommandResource> StartCommand([FromBody] CommandResource commandResource)
{
var commandType =
_knownTypes.GetImplementations(typeof(Command))

View File

@ -34,7 +34,7 @@ namespace Sonarr.Api.V3.Config
[RestPutById]
[Consumes("application/json")]
public virtual ActionResult<TResource> SaveConfig(TResource resource)
public virtual ActionResult<TResource> SaveConfig([FromBody] TResource resource)
{
var dictionary = resource.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)

View File

@ -122,7 +122,7 @@ namespace Sonarr.Api.V3.Config
}
[RestPutById]
public ActionResult<HostConfigResource> SaveHostConfig(HostConfigResource resource)
public ActionResult<HostConfigResource> SaveHostConfig([FromBody] HostConfigResource resource)
{
var dictionary = resource.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)

View File

@ -53,7 +53,7 @@ namespace Sonarr.Api.V3.Config
}
[RestPutById]
public ActionResult<NamingConfigResource> UpdateNamingConfig(NamingConfigResource resource)
public ActionResult<NamingConfigResource> UpdateNamingConfig([FromBody] NamingConfigResource resource)
{
var nameSpec = resource.ToModel();
ValidateFormatResult(nameSpec);

View File

@ -32,7 +32,7 @@ namespace Sonarr.Api.V3.Config
}
[RestPutById]
public override ActionResult<UiConfigResource> SaveConfig(UiConfigResource resource)
public override ActionResult<UiConfigResource> SaveConfig([FromBody] UiConfigResource resource)
{
var dictionary = resource.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)

View File

@ -31,7 +31,7 @@ namespace Sonarr.Api.V3.CustomFilters
[RestPostById]
[Consumes("application/json")]
public ActionResult<CustomFilterResource> AddCustomFilter(CustomFilterResource resource)
public ActionResult<CustomFilterResource> 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<CustomFilterResource> UpdateCustomFilter(CustomFilterResource resource)
public ActionResult<CustomFilterResource> UpdateCustomFilter([FromBody] CustomFilterResource resource)
{
_customFilterService.Update(resource.ToModel());
return Accepted(resource.Id);

View File

@ -49,7 +49,7 @@ namespace Sonarr.Api.V3.CustomFormats
[RestPostById]
[Consumes("application/json")]
public ActionResult<CustomFormatResource> Create(CustomFormatResource customFormatResource)
public ActionResult<CustomFormatResource> Create([FromBody] CustomFormatResource customFormatResource)
{
var model = customFormatResource.ToModel(_specifications);
@ -60,7 +60,7 @@ namespace Sonarr.Api.V3.CustomFormats
[RestPutById]
[Consumes("application/json")]
public ActionResult<CustomFormatResource> Update(CustomFormatResource resource)
public ActionResult<CustomFormatResource> Update([FromBody] CustomFormatResource resource)
{
var model = resource.ToModel(_specifications);

View File

@ -90,7 +90,7 @@ namespace Sonarr.Api.V3.EpisodeFiles
[RestPutById]
[Consumes("application/json")]
public ActionResult<EpisodeFileResource> SetQuality(EpisodeFileResource episodeFileResource)
public ActionResult<EpisodeFileResource> SetQuality([FromBody] EpisodeFileResource episodeFileResource)
{
var episodeFile = _mediaFileService.Get(episodeFileResource.Id);
episodeFile.Quality = episodeFileResource.Quality;

View File

@ -49,7 +49,7 @@ namespace Sonarr.Api.V3.ImportLists
[RestPostById]
[Consumes("application/json")]
public ActionResult<ImportListExclusionResource> AddImportListExclusion(ImportListExclusionResource resource)
public ActionResult<ImportListExclusionResource> 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<ImportListExclusionResource> UpdateImportListExclusion(ImportListExclusionResource resource)
public ActionResult<ImportListExclusionResource> UpdateImportListExclusion([FromBody] ImportListExclusionResource resource)
{
_importListExclusionService.Update(resource.ToModel());
return Accepted(resource.Id);

View File

@ -68,7 +68,7 @@ namespace Sonarr.Api.V3.Indexers
[HttpPost]
[Consumes("application/json")]
public async Task<object> DownloadRelease(ReleaseResource release)
public async Task<object> DownloadRelease([FromBody] ReleaseResource release)
{
var remoteEpisode = _remoteEpisodeCache.Find(GetCacheKey(release));

View File

@ -49,7 +49,7 @@ namespace Sonarr.Api.V3.Indexers
[HttpPost]
[Consumes("application/json")]
public ActionResult<List<ReleaseResource>> Create(ReleaseResource release)
public ActionResult<List<ReleaseResource>> Create([FromBody] ReleaseResource release)
{
_logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl ?? release.MagnetUrl);

View File

@ -35,7 +35,7 @@ namespace Sonarr.Api.V3.Profiles.Delay
[RestPostById]
[Consumes("application/json")]
public ActionResult<DelayProfileResource> Create(DelayProfileResource resource)
public ActionResult<DelayProfileResource> 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<DelayProfileResource> Update(DelayProfileResource resource)
public ActionResult<DelayProfileResource> 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<DelayProfileResource> Reorder([FromRoute] int id, int? after)
public List<DelayProfileResource> Reorder([FromRoute] int id, [FromQuery] int? after)
{
ValidateId(id);

View File

@ -15,7 +15,7 @@ namespace Sonarr.Api.V3.Profiles.Languages
[RestPostById]
[Produces("application/json")]
[Consumes("application/json")]
public ActionResult<LanguageProfileResource> Create(LanguageProfileResource resource)
public ActionResult<LanguageProfileResource> 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<LanguageProfileResource> Update(LanguageProfileResource resource)
public ActionResult<LanguageProfileResource> Update([FromBody] LanguageProfileResource resource)
{
return Accepted(resource);
}

View File

@ -46,7 +46,7 @@ namespace Sonarr.Api.V3.Profiles.Quality
[RestPostById]
[Consumes("application/json")]
public ActionResult<QualityProfileResource> Create(QualityProfileResource resource)
public ActionResult<QualityProfileResource> 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<QualityProfileResource> Update(QualityProfileResource resource)
public ActionResult<QualityProfileResource> Update([FromBody] QualityProfileResource resource)
{
var model = resource.ToModel();

View File

@ -36,7 +36,7 @@ namespace Sonarr.Api.V3.Profiles.Release
}
[RestPostById]
public ActionResult<ReleaseProfileResource> Create(ReleaseProfileResource resource)
public ActionResult<ReleaseProfileResource> 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<ReleaseProfileResource> Update(ReleaseProfileResource resource)
public ActionResult<ReleaseProfileResource> Update([FromBody] ReleaseProfileResource resource)
{
var model = resource.ToModel();

View File

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

View File

@ -23,7 +23,7 @@ namespace Sonarr.Api.V3.Qualities
}
[RestPutById]
public ActionResult<QualityDefinitionResource> Update(QualityDefinitionResource resource)
public ActionResult<QualityDefinitionResource> Update([FromBody] QualityDefinitionResource resource)
{
var model = resource.ToModel();
_qualityDefinitionService.Update(model);

View File

@ -21,7 +21,7 @@ namespace Sonarr.Api.V3.Queue
}
[HttpPost("grab/{id:int}")]
public async Task<object> Grab(int id)
public async Task<object> Grab([FromRoute] int id)
{
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);

View File

@ -41,7 +41,7 @@ namespace Sonarr.Api.V3.RemotePathMappings
[RestPostById]
[Consumes("application/json")]
public ActionResult<RemotePathMappingResource> CreateMapping(RemotePathMappingResource resource)
public ActionResult<RemotePathMappingResource> CreateMapping([FromBody] RemotePathMappingResource resource)
{
var model = resource.ToModel();
@ -62,7 +62,7 @@ namespace Sonarr.Api.V3.RemotePathMappings
}
[RestPutById]
public ActionResult<RemotePathMappingResource> UpdateMapping(RemotePathMappingResource resource)
public ActionResult<RemotePathMappingResource> UpdateMapping([FromBody] RemotePathMappingResource resource)
{
var mapping = resource.ToModel();

View File

@ -50,7 +50,7 @@ namespace Sonarr.Api.V3.RootFolders
[RestPostById]
[Consumes("application/json")]
public ActionResult<RootFolderResource> CreateRootFolder(RootFolderResource rootFolderResource)
public ActionResult<RootFolderResource> CreateRootFolder([FromBody] RootFolderResource rootFolderResource)
{
var model = rootFolderResource.ToModel();

View File

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

View File

@ -156,7 +156,7 @@ namespace Sonarr.Api.V3.Series
[RestPostById]
[Consumes("application/json")]
public ActionResult<SeriesResource> AddSeries(SeriesResource seriesResource)
public ActionResult<SeriesResource> 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<SeriesResource> UpdateSeries(SeriesResource seriesResource, bool moveFiles = false)
public ActionResult<SeriesResource> UpdateSeries([FromBody] SeriesResource seriesResource, [FromQuery] bool moveFiles = false)
{
var series = _seriesService.GetSeries(seriesResource.Id);

View File

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

View File

@ -36,14 +36,14 @@ namespace Sonarr.Api.V3.Tags
[RestPostById]
[Consumes("application/json")]
public ActionResult<TagResource> Create(TagResource resource)
public ActionResult<TagResource> Create([FromBody] TagResource resource)
{
return Created(_tagService.Add(resource.ToModel()).Id);
}
[RestPutById]
[Consumes("application/json")]
public ActionResult<TagResource> Update(TagResource resource)
public ActionResult<TagResource> Update([FromBody] TagResource resource)
{
_tagService.Update(resource.ToModel());
return Accepted(resource.Id);