feat: add setter database
This commit is contained in:
parent
eefb049e0e
commit
e7ed69169c
@ -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<bool> SetDatabase<TConnection, TException>(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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user