diff --git a/Endpoint/Controllers/Configuration/SetupController.cs b/Endpoint/Controllers/Configuration/SetupController.cs index b629952..1384d9b 100644 --- a/Endpoint/Controllers/Configuration/SetupController.cs +++ b/Endpoint/Controllers/Configuration/SetupController.cs @@ -9,6 +9,8 @@ using Mirea.Api.Endpoint.Common.Interfaces; using Mirea.Api.Endpoint.Common.Services; using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Configuration.General.Settings; +using System; +using System.Data; namespace Mirea.Api.Endpoint.Controllers.Configuration; @@ -55,5 +57,32 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur return Ok(true); } + private ActionResult SetDatabase(string connectionString, DbSettings.DatabaseEnum databaseType) + where TConnection : class, IDbConnection, new() + where TException : Exception + { + try + { + using var connection = new TConnection(); + connection.ConnectionString = connectionString; + connection.Open(); + connection.Close(); + + var general = GeneralConfig; + general.DbSettings = new DbSettings + { + ConnectionStringSql = connectionString, + TypeDatabase = databaseType + }; + GeneralConfig = general; + + return Ok(true); + } + catch (TException ex) + { + throw new ControllerArgumentException($"Error when connecting: {ex.Message}"); + } + } + } \ No newline at end of file