Skip to content

Commit

Permalink
Added unresolve feature
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Feb 6, 2024
1 parent a05d540 commit 3c94996
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class IncidentShortInfoProjection: SingleStreamProjection<IncidentShortIn
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 };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public IncidentHistory Transform(IEvent<IncidentResolved> input)
);
}

public IncidentHistory Transform(IEvent<IncidentUnresolved> 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<ResolutionAcknowledgedByCustomer> input)
{
var (incidentId, acknowledgedBy, acknowledgedAt) = input.Data;
Expand Down
10 changes: 10 additions & 0 deletions Sample/Helpdesk.Wolverine/Helpdesk.Api/Incidents/Incident.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -86,6 +93,9 @@ public record Incident(
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 };

Expand Down
Original file line number Diff line number Diff line change
@@ -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) Resolve
(
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
);

0 comments on commit 3c94996

Please sign in to comment.