Working on user+org create

This commit is contained in:
Janus C. H. Knudsen 2025-03-06 00:05:58 +01:00
parent a15cc00595
commit 0010a32248
6 changed files with 49 additions and 21 deletions

View file

@ -84,7 +84,6 @@ namespace PlanTempus.Database.Core.DDL
id SERIAL PRIMARY KEY,
connection_string VARCHAR(500) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
created_by INTEGER NOT NULL REFERENCES {_command.Schema}.users(id),
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);";

View file

@ -5,7 +5,7 @@ using System.Data;
namespace PlanTempus.Database.Core
{
public class UserService
public class UserService
{
public record UserCreateCommand(string CorrelationId, string Email, string Password);
@ -18,7 +18,6 @@ namespace PlanTempus.Database.Core
public async Task CreateUser(UserCreateCommand command)
{
var user = new User
{
Email = command.Email,
@ -32,8 +31,8 @@ namespace PlanTempus.Database.Core
INSERT INTO users (email, password_hash, security_stamp, email_confirmed, created_at)
VALUES (@Email, @PasswordHash, @SecurityStamp, @EmailConfirmed, @CreatedDate)
RETURNING id", user);
}
public async Task CreateOrganization(int userId, string organizationConnectionString)
{
var schema = "dev";
@ -52,8 +51,8 @@ namespace PlanTempus.Database.Core
};
var organizationId = await _db.ExecuteScalarAsync<int>(@$"
INSERT INTO {schema}.organizations (connection_string, created_date, created_by, is_active)
VALUES (@ConnectionString, @CreatedDate, @CreatedBy, @IsActive)
INSERT INTO {schema}.organizations (connection_string, created_date, is_active)
VALUES (@ConnectionString, @CreatedDate, @IsActive)
RETURNING id", organization);
// Link user to organization
@ -77,4 +76,4 @@ namespace PlanTempus.Database.Core
}
}
}
}
}