Add Application configuration #11

Merged
Wesser merged 128 commits from feat/add-setup into release/v1.0.0 2024-06-01 07:35:30 +03:00
Showing only changes of commit 5400e0c873 - Show all commits

View File

@ -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;
@ -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;
}
}