Skip to content

Commit

Permalink
Sliced endpoints in Helpdesk Marten+Wolverine example
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Sep 1, 2023
1 parent 07ff838 commit 1449c86
Show file tree
Hide file tree
Showing 31 changed files with 491 additions and 413 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bogus;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Incidents.Categorising;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Helpdesk.Api.Incidents.GetIncidentDetails;
using Helpdesk.Api.Incidents.GettingDetails;
using Ogooreck.API;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Helpdesk.Api.Incidents.GetIncidentDetails;
using Helpdesk.Api.Incidents.GettingDetails;
using Ogooreck.API;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Helpdesk.Api.Incidents.GetIncidentDetails;
using Helpdesk.Api.Incidents.GettingDetails;
using Ogooreck.API;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Bogus;
using Bogus.DataSets;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Incidents.GetIncidentDetails;
using Helpdesk.Api.Incidents.GettingDetails;
using Helpdesk.Api.Incidents.Logging;
using Helpdesk.Api.Incidents.Resolving;
using Ogooreck.API;
using static Ogooreck.API.ApiSpecification;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Bogus;
using Bogus.DataSets;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Incidents.GetIncidentDetails;
using Helpdesk.Api.Incidents.GettingDetails;
using Helpdesk.Api.Incidents.Logging;
using Xunit;
using Ogooreck.API;
using static Ogooreck.API.ApiSpecification;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bogus;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Incidents.Prioritising;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Bogus;
using Bogus.DataSets;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Incidents.GetIncidentDetails;
using Helpdesk.Api.Incidents.GettingDetails;
using Helpdesk.Api.Incidents.RecordingAgentResponse;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Bogus.DataSets;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Incidents.GetIncidentDetails;
using Helpdesk.Api.Incidents.GettingDetails;
using Helpdesk.Api.Incidents.RecordingCustomerResponse;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bogus;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Incidents.Resolving;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Helpdesk.Api.Core.Http;
using Helpdesk.Api.Core.Marten;
using Marten;
using Wolverine.Http;
using static Microsoft.AspNetCore.Http.TypedResults;
using static Helpdesk.Api.Incidents.IncidentService;

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AcknowledgingResolution/AcknowledgeResolution.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AcknowledgingResolution/AcknowledgeResolution.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AcknowledgingResolution/AcknowledgeResolution.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AcknowledgingResolution/AcknowledgeResolution.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)
using static Helpdesk.Api.Core.Http.ETagExtensions;
using static System.DateTimeOffset;

namespace Helpdesk.Api.Incidents.AcknowledgingResolution;

public static class AcknowledgeResolutionEndpoint
{
[WolverinePost("/api/customers/{customerId:guid}/incidents/{incidentId:guid}/acknowledge")]
public static async Task<IResult> AcknowledgeResolution
(
IDocumentSession documentSession,
Guid incidentId,
Guid customerId,
[FromIfMatchHeader] string eTag,
CancellationToken ct
)
{
await documentSession.GetAndUpdate<Incident>(incidentId, ToExpectedVersion(eTag),
state => Handle(state, new AcknowledgeResolution(incidentId, customerId, Now)), ct);

return Ok();
}

public static ResolutionAcknowledgedByCustomer Handle(
Incident current,
AcknowledgeResolution command
)
{
if (current.Status is not IncidentStatus.Resolved)
throw new InvalidOperationException("Only resolved incident can be acknowledged");

var (incidentId, acknowledgedBy, now) = command;

return new ResolutionAcknowledgedByCustomer(incidentId, acknowledgedBy, now);
}
}

public record AcknowledgeResolution(
Guid IncidentId,
Guid AcknowledgedBy,
DateTimeOffset Now
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Helpdesk.Api.Core.Http;
using Helpdesk.Api.Core.Marten;
using Marten;
using Wolverine.Http;
using static Microsoft.AspNetCore.Http.TypedResults;
using static Helpdesk.Api.Incidents.IncidentService;

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AssigningAgent/AssignAgent.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AssigningAgent/AssignAgent.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AssigningAgent/AssignAgent.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AssigningAgent/AssignAgent.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)
using static Helpdesk.Api.Core.Http.ETagExtensions;
using static System.DateTimeOffset;

namespace Helpdesk.Api.Incidents.AssigningAgent;

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

return Ok();
}

public static AgentAssignedToIncident Handle(Incident current, AssignAgentToIncident command)
{
if (current.Status == IncidentStatus.Closed)
throw new InvalidOperationException("Incident is already closed");

var (incidentId, agentId, now) = command;

return new AgentAssignedToIncident(incidentId, agentId, now);
}
}

public record AssignAgentToIncident(
Guid IncidentId,
Guid AgentId,
DateTimeOffset Now
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using Wolverine.Marten;
using static Microsoft.AspNetCore.Http.TypedResults;

namespace Helpdesk.Api.Incidents.Categorise;
namespace Helpdesk.Api.Incidents.Categorising;

public static class CategoriseIncidentEndpoint
public static class CategoriseEndpoint
{
[AggregateHandler]
[WolverinePost("api/agents/{agentId:guid}/incidents/{incidentId:guid}/category")]
Expand All @@ -24,3 +24,8 @@ public static class CategoriseIncidentEndpoint
return (Ok(), new Events { new IncidentCategorised(incidentId, request.Category, agentId, now) });
}
}

public record CategoriseIncidentRequest(
Guid IncidentId,
IncidentCategory Category
);
51 changes: 51 additions & 0 deletions Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Closing/Close.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Helpdesk.Api.Core.Http;
using Helpdesk.Api.Core.Marten;
using Marten;
using Wolverine.Http;
using static Microsoft.AspNetCore.Http.TypedResults;
using static Helpdesk.Api.Incidents.IncidentService;

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Closing/Close.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Closing/Close.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Closing/Close.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)

Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Closing/Close.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IncidentService' does not exist in the namespace 'Helpdesk.Api.Incidents' (are you missing an assembly reference?)
using static Helpdesk.Api.Core.Http.ETagExtensions;
using static System.DateTimeOffset;

namespace Helpdesk.Api.Incidents.Closing;

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

return Ok();
}

public static IncidentClosed Handle(
Incident current,
CloseIncident command
)
{
if (current.Status is not IncidentStatus.ResolutionAcknowledgedByCustomer)
throw new InvalidOperationException("Only incident with acknowledged resolution can be closed");

if (current.HasOutstandingResponseToCustomer)
throw new InvalidOperationException("Cannot close incident that has outstanding responses to customer");

var (incidentId, acknowledgedBy, now) = command;

return new IncidentClosed(incidentId, acknowledgedBy, now);
}
}

public record CloseIncident(
Guid IncidentId,
Guid ClosedBy,
DateTimeOffset Now
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Helpdesk.Api.Incidents.GettingShortInfo;
using Marten;
using Marten.Pagination;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;

namespace Helpdesk.Api.Incidents.GettingCustomerIncidents;

public static class GetCustomerIncidentsEndpoints
{
[WolverineGet("/api/customers/{customerId:guid}/incidents/")]
public static Task<IPagedList<IncidentShortInfo>> GetCustomerIncidents
(IQuerySession querySession, [FromRoute] Guid customerId, [FromQuery] int? pageNumber, [FromQuery] int? pageSize,
CancellationToken ct) =>
querySession.Query<IncidentShortInfo>().Where(i => i.CustomerId == customerId)
.ToPagedListAsync(pageNumber ?? 1, pageSize ?? 10, ct);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Marten.Events.Aggregation;

namespace Helpdesk.Api.Incidents.GetIncidentShortInfo;
namespace Helpdesk.Api.Incidents.GettingShortInfo;

public record IncidentShortInfo(
Guid Id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Marten;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;

namespace Helpdesk.Api.Incidents.GettingCustomerIncidentsSummary;

public static class GetCustomerIncidentsSummaryEndpoint
{
// That for some reason doesn't work for me
// [WolverineGet("/api/customers/{customerId:guid}/incidents/incidents-summary")]
// public static Task GetCustomerIncidentsSummary([FromRoute] Guid customerId, HttpContext context,
// IQuerySession querySession) =>
// querySession.Json.WriteById<CustomerIncidentsSummary>(customerId, context);

[WolverineGet("/api/customers/{customerId:guid}/incidents/incidents-summary")]
public static Task<CustomerIncidentsSummary?> GetCustomerIncidentsSummary(
[FromRoute] Guid customerId,
IQuerySession querySession,
CancellationToken ct
) =>
querySession.LoadAsync<CustomerIncidentsSummary>(customerId, ct);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Marten.Events.Aggregation;
using Marten.Events.Projections;

namespace Helpdesk.Api.Incidents.GetCustomerIncidentsSummary;
namespace Helpdesk.Api.Incidents.GettingCustomerIncidentsSummary;

public class CustomerIncidentsSummary
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Marten;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;

namespace Helpdesk.Api.Incidents.GettingDetails;

public static class GetDetailsEndpoints
{
// That for some reason doesn't work for me
// [WolverineGet("/api/incidents/{incidentId:guid}")]
// public static Task GetIncidentById([FromRoute] Guid incidentId, IQuerySession querySession, HttpContext context) =>
// querySession.Json.WriteById<IncidentDetails>(incidentId, context);

[WolverineGet("/api/incidents/{incidentId:guid}")]
public static Task<IncidentDetails?> GetDetails([FromRoute] Guid incidentId, IQuerySession querySession,
CancellationToken ct) =>
querySession.LoadAsync<IncidentDetails>(incidentId, ct);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Marten.Events.Aggregation;

namespace Helpdesk.Api.Incidents.GetIncidentDetails;
namespace Helpdesk.Api.Incidents.GettingDetails;

public record IncidentDetails(
Guid Id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Marten;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;

namespace Helpdesk.Api.Incidents.GettingHistory;

public static class GetHistoryEndpoint
{
//That for some reason doesn't work for me
// [WolverineGet("/api/incidents/{incidentId:guid}/history")]
// public static Task GetIncidentHistory([FromRoute]Guid incidentId, HttpContext context, IQuerySession querySession) =>
// querySession.Query<IncidentHistory>().Where(i => i.IncidentId == incidentId).WriteArray(context);

[WolverineGet("/api/incidents/{incidentId:guid}/history")]
public static Task<IReadOnlyList<IncidentHistory>> GetHistory(
[FromRoute] Guid incidentId,
IQuerySession querySession,
CancellationToken ct
) =>
querySession.Query<IncidentHistory>().Where(i => i.IncidentId == incidentId).ToListAsync(ct);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Marten.Events.Projections;
using Marten.Schema.Identity;

namespace Helpdesk.Api.Incidents.GetIncidentHistory;
namespace Helpdesk.Api.Incidents.GettingHistory;

public record IncidentHistory(
Guid Id,
Expand Down

0 comments on commit 1449c86

Please sign in to comment.