diff --git a/Endpoint/Configuration/General/GeneralConfig.cs b/Endpoint/Common/Settings/GeneralConfig.cs similarity index 90% rename from Endpoint/Configuration/General/GeneralConfig.cs rename to Endpoint/Common/Settings/GeneralConfig.cs index 2a6fcc2..dcf218e 100644 --- a/Endpoint/Configuration/General/GeneralConfig.cs +++ b/Endpoint/Common/Settings/GeneralConfig.cs @@ -4,9 +4,9 @@ using System.IO; using System.Text.Json; using System.Text.Json.Serialization; -namespace Mirea.Api.Endpoint.Configuration.General; +namespace Mirea.Api.Endpoint.Common.Settings; -public class GeneralConfig +public class GeneralConfig : ISaveSettings { [JsonIgnore] private const string FileName = "Settings.json"; diff --git a/Endpoint/Common/Settings/ISaveSettings.cs b/Endpoint/Common/Settings/ISaveSettings.cs new file mode 100644 index 0000000..0b51bde --- /dev/null +++ b/Endpoint/Common/Settings/ISaveSettings.cs @@ -0,0 +1,5 @@ +namespace Mirea.Api.Endpoint.Common.Settings; +public interface ISaveSettings +{ + void SaveSetting(); +} diff --git a/Endpoint/Configuration/AppConfig/CacheConfiguration.cs b/Endpoint/Configuration/AppConfig/CacheConfiguration.cs index bab6483..d81c3cb 100644 --- a/Endpoint/Configuration/AppConfig/CacheConfiguration.cs +++ b/Endpoint/Configuration/AppConfig/CacheConfiguration.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Mirea.Api.Endpoint.Configuration.General; +using Mirea.Api.Endpoint.Common.Settings; using Mirea.Api.Endpoint.Configuration.General.Settings; namespace Mirea.Api.Endpoint.Configuration.AppConfig; diff --git a/Endpoint/Configuration/AppConfig/LoggerConfiguration.cs b/Endpoint/Configuration/AppConfig/LoggerConfiguration.cs index a82010f..595810e 100644 --- a/Endpoint/Configuration/AppConfig/LoggerConfiguration.cs +++ b/Endpoint/Configuration/AppConfig/LoggerConfiguration.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Mirea.Api.Endpoint.Common.Services; -using Mirea.Api.Endpoint.Configuration.General; +using Mirea.Api.Endpoint.Common.Settings; using Serilog; using Serilog.Events; using Serilog.Filters; diff --git a/Endpoint/Configuration/AppConfig/SecureConfiguration.cs b/Endpoint/Configuration/AppConfig/SecureConfiguration.cs index 8e49960..5ea2fca 100644 --- a/Endpoint/Configuration/AppConfig/SecureConfiguration.cs +++ b/Endpoint/Configuration/AppConfig/SecureConfiguration.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Mirea.Api.Endpoint.Common.Services.Security; -using Mirea.Api.Endpoint.Configuration.General; +using Mirea.Api.Endpoint.Common.Settings; using Mirea.Api.Endpoint.Configuration.General.Settings; using Mirea.Api.Security; using Mirea.Api.Security.Common.Interfaces; diff --git a/Endpoint/Configuration/General/Validators/SettingsRequiredValidator.cs b/Endpoint/Configuration/General/Validators/SettingsRequiredValidator.cs index a1e8fbc..323ea7c 100644 --- a/Endpoint/Configuration/General/Validators/SettingsRequiredValidator.cs +++ b/Endpoint/Configuration/General/Validators/SettingsRequiredValidator.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Options; +using Mirea.Api.Endpoint.Common.Settings; using Mirea.Api.Endpoint.Configuration.General.Attributes; using Mirea.Api.Endpoint.Configuration.General.Interfaces; using System; diff --git a/Endpoint/Controllers/Configuration/SetupController.cs b/Endpoint/Controllers/Configuration/SetupController.cs index 9e35c8b..46a4d26 100644 --- a/Endpoint/Controllers/Configuration/SetupController.cs +++ b/Endpoint/Controllers/Configuration/SetupController.cs @@ -8,9 +8,8 @@ using Mirea.Api.Dto.Requests.Configuration; using Mirea.Api.Endpoint.Common.Attributes; using Mirea.Api.Endpoint.Common.Exceptions; using Mirea.Api.Endpoint.Common.Interfaces; -using Mirea.Api.Endpoint.Common.Model; using Mirea.Api.Endpoint.Common.Services; -using Mirea.Api.Endpoint.Configuration.General; +using Mirea.Api.Endpoint.Common.Settings; using Mirea.Api.Endpoint.Configuration.General.Settings; using Mirea.Api.Endpoint.Configuration.General.Validators; using Mirea.Api.Security.Services; @@ -24,7 +23,6 @@ using System.IO; using System.Net.Mail; using System.Runtime.InteropServices; using System.Security.Cryptography; -using System.Text.Json; using System.Text.RegularExpressions; namespace Mirea.Api.Endpoint.Controllers.Configuration; @@ -333,8 +331,7 @@ public partial class SetupController( if (!cache.TryGetValue(CacheAdminKey, out Admin? admin) || admin == null) throw new ControllerArgumentException("The administrator's data was not set."); - System.IO.File.WriteAllText(PathBuilder.Combine(Admin.PathToSave), JsonSerializer.Serialize(admin)); - + admin.SaveSetting(); GeneralConfig.SaveSetting(); return true; diff --git a/Endpoint/Controllers/V1/AuthController.cs b/Endpoint/Controllers/V1/AuthController.cs index dcd1821..0f70204 100644 --- a/Endpoint/Controllers/V1/AuthController.cs +++ b/Endpoint/Controllers/V1/AuthController.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Options; using Mirea.Api.Dto.Common; using Mirea.Api.Dto.Requests; using Mirea.Api.Dto.Responses; -using Mirea.Api.Endpoint.Common.Model; +using Mirea.Api.Endpoint.Common.Settings; using Mirea.Api.Security.Common.Dto.Requests; using Mirea.Api.Security.Services; using System; diff --git a/Endpoint/Controllers/V1/ScheduleController.cs b/Endpoint/Controllers/V1/ScheduleController.cs index 81bc283..0b16686 100644 --- a/Endpoint/Controllers/V1/ScheduleController.cs +++ b/Endpoint/Controllers/V1/ScheduleController.cs @@ -8,7 +8,7 @@ using Mirea.Api.Dto.Requests; using Mirea.Api.Dto.Responses; using Mirea.Api.Endpoint.Common.Attributes; using Mirea.Api.Endpoint.Common.Services; -using Mirea.Api.Endpoint.Configuration.General; +using Mirea.Api.Endpoint.Common.Settings; using System; using System.Collections.Generic; using System.Linq; diff --git a/Endpoint/Program.cs b/Endpoint/Program.cs index 89c754c..88f99a0 100644 --- a/Endpoint/Program.cs +++ b/Endpoint/Program.cs @@ -7,8 +7,8 @@ using Mirea.Api.DataAccess.Application; using Mirea.Api.DataAccess.Persistence; using Mirea.Api.DataAccess.Persistence.Common; using Mirea.Api.Endpoint.Common.Interfaces; -using Mirea.Api.Endpoint.Common.Model; using Mirea.Api.Endpoint.Common.Services; +using Mirea.Api.Endpoint.Common.Settings; using Mirea.Api.Endpoint.Configuration.AppConfig; using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Configuration.General.Validators; @@ -40,7 +40,7 @@ public class Program builder.Configuration.AddConfiguration(EnvironmentConfiguration.GetEnvironment()); builder.Configuration.AddJsonFile(GeneralConfig.FilePath, optional: true, reloadOnChange: true); builder.Services.Configure(builder.Configuration); - builder.Configuration.AddJsonFile(PathBuilder.Combine(Admin.PathToSave), optional: true, reloadOnChange: true); + builder.Configuration.AddJsonFile(Admin.FilePath, optional: true, reloadOnChange: true); builder.Services.Configure(builder.Configuration); builder.Host.AddCustomSerilog();