Add theme property in API

Fixes #7772
This commit is contained in:
Qstick 2022-11-22 18:27:47 -06:00
parent aa8e886dab
commit ef90ac7041
3 changed files with 31 additions and 6 deletions

View File

@ -10,7 +10,7 @@ namespace Radarr.Api.V3.Config
public abstract class ConfigController<TResource> : RestController<TResource>
where TResource : RestResource, new()
{
private readonly IConfigService _configService;
protected readonly IConfigService _configService;
protected ConfigController(IConfigService configService)
{
@ -23,6 +23,7 @@ namespace Radarr.Api.V3.Config
}
[HttpGet]
[Produces("application/json")]
public TResource GetConfig()
{
var resource = ToResource(_configService);
@ -32,7 +33,8 @@ namespace Radarr.Api.V3.Config
}
[RestPutById]
public ActionResult<TResource> SaveConfig(TResource resource)
[Consumes("application/json")]
public virtual ActionResult<TResource> SaveConfig(TResource resource)
{
var dictionary = resource.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)

View File

@ -1,19 +1,40 @@
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.Configuration;
using Radarr.Api.V3.Config;
using Radarr.Http;
using Radarr.Http.REST.Attributes;
namespace Radarr.Api.V3.Config
{
[V3ApiController("config/ui")]
public class UiConfigController : ConfigController<UiConfigResource>
{
public UiConfigController(IConfigService configService)
private readonly IConfigFileProvider _configFileProvider;
public UiConfigController(IConfigFileProvider configFileProvider, IConfigService configService)
: base(configService)
{
_configFileProvider = configFileProvider;
}
[RestPutById]
public override ActionResult<UiConfigResource> SaveConfig(UiConfigResource resource)
{
var dictionary = resource.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.ToDictionary(prop => prop.Name, prop => prop.GetValue(resource, null));
_configFileProvider.SaveConfigDictionary(dictionary);
_configService.SaveConfigDictionary(dictionary);
return Accepted(resource.Id);
}
protected override UiConfigResource ToResource(IConfigService model)
{
return UiConfigResourceMapper.ToResource(model);
return UiConfigResourceMapper.ToResource(_configFileProvider, model);
}
}
}

View File

@ -21,11 +21,12 @@ namespace Radarr.Api.V3.Config
public bool EnableColorImpairedMode { get; set; }
public int MovieInfoLanguage { get; set; }
public int UILanguage { get; set; }
public string Theme { get; set; }
}
public static class UiConfigResourceMapper
{
public static UiConfigResource ToResource(IConfigService model)
public static UiConfigResource ToResource(IConfigFileProvider config, IConfigService model)
{
return new UiConfigResource
{
@ -41,7 +42,8 @@ namespace Radarr.Api.V3.Config
EnableColorImpairedMode = model.EnableColorImpairedMode,
MovieInfoLanguage = model.MovieInfoLanguage,
UILanguage = model.UILanguage
UILanguage = model.UILanguage,
Theme = config.Theme
};
}
}