Add Application configuration #11
.envDbInitializer.csDependencyInjection.cs
.gitea/workflows
ApiDto
Common
Requests
Application/Common/Mappings
Backend.slnEndpoint
Common
Attributes
Exceptions
Interfaces
Services
Configuration
EnvironmentManager.cs
General
Swagger
Controllers
Endpoint.csprojMiddleware
Program.csProperties
Persistence
Security
SqlData
Application
Application.csprojDependencyInjection.cs
Common
Cqrs
Campus
Queries
Discipline
Queries
Faculty
Queries
Group
Queries
LectureHall
Queries
Professor
Queries
Schedule
Interfaces
Domain
Domain.csproj
Schedule
Migrations
MysqlMigrations
Migrations
20240601023106_InitialMigration.Designer.cs20240601023106_InitialMigration.csUberDbContextModelSnapshot.cs
MysqlMigrations.csprojPsqlMigrations
Migrations
20240601021702_InitialMigration.Designer.cs20240601021702_InitialMigration.csUberDbContextModelSnapshot.cs
PsqlMigrations.csprojSqliteMigrations
Persistence
Common
BaseDbContext.csConfigurationResolver.csDatabaseProvider.csDbContextFactory.csModelBuilderExtensions.cs
Contexts
Schedule
EntityTypeConfigurations
Persistence.csprojUberDbContext.cs@ -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);
|
||||
}
|
||||
@ -87,8 +88,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}");
|
||||
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user