Skip to content

Commit

Permalink
Moved LogIncident to Wolverine endpoint from ASP.NET one
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Aug 2, 2023
1 parent b2bc7e3 commit 247de18
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
49 changes: 34 additions & 15 deletions Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/IncidentsApi.cs
Expand Up @@ -9,6 +9,7 @@
using Marten.AspNetCore;
using Marten.Pagination;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;
using static Microsoft.AspNetCore.Http.TypedResults;
using static Helpdesk.Api.Incidents.IncidentService;
using static Helpdesk.Api.Core.Http.ETagExtensions;
Expand All @@ -18,24 +19,42 @@ namespace Helpdesk.Api.Incidents;

public static class IncidentsApi
{
public static void MapIncidentsEndpoints(this WebApplication app)

[WolverinePost("/api/customers/{customerId:guid}/incidents")]
public static async Task<IResult> LogIncident
(
Guid customerId,
LogIncidentRequest body,
IDocumentSession documentSession,
CancellationToken ct)
{
app.MapPost("/api/customers/{customerId:guid}/incidents",
async (
IDocumentSession documentSession,
Guid customerId,
LogIncidentRequest body,
CancellationToken ct) =>
{
var (contact, description) = body;
var incidentId = CombGuidIdGeneration.NewGuid();
var (contact, description) = body;
var incidentId = CombGuidIdGeneration.NewGuid();

await documentSession.Add<Incident>(incidentId,
Handle(new LogIncident(incidentId, customerId, contact, description, customerId, Now)), ct);
await documentSession.Add<Incident>(incidentId,
Handle(new LogIncident(incidentId, customerId, contact, description, customerId, Now)), ct);

return Created($"/api/incidents/{incidentId}", incidentId);
}
);
return Created($"/api/incidents/{incidentId}", incidentId);
}

public static void MapIncidentsEndpoints(this WebApplication app)
{
// app.MapPost("/api/customers/{customerId:guid}/incidents",
// async (
// IDocumentSession documentSession,
// Guid customerId,
// LogIncidentRequest body,
// CancellationToken ct) =>
// {
// var (contact, description) = body;
// var incidentId = CombGuidIdGeneration.NewGuid();
//
// await documentSession.Add<Incident>(incidentId,
// Handle(new LogIncident(incidentId, customerId, contact, description, customerId, Now)), ct);
//
// return Created($"/api/incidents/{incidentId}", incidentId);
// }
// );

app.MapPost("/api/agents/{agentId:guid}/incidents/{incidentId:guid}/category",
(
Expand Down
7 changes: 7 additions & 0 deletions Sample/Helpdesk.Wolverine/Helpdesk.Api/Program.cs
Expand Up @@ -13,8 +13,10 @@
using Marten.Services.Json;
using Microsoft.AspNetCore.SignalR;
using Oakton;
using Oakton.Resources;
using Weasel.Core;
using Wolverine;
using Wolverine.Http;
using Wolverine.Marten;
using JsonOptions = Microsoft.AspNetCore.Http.Json.JsonOptions;

Expand Down Expand Up @@ -59,6 +61,8 @@
// Add Marten/PostgreSQL integration with Wolverine's outbox
.IntegrateWithWolverine();

builder.Services.AddResourceSetupOnStartup();

builder.Services
.AddCors(options =>
options.AddPolicy("ClientPermission", policy =>
Expand Down Expand Up @@ -91,6 +95,9 @@
app.UseCors("ClientPermission");
app.MapHub<IncidentsHub>("/hubs/incidents");

// Let's add in Wolverine HTTP endpoints to the routing tree
app.MapWolverineEndpoints();

return await app.RunOaktonCommands(args);

public class IncidentsHub: Hub
Expand Down

0 comments on commit 247de18

Please sign in to comment.