mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-03-04 14:27:52 -05:00
added config DTOs
This commit is contained in:
@@ -1,10 +1,22 @@
|
||||
using Common.Configuration.Arr;
|
||||
using Common.Configuration.ContentBlocker;
|
||||
using Common.Configuration.DownloadCleaner;
|
||||
using Common.Configuration.DownloadClient;
|
||||
using Common.Configuration.DTOs.Arr;
|
||||
using Common.Configuration.DTOs.ContentBlocker;
|
||||
using Common.Configuration.DTOs.DownloadCleaner;
|
||||
using Common.Configuration.DTOs.DownloadClient;
|
||||
using Common.Configuration.DTOs.General;
|
||||
using Common.Configuration.DTOs.IgnoredDownloads;
|
||||
using Common.Configuration.DTOs.Notification;
|
||||
using Common.Configuration.DTOs.QueueCleaner;
|
||||
using Common.Configuration.General;
|
||||
using Common.Configuration.IgnoredDownloads;
|
||||
using Common.Configuration.Notification;
|
||||
using Common.Configuration.QueueCleaner;
|
||||
using Infrastructure.Configuration;
|
||||
using Infrastructure.Services;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Executable.Controllers;
|
||||
@@ -30,7 +42,8 @@ public class ConfigurationController : ControllerBase
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<QueueCleanerConfig>();
|
||||
return Ok(config);
|
||||
var dto = config.Adapt<QueueCleanerConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -45,7 +58,8 @@ public class ConfigurationController : ControllerBase
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<ContentBlockerConfig>();
|
||||
return Ok(config);
|
||||
var dto = config.Adapt<ContentBlockerConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -60,7 +74,8 @@ public class ConfigurationController : ControllerBase
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<DownloadCleanerConfig>();
|
||||
return Ok(config);
|
||||
var dto = config.Adapt<DownloadCleanerConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -75,7 +90,8 @@ public class ConfigurationController : ControllerBase
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<DownloadClientConfig>();
|
||||
return Ok(config);
|
||||
var dto = config.Adapt<DownloadClientConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -90,7 +106,8 @@ public class ConfigurationController : ControllerBase
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<IgnoredDownloadsConfig>();
|
||||
return Ok(config);
|
||||
var dto = config.Adapt<IgnoredDownloadsConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -98,12 +115,98 @@ public class ConfigurationController : ControllerBase
|
||||
return StatusCode(500, "An error occurred while retrieving IgnoredDownloads configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("queue_cleaner")]
|
||||
public async Task<IActionResult> UpdateQueueCleanerConfig([FromBody] QueueCleanerConfig config)
|
||||
|
||||
[HttpGet("general")]
|
||||
public async Task<IActionResult> GetGeneralConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<GeneralConfig>();
|
||||
var dto = config.Adapt<GeneralConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving General configuration");
|
||||
return StatusCode(500, "An error occurred while retrieving General configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("sonarr")]
|
||||
public async Task<IActionResult> GetSonarrConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<SonarrConfig>();
|
||||
var dto = config.Adapt<SonarrConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving Sonarr configuration");
|
||||
return StatusCode(500, "An error occurred while retrieving Sonarr configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("radarr")]
|
||||
public async Task<IActionResult> GetRadarrConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<RadarrConfig>();
|
||||
var dto = config.Adapt<RadarrConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving Radarr configuration");
|
||||
return StatusCode(500, "An error occurred while retrieving Radarr configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("lidarr")]
|
||||
public async Task<IActionResult> GetLidarrConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<LidarrConfig>();
|
||||
var dto = config.Adapt<LidarrConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving Lidarr configuration");
|
||||
return StatusCode(500, "An error occurred while retrieving Lidarr configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("notifications")]
|
||||
public async Task<IActionResult> GetNotificationsConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
var config = await _configManager.GetConfigurationAsync<NotificationsConfig>();
|
||||
var dto = config.Adapt<NotificationsConfigDto>();
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error retrieving Notifications configuration");
|
||||
return StatusCode(500, "An error occurred while retrieving Notifications configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("queue_cleaner")]
|
||||
public async Task<IActionResult> UpdateQueueCleanerConfig([FromBody] QueueCleanerConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config
|
||||
var config = await _configManager.GetConfigurationAsync<QueueCleanerConfig>();
|
||||
|
||||
// Apply updates from DTO
|
||||
dto.Adapt(config);
|
||||
|
||||
// Validate the configuration
|
||||
config.Validate();
|
||||
|
||||
@@ -125,10 +228,16 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("content_blocker")]
|
||||
public async Task<IActionResult> UpdateContentBlockerConfig([FromBody] ContentBlockerConfig config)
|
||||
public async Task<IActionResult> UpdateContentBlockerConfig([FromBody] ContentBlockerConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config
|
||||
var config = await _configManager.GetConfigurationAsync<ContentBlockerConfig>();
|
||||
|
||||
// Apply updates from DTO
|
||||
dto.Adapt(config);
|
||||
|
||||
// Validate the configuration
|
||||
config.Validate();
|
||||
|
||||
@@ -150,10 +259,16 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("download_cleaner")]
|
||||
public async Task<IActionResult> UpdateDownloadCleanerConfig([FromBody] DownloadCleanerConfig config)
|
||||
public async Task<IActionResult> UpdateDownloadCleanerConfig([FromBody] DownloadCleanerConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config
|
||||
var config = await _configManager.GetConfigurationAsync<DownloadCleanerConfig>();
|
||||
|
||||
// Apply updates from DTO
|
||||
dto.Adapt(config);
|
||||
|
||||
// Validate the configuration
|
||||
config.Validate();
|
||||
|
||||
@@ -175,10 +290,16 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("download_client")]
|
||||
public async Task<IActionResult> UpdateDownloadClientConfig([FromBody] DownloadClientConfig config)
|
||||
public async Task<IActionResult> UpdateDownloadClientConfig([FromBody] DownloadClientConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config to preserve sensitive data
|
||||
var config = await _configManager.GetConfigurationAsync<DownloadClientConfig>();
|
||||
|
||||
// Apply updates from DTO, preserving sensitive data if not provided
|
||||
dto.Adapt(config);
|
||||
|
||||
// Validate the configuration
|
||||
config.Validate();
|
||||
|
||||
@@ -200,10 +321,16 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("ignored_downloads")]
|
||||
public async Task<IActionResult> UpdateIgnoredDownloadsConfig([FromBody] IgnoredDownloadsConfig config)
|
||||
public async Task<IActionResult> UpdateIgnoredDownloadsConfig([FromBody] IgnoredDownloadsConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config
|
||||
var config = await _configManager.GetConfigurationAsync<IgnoredDownloadsConfig>();
|
||||
|
||||
// Apply updates from DTO
|
||||
dto.Adapt(config);
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configManager.SaveConfigurationAsync(config);
|
||||
if (!result)
|
||||
@@ -221,6 +348,158 @@ public class ConfigurationController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("general")]
|
||||
public async Task<IActionResult> UpdateGeneralConfig([FromBody] GeneralConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config to preserve sensitive data
|
||||
var config = await _configManager.GetConfigurationAsync<GeneralConfig>();
|
||||
|
||||
// Apply updates from DTO, preserving sensitive data if not provided
|
||||
dto.Adapt(config);
|
||||
|
||||
// Validate the configuration
|
||||
config.Validate();
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configManager.SaveConfigurationAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save General configuration");
|
||||
}
|
||||
|
||||
_logger.LogInformation("General configuration updated successfully");
|
||||
return Ok(new { Message = "General configuration updated successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating General configuration");
|
||||
return StatusCode(500, "An error occurred while updating General configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("sonarr")]
|
||||
public async Task<IActionResult> UpdateSonarrConfig([FromBody] SonarrConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config to preserve sensitive data
|
||||
var config = await _configManager.GetConfigurationAsync<SonarrConfig>();
|
||||
|
||||
// Apply updates from DTO, preserving sensitive data if not provided
|
||||
dto.Adapt(config);
|
||||
|
||||
// Validate the configuration
|
||||
config.Validate();
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configManager.SaveConfigurationAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save Sonarr configuration");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Sonarr configuration updated successfully");
|
||||
return Ok(new { Message = "Sonarr configuration updated successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating Sonarr configuration");
|
||||
return StatusCode(500, "An error occurred while updating Sonarr configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("radarr")]
|
||||
public async Task<IActionResult> UpdateRadarrConfig([FromBody] RadarrConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config to preserve sensitive data
|
||||
var config = await _configManager.GetConfigurationAsync<RadarrConfig>();
|
||||
|
||||
// Apply updates from DTO, preserving sensitive data if not provided
|
||||
dto.Adapt(config);
|
||||
|
||||
// Validate the configuration
|
||||
config.Validate();
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configManager.SaveConfigurationAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save Radarr configuration");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Radarr configuration updated successfully");
|
||||
return Ok(new { Message = "Radarr configuration updated successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating Radarr configuration");
|
||||
return StatusCode(500, "An error occurred while updating Radarr configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("lidarr")]
|
||||
public async Task<IActionResult> UpdateLidarrConfig([FromBody] LidarrConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config to preserve sensitive data
|
||||
var config = await _configManager.GetConfigurationAsync<LidarrConfig>();
|
||||
|
||||
// Apply updates from DTO, preserving sensitive data if not provided
|
||||
dto.Adapt(config);
|
||||
|
||||
// Validate the configuration
|
||||
config.Validate();
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configManager.SaveConfigurationAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save Lidarr configuration");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Lidarr configuration updated successfully");
|
||||
return Ok(new { Message = "Lidarr configuration updated successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating Lidarr configuration");
|
||||
return StatusCode(500, "An error occurred while updating Lidarr configuration");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("notifications")]
|
||||
public async Task<IActionResult> UpdateNotificationsConfig([FromBody] NotificationsConfigUpdateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get existing config to preserve sensitive data
|
||||
var config = await _configManager.GetConfigurationAsync<NotificationsConfig>();
|
||||
|
||||
// Apply updates from DTO, preserving sensitive data if not provided
|
||||
dto.Adapt(config);
|
||||
|
||||
// Persist the configuration
|
||||
var result = await _configManager.SaveConfigurationAsync(config);
|
||||
if (!result)
|
||||
{
|
||||
return StatusCode(500, "Failed to save Notifications configuration");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Notifications configuration updated successfully");
|
||||
return Ok(new { Message = "Notifications configuration updated successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating Notifications configuration");
|
||||
return StatusCode(500, "An error occurred while updating Notifications configuration");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO add missing configs
|
||||
// TODO do not return passwords
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user