WIP cozy
This commit is contained in:
parent
91da89a4e8
commit
a15cc00595
4 changed files with 20 additions and 36 deletions
|
|
@ -5,19 +5,13 @@ using System.Data;
|
|||
|
||||
namespace PlanTempus.Database.ConfigurationManagementSystem;
|
||||
|
||||
public class SetupConfiguration : IDbConfigure<SetupConfiguration.Command>
|
||||
public class SetupConfiguration(IDbConnectionFactory connectionFactory) : IDbConfigure<SetupConfiguration.Command>
|
||||
{
|
||||
public class Command { }
|
||||
|
||||
private readonly IDbConnectionFactory _connectionFactory;
|
||||
|
||||
public SetupConfiguration(IDbConnectionFactory connectionFactory)
|
||||
{
|
||||
_connectionFactory = connectionFactory;
|
||||
}
|
||||
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();
|
||||
|
||||
try
|
||||
|
|
|
|||
|
|
@ -22,26 +22,23 @@ namespace PlanTempus.Database.RolesPermissionSystem
|
|||
/// <param name="schema">The schema name where the tables will be created.</param>
|
||||
public void CreateSystem()
|
||||
{
|
||||
|
||||
//if (!Validations.IsValidSchemaName(_schema))
|
||||
// throw new ArgumentException("Invalid schema name", _schema);
|
||||
|
||||
using (var transaction = _db.BeginTransaction())
|
||||
using var transaction = _db.BeginTransaction();
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
CreateRolesTable();
|
||||
CreatePermissionsTable();
|
||||
CreatePermissionTypesTable();
|
||||
CreateRolePermissionsTable();
|
||||
CreateRolesTable();
|
||||
CreatePermissionsTable();
|
||||
CreatePermissionTypesTable();
|
||||
CreateRolePermissionsTable();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to create system tables.", ex);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw new InvalidOperationException("Failed to create system tables.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,25 +3,17 @@ using PlanTempus.Core.Sql;
|
|||
|
||||
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)
|
||||
{
|
||||
using var db = _databaseOperations.CreateScope(nameof(CreateOrganizationHandler));
|
||||
using var db = databaseOperations.CreateScope(nameof(CreateOrganizationHandler));
|
||||
|
||||
try
|
||||
{
|
||||
var sql = @"
|
||||
INSERT INTO organizations (connection_string, created_by)
|
||||
VALUES (@ConnectionString, @CreatedBy)
|
||||
RETURNING id, created_at";
|
||||
var sql = @"INSERT INTO organizations (connection_string, created_by)
|
||||
VALUES (@ConnectionString, @CreatedBy)
|
||||
RETURNING id, created_at";
|
||||
|
||||
|
||||
var data = await db.Connection.QuerySqlAsync<CreateOrganizationResult>(sql, new
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace PlanTempus.Components.Users.Create
|
|||
}
|
||||
|
||||
var result = await handler.Handle(command);
|
||||
|
||||
return CreatedAtAction(
|
||||
nameof(CreateUserCommand),
|
||||
"GetUser",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue