Compare commits
No commits in common. "5400e0c8737704f04de2afd03c28bbe520266a90" and "a902d9eb810d7ca37276eafc0eb8feb5e4549c86" have entirely different histories.
5400e0c873
...
a902d9eb81
@ -11,7 +11,6 @@ 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 Mirea.Api.Endpoint.Configuration.General.Validators;
|
||||
using MySqlConnector;
|
||||
using Npgsql;
|
||||
using StackExchange.Redis;
|
||||
@ -29,11 +28,9 @@ namespace Mirea.Api.Endpoint.Controllers.Configuration;
|
||||
[MaintenanceModeIgnore]
|
||||
public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigureService notConfigureService, IMemoryCache cache) : BaseController
|
||||
{
|
||||
private const string CacheGeneralKey = "config_general";
|
||||
private const string CacheAdminKey = "config_admin";
|
||||
|
||||
private const string CacheGeneralKey = "config_part";
|
||||
private GeneralConfig GeneralConfig
|
||||
{
|
||||
{
|
||||
get => cache.Get<GeneralConfig>(CacheGeneralKey) ?? new GeneralConfig();
|
||||
set => cache.Set(CacheGeneralKey, value);
|
||||
}
|
||||
@ -88,8 +85,8 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
|
||||
};
|
||||
GeneralConfig = general;
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
return Ok(true);
|
||||
}
|
||||
catch (TException ex)
|
||||
{
|
||||
throw new ControllerArgumentException($"Error when connecting: {ex.Message}");
|
||||
@ -115,11 +112,11 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
|
||||
[BadRequestResponse]
|
||||
public ActionResult<bool> SetMysql([FromBody] DatabaseRequest request)
|
||||
{
|
||||
string connectionString = $"Server={request.Server}:{request.Port};Uid={request.User};Database={request.Database};";
|
||||
string connectionString = $"Server={request.Server}:{request.Port};Uid={request.User};Database={request.Database}";
|
||||
if (request.Password != null)
|
||||
connectionString += $"Pwd={request.Password};";
|
||||
connectionString += $";Pwd={request.Password}";
|
||||
if (request.Ssl)
|
||||
connectionString += "SslMode=Require;";
|
||||
connectionString += ";SslMode=Require;";
|
||||
|
||||
return SetDatabase<MySqlConnection, MySqlException>(connectionString, DbSettings.DatabaseEnum.Mysql);
|
||||
}
|
||||
@ -193,16 +190,6 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpPost("CreateAdmin")]
|
||||
[TokenAuthentication]
|
||||
[BadRequestResponse]
|
||||
public ActionResult<string> CreateAdmin([FromBody] CreateUserRequest user)
|
||||
{
|
||||
// todo: change CreateUserRequest to Domain entity
|
||||
cache.Set(CacheAdminKey, user);
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpPost("SetLogging")]
|
||||
[TokenAuthentication]
|
||||
[BadRequestResponse]
|
||||
@ -279,31 +266,5 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
|
||||
return true;
|
||||
}
|
||||
|
||||
[HttpPost("Submit")]
|
||||
[TokenAuthentication]
|
||||
[BadRequestResponse]
|
||||
public ActionResult<bool> Submit()
|
||||
{
|
||||
if (!new SettingsRequiredValidator(GeneralConfig).AreSettingsValid())
|
||||
throw new ControllerArgumentException("The necessary data has not been configured.");
|
||||
|
||||
// todo: change CreateUserRequest to Domain entity
|
||||
if (!cache.TryGetValue(CacheAdminKey, out CreateUserRequest? user) || user == null)
|
||||
throw new ControllerArgumentException("The administrator's data was not set.");
|
||||
|
||||
if (System.IO.File.Exists(PathBuilder.Combine(GeneralConfig.FilePath)))
|
||||
System.IO.File.Delete(PathBuilder.Combine(GeneralConfig.FilePath));
|
||||
|
||||
System.IO.File.WriteAllText(PathBuilder.Combine("admin.json"), JsonSerializer.Serialize(user));
|
||||
|
||||
System.IO.File.WriteAllText(
|
||||
PathBuilder.Combine(GeneralConfig.FilePath),
|
||||
JsonSerializer.Serialize(GeneralConfig, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
})
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user