Skip to content

Commit

Permalink
docs(samples): update helpdesk as web api
Browse files Browse the repository at this point in the history
  • Loading branch information
skarllot committed Aug 27, 2023
1 parent 160f0dc commit f21a936
Show file tree
Hide file tree
Showing 47 changed files with 809 additions and 69 deletions.
28 changes: 28 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/.github
**/.idea*
**/artifacts
LICENSE
README.md
1 change: 1 addition & 0 deletions Expressions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".root", ".root", "{7721DE8D
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
version.json = version.json
docker-compose.yml = docker-compose.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4695B427-BD61-4FA2-A3F4-995AC92C9B02}"
Expand Down
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "3"
services:
helpdesk-relational-app:
image: raiqub.samples.helpdesk-relational
build:
context: .
dockerfile: samples/Helpdesk.Relational/Dockerfile
ports:
- "8080:80"
environment:
ASPNETCORE_ENVIRONMENT: Development
depends_on:
- helpdesk-relational-db
- helpdesk-relational-pgadmin

helpdesk-relational-db:
image: clkao/postgres-plv8
environment:
POSTGRES_PASSWORD: Password12!

helpdesk-relational-pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- pgadmin:/var/lib/pgadmin
ports:
- "${PGADMIN_PORT:-5050}:80"
depends_on:
- helpdesk-relational-db

volumes:
pgadmin:
19 changes: 19 additions & 0 deletions samples/Helpdesk.Relational/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY . .
WORKDIR "/src/samples/Helpdesk.Relational"
RUN dotnet restore
RUN dotnet build "Helpdesk.Relational.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Helpdesk.Relational.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Raiqub.Helpdesk.Relational.dll"]
11 changes: 9 additions & 2 deletions samples/Helpdesk.Relational/Helpdesk.Relational.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Expressions.Writing\Expressions.Writing.csproj" />
<ProjectReference Include="..\..\src\Expressions.EntityFrameworkCore\Expressions.EntityFrameworkCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.8" />
<PackageReference Include="RT.Comb" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions samples/Helpdesk.Relational/HelpdeskDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Helpdesk.Relational.Incidents;
using Helpdesk.Relational.Incidents.Categorise;
using Helpdesk.Relational.Incidents.LogNew;
using Helpdesk.Relational.Incidents.Prioritise;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Helpdesk.Relational;

public class HelpdeskDbContext : DbContext
{
public HelpdeskDbContext(DbContextOptions<HelpdeskDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var incidentBuilder = modelBuilder.Entity<Incident>();

incidentBuilder.Property(i => i.Id);
incidentBuilder.Property(i => i.CustomerId);
incidentBuilder.Property(i => i.Description);
incidentBuilder.Property(i => i.LoggedBy);
incidentBuilder.Property(i => i.LoggedAt);
incidentBuilder.Property(i => i.Status).HasConversion<EnumToStringConverter<IncidentStatus>>();
incidentBuilder.Property(i => i.Category).HasConversion<EnumToStringConverter<IncidentCategory>>();
incidentBuilder.Property(i => i.Priority).HasConversion<EnumToStringConverter<IncidentPriority>>();
incidentBuilder.HasKey(i => i.Id);

incidentBuilder.OwnsOne(i => i.Contact)
.Property(c => c.ContactChannel).HasConversion<EnumToStringConverter<ContactChannel>>();
incidentBuilder.HasMany(i => i.Responses).WithOne();

incidentBuilder.Navigation(i => i.Responses).AutoInclude();

var responseBuilder = modelBuilder.Entity<IncidentResponse>();
responseBuilder.Property<int>("Id");
responseBuilder.HasKey("Id");

responseBuilder.HasDiscriminator<string>("type")
.HasValue<IncidentResponse.FromAgent>("agent")
.HasValue<IncidentResponse.FromCustomer>("customer");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Helpdesk.Relational.Incidents.Acknowledge;

public static class AcknowledgeHandler
public static class AcknowledgeScenario
{
public static ResolutionAcknowledgedByCustomer Handle(Incident current, AcknowledgeResolution command)
public static ResolutionAcknowledgedByCustomer Execute(Incident current, AcknowledgeResolution command)
{
if (current.IsSatisfiedBy(IncidentSpecification.IsNotResolved))
throw new IncidentIsNotResolvedException(command.IncidentId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Raiqub.Expressions.Sessions;

namespace Helpdesk.Relational.Incidents.Acknowledge.v1;

public class AcknowledgeIncidentResolutionUseCase
{
private readonly IDbSession _dbSession;

public AcknowledgeIncidentResolutionUseCase(IDbSession dbSession)
{
_dbSession = dbSession;
}

public async Task Execute(Guid incidentId, Guid customerId, CancellationToken cancellationToken)
{
var incident = await _dbSession.Query(IncidentSpecification.HasId(incidentId)).FirstAsync(cancellationToken);
incident.Apply(AcknowledgeScenario.Execute(incident, new AcknowledgeResolution(incidentId, customerId)));

_dbSession.Update(incident);
await _dbSession.SaveChangesAsync(cancellationToken);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Helpdesk.Relational.Incidents.AssignAgent;

public static class AssignAgentHandler
public static class AssignAgentScenario
{
public static AgentAssignedToIncident Handle(Incident current, AssignAgentToIncident command)
public static AgentAssignedToIncident Execute(Incident current, AssignAgentToIncident command)
{
if (current.IsSatisfiedBy(IncidentSpecification.IsClosed))
throw new IncidentAlreadyClosedException(command.IncidentId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Raiqub.Expressions.Sessions;

namespace Helpdesk.Relational.Incidents.AssignAgent.v1;

public class AssignAgentToIncidentUseCase
{
private readonly IDbSession _dbSession;

public AssignAgentToIncidentUseCase(IDbSession dbSession)
{
_dbSession = dbSession;
}

public async Task Execute(Guid incidentId, Guid agentId, CancellationToken cancellationToken)
{
var incident = await _dbSession.Query(IncidentSpecification.HasId(incidentId)).FirstAsync(cancellationToken);
incident.Apply(AssignAgentScenario.Execute(incident, new AssignAgentToIncident(incidentId, agentId)));

_dbSession.Update(incident);
await _dbSession.SaveChangesAsync(cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Helpdesk.Relational.Incidents.Categorise;

public static class CategoriseHandler
public static class CategoriseScenario
{
public static IncidentCategorised Handle(Incident current, CategoriseIncident command)
public static IncidentCategorised Execute(Incident current, CategoriseIncident command)
{
if (current.IsSatisfiedBy(IncidentSpecification.IsClosed))
throw new IncidentAlreadyClosedException(command.IncidentId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Helpdesk.Relational.Incidents.Categorise.v1;

public record CategoriseIncidentRequest(IncidentCategory Category);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Raiqub.Expressions.Sessions;

namespace Helpdesk.Relational.Incidents.Categorise.v1;

public class CategoriseIncidentUseCase
{
private readonly IDbSession _dbSession;

public CategoriseIncidentUseCase(IDbSession dbSession)
{
_dbSession = dbSession;
}

public async Task Execute(
Guid incidentId,
Guid agentId,
CategoriseIncidentRequest request,
CancellationToken cancellationToken)
{
var incident = await _dbSession.Query(IncidentSpecification.HasId(incidentId)).FirstAsync(cancellationToken);
incident.Apply(
CategoriseScenario.Execute(incident, new CategoriseIncident(incidentId, request.Category, agentId)));

_dbSession.Update(incident);
await _dbSession.SaveChangesAsync(cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Helpdesk.Relational.Incidents.Close;

public static class CloseHandler
public static class CloseScenario
{
public static IncidentClosed Handle(Incident current, CloseIncident command)
public static IncidentClosed Execute(Incident current, CloseIncident command)
{
if (current.Status is not IncidentStatus.ResolutionAcknowledgedByCustomer)
throw new IncidentIsNotAcknowledgedException(command.IncidentId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Raiqub.Expressions.Sessions;

namespace Helpdesk.Relational.Incidents.Close.v1;

public class CloseIncidentUseCase
{
private readonly IDbSession _dbSession;

public CloseIncidentUseCase(IDbSession dbSession)
{
_dbSession = dbSession;
}

public async Task Execute(Guid incidentId, Guid agentId, CancellationToken cancellationToken)
{
var incident = await _dbSession.Query(IncidentSpecification.HasId(incidentId)).FirstAsync(cancellationToken);
incident.Apply(CloseScenario.Execute(incident, new CloseIncident(incidentId, agentId)));

_dbSession.Update(incident);
await _dbSession.SaveChangesAsync(cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Helpdesk.Relational.Incidents.GetCustomerSummary;

public record CustomerIncidentsSummary(Guid Id)
{
public int Pending { get; init; }
public int Resolved { get; init; }
public int Acknowledged { get; init; }
public int Closed { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Raiqub.Expressions.Queries;

namespace Helpdesk.Relational.Incidents.GetCustomerSummary;

public class GetCustomerIncidentsSummaryQueryModel : IQueryModel<(IncidentStatus Key, int Count)>
{
public GetCustomerIncidentsSummaryQueryModel(Guid customerId) => CustomerId = customerId;

public Guid CustomerId { get; }

public IQueryable<(IncidentStatus Key, int Count)> Execute(IQuerySource source)
{
return from pending in source.GetSet<Incident>()
where pending.CustomerId == CustomerId
group pending by pending.Status
into g
select new ValueTuple<IncidentStatus, int>(g.Key, g.Count());
}
}
Loading

0 comments on commit f21a936

Please sign in to comment.