-
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
- Loading branch information
There are no files selected for viewing
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 GitHub Actions / build
Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AcknowledgingResolution/AcknowledgeResolution.cs GitHub Actions / build
Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AcknowledgingResolution/AcknowledgeResolution.cs GitHub Actions / build
Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AcknowledgingResolution/AcknowledgeResolution.cs GitHub Actions / build
|
||
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 GitHub Actions / build
Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AssigningAgent/AssignAgent.cs GitHub Actions / build
Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AssigningAgent/AssignAgent.cs GitHub Actions / build
Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/AssigningAgent/AssignAgent.cs GitHub Actions / build
|
||
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 |
---|---|---|
@@ -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 GitHub Actions / build
Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Closing/Close.cs GitHub Actions / build
Check failure on line 6 in Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Closing/Close.cs GitHub Actions / build
|
||
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 |
---|---|---|
@@ -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 |
---|---|---|
@@ -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 |
---|---|---|
@@ -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); | ||
} |