feat: create submit configuration
Some checks failed
.NET Test Pipeline / build-and-test (pull_request) Failing after 6m2s
Some checks failed
.NET Test Pipeline / build-and-test (pull_request) Failing after 6m2s
This commit is contained in:
parent
1fd6c8657a
commit
5400e0c873
@ -11,6 +11,7 @@ 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;
|
||||
@ -32,7 +33,7 @@ public class SetupController(ISetupToken setupToken, IMaintenanceModeNotConfigur
|
||||
private const string CacheAdminKey = "config_admin";
|
||||
|
||||
private GeneralConfig GeneralConfig
|
||||
{
|
||||
{
|
||||
get => cache.Get<GeneralConfig>(CacheGeneralKey) ?? new GeneralConfig();
|
||||
set => cache.Set(CacheGeneralKey, value);
|
||||
}
|
||||
@ -278,5 +279,31 @@ 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