Adds Generic CommandHandlerDecorator

This commit is contained in:
Janus C. H. Knudsen 2025-03-12 00:13:53 +01:00
parent 49f9b99ee1
commit 64e696dc5a
21 changed files with 131 additions and 110 deletions

View file

@ -3,17 +3,16 @@ using Microsoft.ApplicationInsights;
using Npgsql;
using PlanTempus.Components.Users.Exceptions;
using PlanTempus.Core;
using PlanTempus.Core.CommandQueries;
using PlanTempus.Core.Database;
using PlanTempus.Core.Telemetry;
namespace PlanTempus.Components.Users.Create
{
public class CreateUserHandler(
TelemetryClient telemetryClient,
IDatabaseOperations databaseOperations,
ISecureTokenizer secureTokenizer) : ICommandHandler<CreateUserCommand, CreateUserResult>
ISecureTokenizer secureTokenizer) : ICommandHandler<CreateUserCommand>
{
public async Task<CreateUserResult> Handle(CreateUserCommand command)
public async Task<CommandResponse> Handle(CreateUserCommand command)
{
using var db = databaseOperations.CreateScope(nameof(CreateUserHandler));
try
@ -28,20 +27,19 @@ namespace PlanTempus.Components.Users.Create
var data = await db.Connection.QuerySqlAsync<CreateUserResult>(sql, new
{
Email = command.Email,
command.Email,
PasswordHash = secureTokenizer.TokenizeText(command.Password),
SecurityStamp = Guid.NewGuid().ToString("N"),
EmailConfirmed = false,
AccessFailedCount = 0,
LockoutEnabled = false,
IsActive = command.IsActive,
command.IsActive,
});
var result = data.First();
return result;
return new CommandResponse(command.CorrelationId);
}
catch (PostgresException ex) when (ex.SqlState == "23505")
{