From 4300147e6231495f6323d393035627eacbbba56c Mon Sep 17 00:00:00 2001 From: "Eric J. Smith" Date: Mon, 22 Sep 2025 14:27:41 -0500 Subject: [PATCH] Use result coercing --- .../DispatcherEndpoint.cs | 2 +- .../EntityCommandHandler.cs | 14 +++++++------- .../EntityQueryHandler.cs | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Foundatio.CommandQuery.Endpoints/DispatcherEndpoint.cs b/src/Foundatio.CommandQuery.Endpoints/DispatcherEndpoint.cs index 75e21eb..7140bc5 100644 --- a/src/Foundatio.CommandQuery.Endpoints/DispatcherEndpoint.cs +++ b/src/Foundatio.CommandQuery.Endpoints/DispatcherEndpoint.cs @@ -72,7 +72,7 @@ protected virtual async Task Send( try { - var result = await mediator.InvokeAsync(request, cancellationToken).ConfigureAwait(false); + var result = await mediator.InvokeAsync(request, cancellationToken).ConfigureAwait(false); return TypedResults.Ok(result); } catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) diff --git a/src/Foundatio.CommandQuery.EntityFramework/EntityCommandHandler.cs b/src/Foundatio.CommandQuery.EntityFramework/EntityCommandHandler.cs index 86033fe..5580aad 100644 --- a/src/Foundatio.CommandQuery.EntityFramework/EntityCommandHandler.cs +++ b/src/Foundatio.CommandQuery.EntityFramework/EntityCommandHandler.cs @@ -83,9 +83,9 @@ await DataContext .ConfigureAwait(false); if (result == null) - return Result.NotFound("Could not map read model."); + return Result.NotFound("Could not map read model."); - return Result.Success(result); + return result; } public virtual async ValueTask> HandleAsync( @@ -105,7 +105,7 @@ public virtual async ValueTask> HandleAsync( : default; if (entity == null && !request.Upsert) - return Result.NotFound($"Entity with id '{request.Id}' not found."); + return Result.NotFound($"Entity with id '{request.Id}' not found."); // create entity if not found if (entity == null) @@ -153,9 +153,9 @@ await DataContext .ConfigureAwait(false); if (result == null) - return Result.NotFound("Could not map read model."); + return Result.NotFound("Could not map read model."); - return Result.Success(result); + return result; } public virtual async ValueTask> HandleAsync( @@ -173,7 +173,7 @@ public virtual async ValueTask> HandleAsync( .ConfigureAwait(false); if (entity == null) - return Result.NotFound($"Entity with id '{request.Id}' not found."); + return Result.NotFound($"Entity with id '{request.Id}' not found."); // read the entity before deleting it var query = DataContext @@ -222,6 +222,6 @@ await DataContext .SaveChangesAsync(cancellationToken) .ConfigureAwait(false); - return Result.Success(result); + return result; } } diff --git a/src/Foundatio.CommandQuery.EntityFramework/EntityQueryHandler.cs b/src/Foundatio.CommandQuery.EntityFramework/EntityQueryHandler.cs index 55cf2bc..9e5c033 100644 --- a/src/Foundatio.CommandQuery.EntityFramework/EntityQueryHandler.cs +++ b/src/Foundatio.CommandQuery.EntityFramework/EntityQueryHandler.cs @@ -67,9 +67,9 @@ public virtual async ValueTask> HandleAsync( .ConfigureAwait(false); if (result == null) - return Result.NotFound($"Entity with id '{request.Id}' not found."); + return Result.NotFound($"Entity with id '{request.Id}' not found."); - return Result.Success(result); + return result; } public virtual async ValueTask>> HandleAsync( @@ -92,7 +92,7 @@ public virtual async ValueTask>> HandleAsync( .ToListAsync(cancellationToken) .ConfigureAwait(false); - return Result>.Success(results); + return results; } public virtual async ValueTask>> HandleAsync( @@ -124,7 +124,7 @@ public virtual async ValueTask>> HandleAsync( // short circuit if total is zero if (total == 0) - return Result>.Success(new()); + return new QueryResult(); query = query.Page(queryDefinition.Page.Value, queryDefinition.PageSize.Value); } @@ -142,6 +142,6 @@ public virtual async ValueTask>> HandleAsync( Data = results }; - return Result>.Success(queryResult); + return queryResult; } }