Skip to content

Commit

Permalink
Refactored LogIncident to use Wolverine start stream
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Aug 2, 2023
1 parent 7ccceb7 commit b5c76e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Expand Up @@ -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;
Expand All @@ -13,20 +14,16 @@ namespace Helpdesk.Api.Incidents;
public static class IncidentsEndpoints
{
[WolverinePost("/api/customers/{customerId:guid}/incidents")]
public static async Task<IResult> 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<Incident>(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<Incident>(result);

return Created($"/api/incidents/{incidentId}", incidentId);
return (new CreationResponse($"/api/incidents/{startStream.StreamId}"), startStream);
}

[WolverinePost("/api/agents/{agentId:guid}/incidents/{incidentId:guid}/category")]
Expand Down
5 changes: 4 additions & 1 deletion Sample/Helpdesk.Wolverine/Helpdesk.Api/Program.cs
Expand Up @@ -80,7 +80,10 @@

builder.Host.ApplyOaktonExtensions();
// Configure Wolverine
builder.Host.UseWolverine();
builder.Host.UseWolverine(opts =>
{
opts.Policies.AutoApplyTransactions();
});

var app = builder.Build();

Expand Down

0 comments on commit b5c76e8

Please sign in to comment.