Skip to content

Commit

Permalink
Outbox + Notifications Module (#2)
Browse files Browse the repository at this point in the history
* added custom Inbox/Outbox implementation using Quartz.NET (changed migrations)
* refactored modules (module and module with endpoints), added notifications module
* fixed dependency tests
* fixed configurations (MassTransit)
* added endpoint group builder and refactored endpoints
* added waiting for integrating event handling in E2E tests
* updated packages
* refactoring (namespaces, typos ...)
* additional fixes
  • Loading branch information
skrasekmichael committed Apr 20, 2024
1 parent 7b0ce37 commit c80e541
Show file tree
Hide file tree
Showing 151 changed files with 2,298 additions and 1,343 deletions.
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="TeamUp.Tests.EndToEnd" />
</ItemGroup>
</Project>
12 changes: 7 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageVersion Include="Bogus" Version="35.5.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.30.0" />
<PackageVersion Include="FluentAssertions.Web" Version="1.2.5" />
<PackageVersion Include="FluentAssertions.Web" Version="1.3.0" />
<PackageVersion Include="FluentValidation" Version="11.9.0" />
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
<PackageVersion Include="MailKit" Version="4.4.0" />
Expand All @@ -27,7 +27,7 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Identity.Stores" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
Expand All @@ -37,12 +37,14 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="NetArchTest.Rules" Version="1.3.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageVersion Include="Quartz" Version="3.8.1" />
<PackageVersion Include="Quartz.Extensions.Hosting" Version="3.8.1" />
<PackageVersion Include="RabbitMQ.Client" Version="6.8.1" />
<PackageVersion Include="Respawn" Version="6.2.1" />
<PackageVersion Include="Riok.Mapperly" Version="3.3.0" />
<PackageVersion Include="Skrasek.RailwayResult" Version="1.0.4" />
<PackageVersion Include="Skrasek.RailwayResult.Errors" Version="1.0.4" />
<PackageVersion Include="Skrasek.RailwayResult.FunctionalExtensions" Version="1.0.4" />
<PackageVersion Include="Skrasek.RailwayResult" Version="1.1.0" />
<PackageVersion Include="Skrasek.RailwayResult.Errors" Version="1.1.0" />
<PackageVersion Include="Skrasek.RailwayResult.FunctionalExtensions" Version="1.1.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.1.2" />
<PackageVersion Include="Testcontainers" Version="3.8.0" />
Expand Down
24 changes: 24 additions & 0 deletions TeamUp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.TeamManagement.Endpo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.TeamManagement.Infrastructure", "src\Modules\TeamManagement\TeamUp.TeamManagement.Infrastructure\TeamUp.TeamManagement.Infrastructure.csproj", "{5A322584-C568-46BB-8D3E-2D80C0236249}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notifications", "Notifications", "{86FE1981-2361-4417-89F3-90CE0DC21692}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamUp.Notifications.Application", "src\Modules\Notifications\TeamUp.Notifications.Application\TeamUp.Notifications.Application.csproj", "{256074E6-3736-41D1-8F44-6EB9EC25E151}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamUp.Notifications.Contracts", "src\Modules\Notifications\TeamUp.Notifications.Contracts\TeamUp.Notifications.Contracts.csproj", "{25BE033F-3973-4BC8-8C1D-246C3C4AD3C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamUp.Notifications.Infrastructure", "src\Modules\Notifications\TeamUp.Notifications.Infrastructure\TeamUp.Notifications.Infrastructure.csproj", "{4A940BAC-8B19-4167-95C2-944394502CA1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -150,6 +158,18 @@ Global
{6DC6465B-FDC2-4637-99E3-31B77725B016}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DC6465B-FDC2-4637-99E3-31B77725B016}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DC6465B-FDC2-4637-99E3-31B77725B016}.Release|Any CPU.Build.0 = Release|Any CPU
{256074E6-3736-41D1-8F44-6EB9EC25E151}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{256074E6-3736-41D1-8F44-6EB9EC25E151}.Debug|Any CPU.Build.0 = Debug|Any CPU
{256074E6-3736-41D1-8F44-6EB9EC25E151}.Release|Any CPU.ActiveCfg = Release|Any CPU
{256074E6-3736-41D1-8F44-6EB9EC25E151}.Release|Any CPU.Build.0 = Release|Any CPU
{25BE033F-3973-4BC8-8C1D-246C3C4AD3C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25BE033F-3973-4BC8-8C1D-246C3C4AD3C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25BE033F-3973-4BC8-8C1D-246C3C4AD3C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25BE033F-3973-4BC8-8C1D-246C3C4AD3C6}.Release|Any CPU.Build.0 = Release|Any CPU
{4A940BAC-8B19-4167-95C2-944394502CA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A940BAC-8B19-4167-95C2-944394502CA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A940BAC-8B19-4167-95C2-944394502CA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A940BAC-8B19-4167-95C2-944394502CA1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -179,6 +199,10 @@ Global
{5C58155F-2EB2-41AE-BF00-98EC13772624} = {E18384AC-84A4-47B8-B6ED-F9BB5CD37926}
{A3E971F8-563C-43D1-B822-8164B22D8C11} = {E18384AC-84A4-47B8-B6ED-F9BB5CD37926}
{6DC6465B-FDC2-4637-99E3-31B77725B016} = {E18384AC-84A4-47B8-B6ED-F9BB5CD37926}
{86FE1981-2361-4417-89F3-90CE0DC21692} = {6B1672A0-DAF3-4002-93E7-DB4C995C5477}
{256074E6-3736-41D1-8F44-6EB9EC25E151} = {86FE1981-2361-4417-89F3-90CE0DC21692}
{25BE033F-3973-4BC8-8C1D-246C3C4AD3C6} = {86FE1981-2361-4417-89F3-90CE0DC21692}
{4A940BAC-8B19-4167-95C2-944394502CA1} = {86FE1981-2361-4417-89F3-90CE0DC21692}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B045A915-127E-4011-AD1D-A375525CF8A6}
Expand Down
2 changes: 1 addition & 1 deletion scripts/runbus-management.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
docker run -d --name mm-rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
docker run -d --name mm-rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.13.1-management

2 changes: 1 addition & 1 deletion scripts/runbus.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
docker run -d --name mm-rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq
docker run -d --name mm-rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.13.1

2 changes: 1 addition & 1 deletion scripts/rundb.ps1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker run --name mm-postgres -e POSTGRES_PASSWORD=devpass -p 5432:5432 -d postgres
docker run --name mm-postgres -e POSTGRES_PASSWORD=devpass -p 5432:5432 -d postgres:16.2
3 changes: 0 additions & 3 deletions src/Common/TeamUp.Common.Application/AssemblyInfo.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Common/TeamUp.Common.Application/ICommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using RailwayResult;

using TeamUp.Application.Abstractions;
using TeamUp.Common.Contracts;

namespace TeamUp.Common.Application;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using RailwayResult;

using TeamUp.Domain.Abstractions;
using TeamUp.Common.Contracts;

namespace TeamUp.Common.Application;

public interface IIntegrationEventHandler<TIntegrationEvent> where TIntegrationEvent : class, IIntegrationEvent
public interface IIntegrationEventHandlerMarker;

public interface IIntegrationEventHandler<TIntegrationEvent> : IIntegrationEventHandlerMarker where TIntegrationEvent : class, IIntegrationEvent
{
public Task<Result> Handle(TIntegrationEvent integrationEvent, CancellationToken ct);
}
2 changes: 1 addition & 1 deletion src/Common/TeamUp.Common.Application/IQueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using RailwayResult;

using TeamUp.Application.Abstractions;
using TeamUp.Common.Contracts;

namespace TeamUp.Common.Application;

Expand Down
4 changes: 3 additions & 1 deletion src/Common/TeamUp.Common.Application/IUnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using RailwayResult;

using TeamUp.Common.Contracts;

namespace TeamUp.Common.Application;

public interface IUnitOfWork
public interface IUnitOfWork<TModuleId> where TModuleId : IModuleId
{
public Task<Result> SaveChangesAsync(CancellationToken ct = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<ItemGroup>
<PackageReference Include="FluentValidation" />
<PackageReference Include="MassTransit" />
<PackageReference Include="MediatR" />
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
Expand All @@ -10,5 +11,9 @@
<ItemGroup>
<ProjectReference Include="..\TeamUp.Common.Contracts\TeamUp.Common.Contracts.csproj" />
</ItemGroup>


<ItemGroup>
<InternalsVisibleTo Include="TeamUp.Common.Infrastructure" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Common/TeamUp.Common.Contracts/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using RailwayResult;

namespace TeamUp.Application.Abstractions;
namespace TeamUp.Common.Contracts;

public interface ICommand : IRequest<Result>, ICommandPipeline;

Expand Down
2 changes: 1 addition & 1 deletion src/Common/TeamUp.Common.Contracts/IIntegrationEvent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace TeamUp.Domain.Abstractions;
namespace TeamUp.Common.Contracts;

public interface IIntegrationEvent;
6 changes: 6 additions & 0 deletions src/Common/TeamUp.Common.Contracts/IModuleId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TeamUp.Common.Contracts;

public interface IModuleId
{
public static abstract string ModuleName { get; }
}
2 changes: 1 addition & 1 deletion src/Common/TeamUp.Common.Contracts/IQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using RailwayResult;

namespace TeamUp.Application.Abstractions;
namespace TeamUp.Common.Contracts;

public interface IQuery<TResponse> : IRequest<Result<TResponse>>, IQueryPipeline;

Expand Down
8 changes: 8 additions & 0 deletions src/Common/TeamUp.Common.Domain/IIntegrationEventPublisher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using TeamUp.Common.Contracts;

namespace TeamUp.Common.Domain;

public interface IIntegrationEventPublisher<TModuleId> where TModuleId : IModuleId
{
public void Publish<TEvent>(TEvent integrationEvent) where TEvent : class, IIntegrationEvent;
}
21 changes: 0 additions & 21 deletions src/Common/TeamUp.Common.Endpoints/ComplexEndpointGroup.cs

This file was deleted.

24 changes: 0 additions & 24 deletions src/Common/TeamUp.Common.Endpoints/EndpointGroup.cs

This file was deleted.

61 changes: 61 additions & 0 deletions src/Common/TeamUp.Common.Endpoints/EndpointGroupBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Diagnostics.CodeAnalysis;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;

namespace TeamUp.Common.Endpoints;

public sealed class EndpointGroupBuilder
{
public RouteGroupBuilder Group { get; private set; }

private readonly List<EndpointGroupBuilder> _subGroups = [];

public EndpointGroupBuilder(RouteGroupBuilder group)
{
Group = group;
}

public EndpointGroupBuilder WithTags(params string[] tags)
{
foreach (var group in _subGroups)
{
group.Group.WithTags(tags);
}

return this;
}

public EndpointGroupBuilder AddEndpoint<TEndpoint>() where TEndpoint : IEndpoint, new()
{
var endpoint = new TEndpoint();
endpoint.MapEndpoint(Group);
return this;
}

public EndpointGroupBuilder Configure(Func<RouteGroupBuilder, RouteGroupBuilder> configureGroup)
{
Group = configureGroup(Group);
return this;
}

public EndpointGroupBuilder CreateGroup([StringSyntax("Route")] string prefix, Action<EndpointGroupBuilder> configureGroup)
{
var newGroup = Group.MapGroup(prefix);

var newEndpointGroup = new EndpointGroupBuilder(newGroup);
configureGroup(newEndpointGroup);
_subGroups.Add(newEndpointGroup);

return this;
}

public EndpointGroupBuilder MapGroup<TEndpointGroup>() where TEndpointGroup : IEndpointGroup, new()
{
var group = new TEndpointGroup();
group.MapEndpoints(this);

return this;
}
}
6 changes: 2 additions & 4 deletions src/Common/TeamUp.Common.Endpoints/IEndpointGroup.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Microsoft.AspNetCore.Routing;

namespace TeamUp.Common.Endpoints;
namespace TeamUp.Common.Endpoints;

public interface IEndpointGroup
{
public RouteGroupBuilder MapEndpoints(RouteGroupBuilder group);
public EndpointGroupBuilder MapEndpoints(EndpointGroupBuilder group);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace TeamUp.Common.Endpoints;

public static class ResultExtensions
public static class ResultToResponseExtensions
{
public static IResult ToResponse<TOut>(this Result<TOut> result, Func<TOut, IResult> success)
{
Expand Down
20 changes: 0 additions & 20 deletions src/Common/TeamUp.Common.Endpoints/RouteGroupBuilderExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="Asp.Versioning.Http" />
<PackageReference Include="MediatR" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions src/Common/TeamUp.Common.Infrastructure/AssemblyInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;

using TeamUp.Common.Infrastructure.Processing.Inbox;
using TeamUp.Common.Infrastructure.Processing.Outbox;

namespace TeamUp.Common.Infrastructure.Extensions;

public static class ModelBuilderExtensions
{
public static void ConfigureOutbox(this ModelBuilder builder)
{
builder.Entity<OutboxMessage>()
.ToTable("OutboxMessages")
.HasKey(m => m.Id);

builder.Entity<InboxMessage>()
.ToTable("InboxMessages")
.HasKey(m => m.Id);
}
}
Loading

0 comments on commit c80e541

Please sign in to comment.