From e7ed69169c5c1ddbcae5a1dbd53afb6c4ab7031f Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Wed, 29 May 2024 03:37:04 +0300 Subject: [PATCH] feat: add setter database --- .../Configuration/SetupController.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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