This commit is contained in:
Janus Knudsen 2025-03-05 16:56:58 +01:00
parent 91da89a4e8
commit a15cc00595
4 changed files with 20 additions and 36 deletions

View file

@ -5,19 +5,13 @@ using System.Data;
namespace PlanTempus.Database.ConfigurationManagementSystem; namespace PlanTempus.Database.ConfigurationManagementSystem;
public class SetupConfiguration : IDbConfigure<SetupConfiguration.Command> public class SetupConfiguration(IDbConnectionFactory connectionFactory) : IDbConfigure<SetupConfiguration.Command>
{ {
public class Command { } public class Command { }
private readonly IDbConnectionFactory _connectionFactory;
public SetupConfiguration(IDbConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory;
}
public void With(Command notInUse, ConnectionStringParameters parameters = null) public void With(Command notInUse, ConnectionStringParameters parameters = null)
{ {
using var conn = parameters is null ? _connectionFactory.Create() : _connectionFactory.Create(parameters); using var conn = parameters is null ? connectionFactory.Create() : connectionFactory.Create(parameters);
using var transaction = conn.OpenWithTransaction(); using var transaction = conn.OpenWithTransaction();
try try

View file

@ -22,12 +22,10 @@ namespace PlanTempus.Database.RolesPermissionSystem
/// <param name="schema">The schema name where the tables will be created.</param> /// <param name="schema">The schema name where the tables will be created.</param>
public void CreateSystem() public void CreateSystem()
{ {
//if (!Validations.IsValidSchemaName(_schema)) //if (!Validations.IsValidSchemaName(_schema))
// throw new ArgumentException("Invalid schema name", _schema); // throw new ArgumentException("Invalid schema name", _schema);
using (var transaction = _db.BeginTransaction()) using var transaction = _db.BeginTransaction();
{
try try
{ {
CreateRolesTable(); CreateRolesTable();
@ -43,7 +41,6 @@ namespace PlanTempus.Database.RolesPermissionSystem
throw new InvalidOperationException("Failed to create system tables.", ex); throw new InvalidOperationException("Failed to create system tables.", ex);
} }
} }
}
private void ExecuteSql(string sql) private void ExecuteSql(string sql)

View file

@ -3,23 +3,15 @@ using PlanTempus.Core.Sql;
namespace PlanTempus.Components.Organizations.Create namespace PlanTempus.Components.Organizations.Create
{ {
public class CreateOrganizationHandler public class CreateOrganizationHandler(IDatabaseOperations databaseOperations)
{ {
private readonly IDatabaseOperations _databaseOperations;
public CreateOrganizationHandler(IDatabaseOperations databaseOperations)
{
_databaseOperations = databaseOperations;
}
public async Task<CreateOrganizationResult> Handle(CreateOrganizationCommand command) public async Task<CreateOrganizationResult> Handle(CreateOrganizationCommand command)
{ {
using var db = _databaseOperations.CreateScope(nameof(CreateOrganizationHandler)); using var db = databaseOperations.CreateScope(nameof(CreateOrganizationHandler));
try try
{ {
var sql = @" var sql = @"INSERT INTO organizations (connection_string, created_by)
INSERT INTO organizations (connection_string, created_by)
VALUES (@ConnectionString, @CreatedBy) VALUES (@ConnectionString, @CreatedBy)
RETURNING id, created_at"; RETURNING id, created_at";

View file

@ -18,6 +18,7 @@ namespace PlanTempus.Components.Users.Create
} }
var result = await handler.Handle(command); var result = await handler.Handle(command);
return CreatedAtAction( return CreatedAtAction(
nameof(CreateUserCommand), nameof(CreateUserCommand),
"GetUser", "GetUser",