Skip to content

Commit

Permalink
Add methods to create handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
inputfalken committed Jul 11, 2024
1 parent 9885ea5 commit d29c9c4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Dynatello/Handlers/DeleteRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace Dynatello.Handlers;

internal sealed class DeleteREquestHandler<TArg, T> : IRequestHandler<TArg, T?>
internal sealed class DeleteRequestHandler<TArg, T> : IRequestHandler<TArg, T?>
{
private readonly HandlerOptions _handlerOptions;
private readonly Func<TArg, DeleteItemRequest> _createRequest;
private readonly Func<Dictionary<string, AttributeValue>, T> _createItem;

internal DeleteREquestHandler(
internal DeleteRequestHandler(
HandlerOptions handlerOptions,
Func<TArg, DeleteItemRequest> createRequest,
Func<Dictionary<string, AttributeValue>, T> createItem
Expand Down
42 changes: 42 additions & 0 deletions src/Dynatello/Handlers/TableAccessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,46 @@ Func<IRequestBuilderFactory<T, TArg, TReferences, TArgumentReferences>, IRequest
);
}


/// <summary>
/// Creates a <see cref="DeleteItemRequest"/> based <see cref="IRequestHandler{T, TArg}"/> from an <see cref="IRequestBuilder{TArg, TRequest}"/>.
/// </summary>
public static IRequestHandler<TArg, T?> ToDeleteRequestHandler<T, TArg, TReferences, TArgumentReferences>(
this ITableAccess<T, TArg, TReferences, TArgumentReferences> item,
Func<IRequestBuilderFactory<T, TArg, TReferences, TArgumentReferences>, IRequestBuilder<TArg, DeleteItemRequest>> requestBuilderSelector
)
where TReferences : IAttributeExpressionNameTracker
where TArgumentReferences : IAttributeExpressionValueTracker<TArg>
where TArg : notnull
where T : notnull
{
return new DeleteRequestHandler<TArg, T>(
new HandlerOptions(),
requestBuilderSelector(item.ToRequestBuilderFactory()).Build,
item.Marshaller.Unmarshall
);
}

/// <summary>
/// Creates a <see cref="DeleteItemRequest"/> based <see cref="IRequestHandler{T, TArg}"/> from an <see cref="IRequestBuilder{TArg, TRequest}"/>.
/// </summary>
public static IRequestHandler<TArg, T?> ToDeleteRequestHandler<T, TArg, TReferences, TArgumentReferences>(
this ITableAccess<T, TArg, TReferences, TArgumentReferences> item,
Func<IRequestBuilderFactory<T, TArg, TReferences, TArgumentReferences>, IRequestBuilder<TArg, DeleteItemRequest>> requestBuilderSelector,
Action<HandlerOptions> configure
)
where TReferences : IAttributeExpressionNameTracker
where TArgumentReferences : IAttributeExpressionValueTracker<TArg>
where TArg : notnull
where T : notnull
{
var options = new HandlerOptions();
configure(options);
return new DeleteRequestHandler<TArg, T>(
options,
requestBuilderSelector(item.ToRequestBuilderFactory()).Build,
item.Marshaller.Unmarshall
);
}

}

0 comments on commit d29c9c4

Please sign in to comment.