Skip to content

Commit

Permalink
features renamed EventHandlers
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Nov 28, 2024
1 parent adcd024 commit f31ef60
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Shared.Features.Messaging.IntegrationEvents;
using Stripe;

namespace Modules.Subscriptions.Features.DomainFeatures.StripeCustomers.Application.IntegrationEvents
namespace Modules.Subscriptions.Features.DomainFeatures.StripeCustomers.Application.EventHandlers
{
public class TenantAdminCreatedIntegrationEventHandler : IIntegrationEventHandler<TenantAdminCreatedIntegrationEvent>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.EntityFrameworkCore;
using Shared.Features.Messaging.Command;
using Shared.Features.Domain.Exceptions;
using System.Threading;
using Shared.Features.Server;
using Shared.Kernel.Errors;
using Modules.TenantIdentity.Features.DomainFeatures.Tenants.Domain;

namespace Modules.TenantIdentity.Features.DomainFeatures.Tenants.Application.Commands
{
Expand All @@ -17,10 +18,10 @@ public DeleteTenantCommandHandler(IServiceProvider serviceProvider) : base(servi

public async Task HandleAsync(DeleteTenant command, CancellationToken cancellationToken)
{
var tenant = await module.TenantIdentityDbContext.Tenants.SingleAsync(t => t.TenantId == command.TenantId);
var tenant = await module.TenantIdentityDbContext.Tenants.SingleAsync(t => t.Id == command.TenantId);
if (tenant == null)
{
throw new NotFoundException();
throw Errors.NotFound(nameof(Tenant), command.TenantId);
}

tenant.ThrowIfUserCantDeleteTenant();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Shared.Features.Server;
using System.Threading;

namespace Modules.TenantIdentity.Features.DomainFeatures.Tenants.Application.IntegrationEvents
namespace Modules.TenantIdentity.Features.DomainFeatures.Tenants.Application.EventHandlers
{
public class TenantSubscriptionUpdatedIntegrationEventHandler : ServerExecutionBase<TenantIdentityModule>, IIntegrationEventHandler<TenantSubscriptionPlanUpdatedIntegrationEvent>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
using Shared.Features.Domain;
using Shared.Features.Domain.Exceptions;
using Shared.Kernel.BuildingBlocks.Auth;
using Shared.Kernel.Errors;

namespace Modules.TenantIdentity.Features.DomainFeatures.Tenants.Domain
{
public class Tenant : Entity
{
public Tenant() { }

public override Guid TenantId { get => base.TenantId; }
public string Name { get; set; }
public SubscriptionPlanType SubscriptionPlanType { get; set; }
public IReadOnlyCollection<TenantMembership> Memberships => memberships.AsReadOnly();
Expand Down Expand Up @@ -91,7 +91,7 @@ public void DeleteTenantMembership(Guid membershipId)
var tenantMembership = Memberships.SingleOrDefault(t => t.Id == membershipId);
if (tenantMembership == null)
{
throw new NotFoundException();
throw Errors.NotFound(nameof(TenantMembership), membershipId);
}

memberships.Remove(tenantMembership);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Shared.Features.EFCore;
using Shared.Kernel.BuildingBlocks;
using Modules.TenantIdentity.Features.DomainFeatures.Tenants.Domain;
using Shared.Kernel.Errors;

namespace Modules.TenantIdentity.Features.Infrastructure.EFCore
{
Expand Down Expand Up @@ -78,7 +79,7 @@ public async Task<ApplicationUser> GetUserByIdAsync(Guid userId)
var user = await Users.FirstOrDefaultAsync(t => t.Id == userId);
if (user == null)
{
throw new NotFoundException();
throw Errors.NotFound(nameof(ApplicationUser), userId);
}
return user;
}
Expand All @@ -88,7 +89,7 @@ public async Task<Tenant> GetTenantByIdAsync(Guid tenantId)
var tenant = await Tenants.FirstOrDefaultAsync(t => t.TenantId == tenantId);
if (tenant == null)
{
throw new NotFoundException();
throw Errors.NotFound(nameof(Tenant), tenantId);
}
return tenant;
}
Expand All @@ -101,7 +102,7 @@ public async Task<Tenant> GetTenantExtendedByIdAsync(Guid tenantId)
.FirstOrDefaultAsync(t => t.TenantId == tenantId);
if (tenant == null)
{
throw new NotFoundException();
throw Errors.NotFound(nameof(Tenant), tenantId);
}
return tenant;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<ProjectReference Include="..\..\Subscriptions\IntegrationEvents\Modules.Subscriptions.IntegrationEvents.csproj" />
<ProjectReference Include="..\IntegrationEvents\Modules.TenantIdentity.IntegrationEvents.csproj" />
<ProjectReference Include="..\Shared\Modules.TenantIdentity.Shared.csproj" />
<ProjectReference Include="..\Web\Shared\Modules.TenantIdentity.Shared.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -12,7 +12,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\..\Shared\Kernel\Shared.Kernel.csproj" />
<ProjectReference Include="..\Shared\Modules.TenantIdentity.Shared.csproj" />
<ProjectReference Include="..\..\Shared\Modules.TenantIdentity.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ActionResult<BFFUserInfoDTO> GetClaimsOfCurrentUser()
}

[HttpGet("selectTenant/{TenantId}")]
public async Task<ActionResult> SetTenantForCurrentUser(Guid tenantId, [FromQuery] string redirectUri)
public async Task<ActionResult> SetTenantForCurrentUser([FromRoute] Guid tenantId, [FromQuery] string redirectUri)
{
var user = await queryDispatcher.DispatchAsync<GetUserById, ApplicationUser>(new GetUserById { });

Expand Down
10 changes: 0 additions & 10 deletions Source/Shared/Features/Domain/Attributes/JoiningTableAttribute.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions Source/Shared/Features/Domain/Exceptions/NotFoundException.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Source/Shared/Features/EFCore/DbSetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static async Task<TEntity> GetEntityAsync<TEntity>(this DbSet<TEntity> db
var entity = await dbSet.FirstOrDefaultAsync(t => t.Id == entityId);
if (entity == null)
{
throw Errors.NotFound;
throw Errors.NotFound(typeof(TEntity).Name, entityId);
}
if (entity.TenantId != owningTenantId)
{
Expand All @@ -27,7 +27,7 @@ public static async Task<TEntity> GetEntityAsync<TEntity, TSecond>(this IIncluda
var entity = await dbSet.FirstOrDefaultAsync(t => t.Id == entityId);
if (entity == null)
{
throw Errors.NotFound;
throw Errors.NotFound(typeof(TEntity).Name, entityId);
}
if (entity.TenantId != tenantId)
{
Expand Down
6 changes: 5 additions & 1 deletion Source/Shared/Features/Messaging/Commands/ICommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace Shared.Features.Messaging.Command
using Microsoft.EntityFrameworkCore.Metadata;
using Shared.Features.Modules;
using Shared.Features.Server;

namespace Shared.Features.Messaging.Command
{
public interface ICommandHandler<in TCommand> where TCommand : Command
{
Expand Down
10 changes: 10 additions & 0 deletions Source/Shared/Features/Server/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

namespace Shared.Features.Server
{
public class BaseController<TModule> : BaseController
{
protected readonly TModule module;

public BaseController(IServiceProvider serviceProvider) : base(serviceProvider)
{
module = serviceProvider.GetService<TModule>();
}
}

public class BaseController : ControllerBase
{
protected readonly IExecutionContext executionContext;
Expand Down
3 changes: 2 additions & 1 deletion Source/Shared/Kernel/Errors/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace Shared.Kernel.Errors
{
public static class Errors
{
public static NotFoundException NotFound = new NotFoundException();
public static NotFoundException NotFound(string entityName, Guid id) => new NotFoundException(entityName, id);
public static NotFoundException NotFound(string entityName, string id) => new NotFoundException(entityName, id);
public static UnAuthorizedException UnAuthorized = new UnAuthorizedException();
}
}
7 changes: 6 additions & 1 deletion Source/Shared/Kernel/Errors/Exceptions/NotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
{
public class NotFoundException : Exception
{
public NotFoundException() : base("Entity was not found")
public NotFoundException(string entityType, string id) : base($"{entityType} with {id} was not found")
{

}

public NotFoundException(string entityType, Guid id) : base($"{entityType} with {id} was not found")
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Shared.Features.Domain.Exceptions;
using Shared.Kernel.BuildingBlocks.Auth.Exceptions;
using Shared.Kernel.Errors.Exceptions;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion Source/Web/Server/Web.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Modules\LandingPages\Modules.LandingPages.Web.Server\Modules.LandingPages.Web.csproj" />
<ProjectReference Include="..\..\Modules\LandingPages\Server\Modules.LandingPages.Web.csproj" />
<ProjectReference Include="..\..\Modules\Subscriptions\Web\Server\Modules.Subscriptions.Web.Server.csproj" />
<ProjectReference Include="..\..\Modules\TenantIdentity\Web\Server\Modules.TenantIdentity.Web.Server.csproj" />
Expand Down

0 comments on commit f31ef60

Please sign in to comment.