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 35261ab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
1 change: 1 addition & 0 deletions Sample/Helpdesk.Wolverine/Helpdesk.Api/Helpdesk.Api.csproj
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="Marten" Version="6.0.5" />
<PackageReference Include="Confluent.Kafka" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="WolverineFx.Http" Version="1.3.0" />
<PackageReference Include="WolverineFx.Marten" Version="1.3.0" />
</ItemGroup>
Expand Down
Expand Up @@ -9,33 +9,53 @@
using Marten.AspNetCore;
using Marten.Pagination;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using Wolverine.Http;
using static Microsoft.AspNetCore.Http.TypedResults;
using static Helpdesk.Api.Incidents.IncidentService;
using static Helpdesk.Api.Core.Http.ETagExtensions;
using static System.DateTimeOffset;

namespace Helpdesk.Api.Incidents;

public static class IncidentsApi
public static class IncidentsEndpoints
{
public static void MapIncidentsEndpoints(this WebApplication app)
[SwaggerOperation(Tags = new[] { "Incidents" })]
[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 35261ab

Please sign in to comment.