31 lines
871 B
C#
31 lines
871 B
C#
|
|
using Books.Api.Domain.ApiKeys;
|
||
|
|
using EventFlow.Commands;
|
||
|
|
|
||
|
|
namespace Books.Api.Commands.ApiKeys;
|
||
|
|
|
||
|
|
public class CreateApiKeyCommandHandler
|
||
|
|
: CommandHandler<ApiKeyAggregate, ApiKeyId, CreateApiKeyCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
ApiKeyAggregate aggregate,
|
||
|
|
CreateApiKeyCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.Create(command.Name, command.KeyHash, command.CompanyId, command.CreatedBy);
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class RevokeApiKeyCommandHandler
|
||
|
|
: CommandHandler<ApiKeyAggregate, ApiKeyId, RevokeApiKeyCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
ApiKeyAggregate aggregate,
|
||
|
|
RevokeApiKeyCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.Revoke(command.RevokedBy);
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|