diff --git a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingCustomerIncidents/IncidentShortInfo.cs b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingCustomerIncidents/IncidentShortInfo.cs index cb46f2f15..00eabcba9 100644 --- a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingCustomerIncidents/IncidentShortInfo.cs +++ b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingCustomerIncidents/IncidentShortInfo.cs @@ -31,6 +31,9 @@ public IncidentShortInfo Apply(CustomerRespondedToIncident customerResponded, In public IncidentShortInfo Apply(IncidentResolved resolved, IncidentShortInfo current) => current with { Status = IncidentStatus.Resolved }; + public IncidentShortInfo Apply(IncidentUnresolved unresolved, IncidentShortInfo current) => + current with { Status = IncidentStatus.Pending, NotesCount = current.NotesCount + 1 }; + public IncidentShortInfo Apply(ResolutionAcknowledgedByCustomer acknowledged, IncidentShortInfo current) => current with { Status = IncidentStatus.ResolutionAcknowledgedByCustomer }; diff --git a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingDetails/IncidentDetails.cs b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingDetails/IncidentDetails.cs index b9de7826f..b410ca22b 100644 --- a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingDetails/IncidentDetails.cs +++ b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingDetails/IncidentDetails.cs @@ -73,6 +73,22 @@ current with public IncidentDetails Apply(IncidentResolved resolved, IncidentDetails current) => current with { Status = IncidentStatus.Resolved }; + public IncidentDetails Apply(IncidentUnresolved unresolved, IncidentDetails current) => + current with + { + Status = IncidentStatus.Pending, + Notes = current.Notes.Union( + new[] + { + new IncidentNote( + IncidentNoteType.FromCustomer, + unresolved.UnresolvedBy, + unresolved.Reason, + true + ) + }).ToArray() + }; + public IncidentDetails Apply(ResolutionAcknowledgedByCustomer acknowledged, IncidentDetails current) => current with { Status = IncidentStatus.ResolutionAcknowledgedByCustomer }; diff --git a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingHistory/IncidentHistory.cs b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingHistory/IncidentHistory.cs index 7962392c6..1eba1ae22 100644 --- a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingHistory/IncidentHistory.cs +++ b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/GettingHistory/IncidentHistory.cs @@ -91,6 +91,17 @@ public IncidentHistory Transform(IEvent input) ); } + public IncidentHistory Transform(IEvent input) + { + var (incidentId, reason, unresolvedBy, resolvedAt) = input.Data; + + return new IncidentHistory( + CombGuidIdGeneration.NewGuid(), + incidentId, + $"[{resolvedAt}] Unresolved Incident with id: '{incidentId}' with reason `{reason} by '{unresolvedBy}'" + ); + } + public IncidentHistory Transform(IEvent input) { var (incidentId, acknowledgedBy, acknowledgedAt) = input.Data; diff --git a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Incident.cs b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Incident.cs index 38d2c0fce..6f2b1fa3a 100644 --- a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Incident.cs +++ b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Incident.cs @@ -48,6 +48,13 @@ public record IncidentResolved( DateTimeOffset ResolvedAt ); +public record IncidentUnresolved( + Guid IncidentId, + string Reason, + Guid UnresolvedBy, + DateTimeOffset UnresolvedAt +); + public record ResolutionAcknowledgedByCustomer( Guid IncidentId, Guid AcknowledgedBy, @@ -86,6 +93,9 @@ public Incident Apply(CustomerRespondedToIncident customerResponded) => public Incident Apply(IncidentResolved resolved) => this with { Status = IncidentStatus.Resolved }; + public Incident Apply(IncidentUnresolved unresolved) => + this with { Status = IncidentStatus.Pending }; + public Incident Apply(ResolutionAcknowledgedByCustomer acknowledged) => this with { Status = IncidentStatus.ResolutionAcknowledgedByCustomer }; diff --git a/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Unresolving/Unresolve.cs b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Unresolving/Unresolve.cs new file mode 100644 index 000000000..3ac92297d --- /dev/null +++ b/Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Unresolving/Unresolve.cs @@ -0,0 +1,33 @@ +using Wolverine.Http; +using Wolverine.Marten; +using static Microsoft.AspNetCore.Http.TypedResults; + +namespace Helpdesk.Api.Incidents.Unresolving; + +public static class UnResolveEndpoint +{ + [AggregateHandler] + [WolverinePost("/api/agents/{agentId:guid}/incidents/{incidentId:guid}/unresolve")] + public static (IResult, Events) Unresolve + ( + UnesolveIncident command, + Incident incident, + DateTimeOffset now + ) + { + if (incident.Status is IncidentStatus.Closed) + throw new InvalidOperationException("Cannot unresolve already closed incident"); + + if (incident.HasOutstandingResponseToCustomer) + throw new InvalidOperationException("Cannot resolve incident that has outstanding responses to customer"); + + return (Ok(), [new IncidentUnresolved(incident.Id, command.Reason, command.AgentId, now)]); + } +} + +public record UnesolveIncident( + Guid IncidentId, + Guid AgentId, + string Reason, + int Version +);