From b5c76e884a18804c05fa88393cacf0977e28148a Mon Sep 17 00:00:00 2001 From: Oskar Dudycz Date: Wed, 2 Aug 2023 15:47:54 +0200 Subject: [PATCH] Refactored LogIncident to use Wolverine start stream --- .../Helpdesk.Api/Incidents/IncidentsEndpoints.cs | 15 ++++++--------- Sample/Helpdesk.Wolverine/Helpdesk.Api/Program.cs | 5 ++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/IncidentsEndpoints.cs b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/IncidentsEndpoints.cs index a8ea28c7d..4abda386f 100644 --- a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/IncidentsEndpoints.cs +++ b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/IncidentsEndpoints.cs @@ -3,6 +3,7 @@ using JasperFx.Core; using Marten; using Wolverine.Http; +using Wolverine.Marten; using static Microsoft.AspNetCore.Http.TypedResults; using static Helpdesk.Api.Incidents.IncidentService; using static Helpdesk.Api.Core.Http.ETagExtensions; @@ -13,20 +14,16 @@ namespace Helpdesk.Api.Incidents; public static class IncidentsEndpoints { [WolverinePost("/api/customers/{customerId:guid}/incidents")] - public static async Task LogIncident - ( - Guid customerId, - LogIncidentRequest body, - IDocumentSession documentSession, - CancellationToken ct) + public static (CreationResponse, IStartStream) LogIncident(Guid customerId, LogIncidentRequest body) { var (contact, description) = body; var incidentId = CombGuidIdGeneration.NewGuid(); - await documentSession.Add(incidentId, - Handle(new LogIncident(incidentId, customerId, contact, description, customerId, Now)), ct); + var result = Handle(new LogIncident(incidentId, customerId, contact, description, customerId, Now)); + + var startStream = MartenOps.StartStream(result); - return Created($"/api/incidents/{incidentId}", incidentId); + return (new CreationResponse($"/api/incidents/{startStream.StreamId}"), startStream); } [WolverinePost("/api/agents/{agentId:guid}/incidents/{incidentId:guid}/category")] diff --git a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Program.cs b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Program.cs index 98dffbb05..9a4baf032 100644 --- a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Program.cs +++ b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Program.cs @@ -80,7 +80,10 @@ builder.Host.ApplyOaktonExtensions(); // Configure Wolverine -builder.Host.UseWolverine(); +builder.Host.UseWolverine(opts => +{ + opts.Policies.AutoApplyTransactions(); +}); var app = builder.Build();