wip
This commit is contained in:
parent
f3ab94eff1
commit
31666b4ba0
34 changed files with 140 additions and 83 deletions
|
|
@ -1,9 +1,15 @@
|
|||
namespace PlanTempus.Components.Users.Create
|
||||
{
|
||||
public class CreateUserCommand
|
||||
{
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
public interface ICommand
|
||||
{
|
||||
Guid CorrelationId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateUserCommand : ICommand
|
||||
{
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
public required Guid CorrelationId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,22 @@
|
|||
using Insight.Database;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Npgsql;
|
||||
using PlanTempus.Components.Users.Exceptions;
|
||||
using PlanTempus.Core;
|
||||
using PlanTempus.Core.Sql;
|
||||
using PlanTempus.Core.Database;
|
||||
using PlanTempus.Core.Telemetry;
|
||||
|
||||
namespace PlanTempus.Components.Users.Create
|
||||
{
|
||||
public interface ICommandHandler<T, TResult>
|
||||
{
|
||||
Task<TResult> Handle(T input);
|
||||
}
|
||||
|
||||
public class CreateUserHandler(
|
||||
TelemetryClient telemetryClient,
|
||||
IDatabaseOperations databaseOperations,
|
||||
ISecureTokenizer secureTokenizer)
|
||||
ISecureTokenizer secureTokenizer) : ICommandHandler<CreateUserCommand, CreateUserResult>
|
||||
{
|
||||
public async Task<CreateUserResult> Handle(CreateUserCommand command)
|
||||
{
|
||||
|
|
@ -36,13 +43,17 @@ namespace PlanTempus.Components.Users.Create
|
|||
});
|
||||
|
||||
|
||||
db.Success();
|
||||
var result = data.First();
|
||||
|
||||
telemetryClient.TrackTrace(GetType().Name, result.Format());
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (PostgresException ex) when (ex.SqlState == "23505")
|
||||
{
|
||||
db.Error(ex);
|
||||
throw new EmailAlreadyRegistreredException();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
db.Error(ex);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
using Microsoft.ApplicationInsights;
|
||||
|
||||
namespace PlanTempus.Components.Users.Create;
|
||||
|
||||
public class CreateUserHandlerDecorator : ICommandHandler<CreateUserCommand, CreateUserResult>
|
||||
{
|
||||
private readonly ICommandHandler<CreateUserCommand, CreateUserResult> _decoratedHandler;
|
||||
private readonly TelemetryClient _telemetryClient;
|
||||
|
||||
public CreateUserHandlerDecorator(
|
||||
ICommandHandler<CreateUserCommand, CreateUserResult> decoratedHandler,
|
||||
TelemetryClient telemetryClient)
|
||||
{
|
||||
_decoratedHandler = decoratedHandler;
|
||||
_telemetryClient = telemetryClient;
|
||||
}
|
||||
|
||||
public async Task<CreateUserResult> Handle(CreateUserCommand command)
|
||||
{
|
||||
_telemetryClient.TrackTrace($"Before handling {nameof(CreateUserCommand)}");
|
||||
var result = await _decoratedHandler.Handle(command);
|
||||
_telemetryClient.TrackTrace($"After handling {nameof(CreateUserCommand)}");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
namespace PlanTempus.Components.Users.Exceptions;
|
||||
|
||||
public class EmailAlreadyRegistreredException: Exception
|
||||
{
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue