Skip to content

Commit

Permalink
Implement handler
Browse files Browse the repository at this point in the history
  • Loading branch information
inputfalken committed Jul 11, 2024
1 parent f8a5484 commit 9885ea5
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/Dynatello/Handlers/DeleteRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
using Amazon.DynamoDBv2.Model;
using Dynatello.Pipelines;

namespace Dynatello.Handlers;

internal sealed class DeleteREquestHandler<TArg, T> : IRequestHandler<TArg, T>
internal sealed class DeleteREquestHandler<TArg, T> : IRequestHandler<TArg, T?>
{
public Task<T> Send(TArg arg, CancellationToken cancellationToken)
private readonly HandlerOptions _handlerOptions;
private readonly Func<TArg, DeleteItemRequest> _createRequest;
private readonly Func<Dictionary<string, AttributeValue>, T> _createItem;

internal DeleteREquestHandler(
HandlerOptions handlerOptions,
Func<TArg, DeleteItemRequest> createRequest,
Func<Dictionary<string, AttributeValue>, T> createItem
)
{
throw new NotImplementedException();
_handlerOptions = handlerOptions;
_createRequest = createRequest;
_createItem = createItem;
}
public async Task<T?> Send(TArg arg, CancellationToken cancellationToken)
{
var request = _createRequest(arg);
var response = await request
.SendRequest(
_handlerOptions.RequestsPipelines,
(x, y, z) => y.DeleteItemAsync(x, z),
_handlerOptions.AmazonDynamoDB,
cancellationToken
);

return request.ReturnValues.IsValueProvided()
? _createItem(response.Attributes)
: default;
}
}

0 comments on commit 9885ea5

Please sign in to comment.