Add missing TypedResults

This commit is contained in:
Bogdan 2026-04-26 14:17:31 +03:00
parent bf5d48c76a
commit 0c599bef2d
13 changed files with 26 additions and 13 deletions

View file

@ -37,11 +37,11 @@ public Ok<object> GetEntityType(string path)
{
if (_diskProvider.FileExists(path))
{
return TypedResults.Ok((object)new { type = "file" });
return TypedResults.Ok<object>(new { type = "file" });
}
// Return folder even if it doesn't exist on disk to avoid leaking anything from the UI about the underlying system
return TypedResults.Ok((object)new { type = "folder" });
return TypedResults.Ok<object>(new { type = "folder" });
}
[HttpGet("mediafiles")]

View file

@ -163,7 +163,7 @@ public Ok<List<HistoryResource>> GetEpisodeHistory(int episodeId, EpisodeHistory
}).ToList());
}
[HttpPost("failed/{id}")]
[HttpPost("failed/{id:int}")]
public NoContent MarkAsFailed([FromRoute] int id)
{
_failedDownloadService.MarkAsFailed(id);

View file

@ -22,6 +22,7 @@ protected override LanguageResource GetResourceById(int id)
}
[HttpGet]
[Produces("application/json")]
public Ok<List<LanguageResource>> GetAll()
{
var languageResources = Language.All.Select(l => new LanguageResource

View file

@ -17,6 +17,7 @@ public QualityProfileSchemaController(IQualityProfileService profileService)
}
[HttpGet]
[Produces("application/json")]
public Ok<QualityProfileResource> GetSchema()
{
var qualityProfile = _profileService.GetDefaultProfile(string.Empty);

View file

@ -54,6 +54,7 @@ public ReleaseProfileController(IReleaseProfileService releaseProfileService, II
}
[RestPostById]
[Consumes("application/json")]
public Results<Created<ReleaseProfileResource>, NotFound> Create([FromBody] ReleaseProfileResource resource)
{
var model = resource.ToModel();
@ -70,6 +71,7 @@ public NoContent DeleteProfile(int id)
}
[RestPutById]
[Consumes("application/json")]
public Results<Accepted<ReleaseProfileResource>, NotFound> Update([FromBody] ReleaseProfileResource resource)
{
var model = resource.ToModel();
@ -85,6 +87,7 @@ protected override ReleaseProfileResource GetResourceById(int id)
}
[HttpGet]
[Produces("application/json")]
public Ok<List<ReleaseProfileResource>> GetAll()
{
return TypedResults.Ok(_releaseProfileService.All().ToResource());

View file

@ -50,12 +50,14 @@ protected override QualityDefinitionResource GetResourceById(int id)
}
[HttpGet]
[Produces("application/json")]
public Ok<List<QualityDefinitionResource>> GetAll()
{
return TypedResults.Ok(_qualityDefinitionService.All().ToResource());
}
[HttpPut]
[Consumes("application/json")]
public Ok<List<QualityDefinitionResource>> UpdateMany([FromBody] List<QualityDefinitionResource> resource)
{
// Read from request

View file

@ -22,7 +22,7 @@ public QueueActionController(IPendingReleaseService pendingReleaseService,
}
[HttpPost("grab/{id:int}")]
public async Task<NoContent> Grab([FromRoute] int id)
public async Task<Results<NoContent, NotFound>> Grab([FromRoute] int id)
{
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
@ -38,7 +38,7 @@ public async Task<NoContent> Grab([FromRoute] int id)
[HttpPost("grab/bulk")]
[Consumes("application/json")]
public async Task<NoContent> Grab([FromBody] QueueBulkResource resource)
public async Task<Results<NoContent, NotFound>> Grab([FromBody] QueueBulkResource resource)
{
foreach (var id in resource.Ids)
{

View file

@ -95,6 +95,7 @@ public Results<NoContent, NotFound> RemoveAction(int id, string? message = null,
}
[HttpDelete("bulk")]
[Consumes("application/json")]
public NoContent RemoveMany([FromBody] QueueBulkResource resource, [FromQuery] string? message, [FromQuery] bool removeFromClient = true, [FromQuery] bool blocklist = false, [FromQuery] bool skipRedownload = false, [FromQuery] bool changeCategory = false)
{
var trackedDownloadIds = new List<string>();

View file

@ -26,7 +26,7 @@ public Ok<object> GetFolder([FromRoute] int id)
var series = _seriesService.GetSeries(id);
var folder = _fileNameBuilder.GetSeriesFolder(series);
return TypedResults.Ok((object)new
return TypedResults.Ok<object>(new
{
folder
});

View file

@ -17,6 +17,8 @@ public SeriesImportController(IAddSeriesService addSeriesService)
}
[HttpPost]
[Consumes("application/json")]
[Produces("application/json")]
public Ok<List<SeriesResource>> Import([FromBody] List<SeriesResource> resource)
{
var newSeries = resource.ToModel();

View file

@ -42,12 +42,14 @@ protected override NamingSettingsResource GetResourceById(int id)
}
[HttpGet]
[Produces("application/json")]
public Ok<NamingSettingsResource> GetNamingConfig()
{
return TypedResults.Ok(GetResourceById(1));
}
[RestPutById]
[Consumes("application/json")]
public Results<Accepted<NamingSettingsResource>, NotFound> UpdateNamingConfig([FromBody] NamingSettingsResource resource)
{
var nameSpec = resource.ToModel();
@ -59,7 +61,8 @@ public Results<Accepted<NamingSettingsResource>, NotFound> UpdateNamingConfig([F
}
[HttpGet("examples")]
public object GetExamples([FromQuery]NamingSettingsResource settings)
[Produces("application/json")]
public Ok<NamingExampleResource> GetExamples([FromQuery] NamingSettingsResource settings)
{
if (settings.Id == 0)
{
@ -107,7 +110,7 @@ public object GetExamples([FromQuery]NamingSettingsResource settings)
? null
: _filenameSampleService.GetSpecialsFolderSample(nameSpec);
return sampleResource;
return TypedResults.Ok(sampleResource);
}
private void ValidateFormatResult(NamingConfig nameSpec)

View file

@ -86,7 +86,7 @@ public Results<Ok<object>, NotFound> Restore([FromRoute] int id)
var path = GetBackupPath(backup);
_backupService.Restore(path);
return TypedResults.Ok((object)new { RestartRequired = true });
return TypedResults.Ok<object>(new { RestartRequired = true });
}
[HttpPost("restore/upload")]
@ -106,7 +106,7 @@ public Results<Ok<object>, BadRequest<object>> RestoreUpload()
if (!ValidExtensions.Contains(extension))
{
return TypedResults.BadRequest((object)new { error = $"Invalid extension, must be one of: {string.Join(", ", ValidExtensions)}" });
return TypedResults.BadRequest<object>(new { error = $"Invalid extension, must be one of: {string.Join(", ", ValidExtensions)}" });
}
var path = Path.Combine(_appFolderInfo.TempFolder, $"sonarr_backup_restore{extension}");
@ -115,7 +115,7 @@ public Results<Ok<object>, BadRequest<object>> RestoreUpload()
_backupService.Restore(path);
_diskProvider.DeleteFile(path);
return TypedResults.Ok((object)new { RestartRequired = true });
return TypedResults.Ok<object>(new { RestartRequired = true });
}
private string GetBackupPath(NzbDrone.Core.Backup.Backup backup)

View file

@ -116,13 +116,13 @@ public Ok<Dictionary<string, List<string>>> DuplicateRoutes()
public Ok<object> Shutdown()
{
Task.Factory.StartNew(() => _lifecycleService.Shutdown());
return TypedResults.Ok((object)new { ShuttingDown = true });
return TypedResults.Ok<object>(new { ShuttingDown = true });
}
[HttpPost("restart")]
public Ok<object> Restart()
{
Task.Factory.StartNew(() => _lifecycleService.Restart());
return TypedResults.Ok((object)new { Restarting = true });
return TypedResults.Ok<object>(new { Restarting = true });
}
}