Skip to content

Commit

Permalink
Moved Categorise endpoint to Wolverine
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Aug 30, 2023
1 parent 62abac3 commit d0b887c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ await API
.When(
POST,
URI($"/api/agents/{agentId}/incidents/{API.Incident.Id}/category"),
BODY(new CategoriseIncidentRequest(category)),
BODY(new CategoriseIncidentRequest(API.Incident.Id, category)),
HEADERS(IF_MATCH(1))
)
.Then(OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;
using Wolverine.Marten;

namespace Helpdesk.Api.Incidents.Categorise;

public static class CategoriseIncidentEndpoint
{
[AggregateHandler]
[WolverinePost("api/agents/{agentId:guid}/incidents/{incidentId:guid}/category")]
public static IncidentCategorised Post(
CategoriseIncidentRequest request,
Incident incident,
[FromRoute] Guid agentId,
[FromRoute] Guid incidentId,
DateTimeOffset now)
{
if (incident.Status == IncidentStatus.Closed)
{
throw new InvalidOperationException("Incident is already closed");
}

return new IncidentCategorised(incident.Id, request.Category, agentId, now);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,6 @@ namespace Helpdesk.Api.Incidents;

public static class IncidentsEndpoints
{
[WolverinePost("/api/agents/{agentId:guid}/incidents/{incidentId:guid}/category")]
public static async Task<IResult> CategoriseIncident
(
IDocumentSession documentSession,
Guid incidentId,
Guid agentId,
[FromIfMatchHeader] string eTag,
CategoriseIncidentRequest body,
CancellationToken ct
)
{
await documentSession.GetAndUpdate<Incident>(incidentId, ToExpectedVersion(eTag),
state => Handle(state, new CategoriseIncident(incidentId, body.Category, agentId, Now)), ct);

return Ok();
}

[WolverinePost("/api/agents/{agentId:guid}/incidents/{incidentId:guid}/priority")]
public static async Task<IResult> PrioritiseIncident
(
Expand Down Expand Up @@ -159,6 +142,7 @@ string Description
);

public record CategoriseIncidentRequest(
Guid IncidentId,
IncidentCategory Category
);

Expand Down

0 comments on commit d0b887c

Please sign in to comment.