diff --git a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeCustomers/Application/IntegrationEvents/TenantAdminCreatedIntegrationEventHandler.cs b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeCustomers/Application/EventHandlers/TenantAdminCreatedIntegrationEventHandler.cs similarity index 97% rename from Source/Modules/Subscriptions/Features/DomainFeatures/StripeCustomers/Application/IntegrationEvents/TenantAdminCreatedIntegrationEventHandler.cs rename to Source/Modules/Subscriptions/Features/DomainFeatures/StripeCustomers/Application/EventHandlers/TenantAdminCreatedIntegrationEventHandler.cs index 9be6e919..8ee000c1 100644 --- a/Source/Modules/Subscriptions/Features/DomainFeatures/StripeCustomers/Application/IntegrationEvents/TenantAdminCreatedIntegrationEventHandler.cs +++ b/Source/Modules/Subscriptions/Features/DomainFeatures/StripeCustomers/Application/EventHandlers/TenantAdminCreatedIntegrationEventHandler.cs @@ -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 { diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/Commands/DeleteTenant.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/Commands/DeleteTenant.cs index ef5221fc..2e6cbe37 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/Commands/DeleteTenant.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/Commands/DeleteTenant.cs @@ -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 { @@ -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(); diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/IntegrationEvents/TenantSubscriptionUpdatedIntegrationEventHandler.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/EventHandlers/TenantSubscriptionUpdatedIntegrationEventHandler.cs similarity index 97% rename from Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/IntegrationEvents/TenantSubscriptionUpdatedIntegrationEventHandler.cs rename to Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/EventHandlers/TenantSubscriptionUpdatedIntegrationEventHandler.cs index d6a10255..0dd5928a 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/IntegrationEvents/TenantSubscriptionUpdatedIntegrationEventHandler.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Application/EventHandlers/TenantSubscriptionUpdatedIntegrationEventHandler.cs @@ -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, IIntegrationEventHandler { diff --git a/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Domain/Tenant.cs b/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Domain/Tenant.cs index 6160af60..7de3e64d 100644 --- a/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Domain/Tenant.cs +++ b/Source/Modules/TenantIdentity/Features/DomainFeatures/Tenants/Domain/Tenant.cs @@ -5,6 +5,7 @@ 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 { @@ -12,7 +13,6 @@ 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 Memberships => memberships.AsReadOnly(); @@ -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); diff --git a/Source/Modules/TenantIdentity/Features/Infrastructure/EFCore/TenantIdentityDbContext.cs b/Source/Modules/TenantIdentity/Features/Infrastructure/EFCore/TenantIdentityDbContext.cs index 5e2f668e..e71cb0fc 100644 --- a/Source/Modules/TenantIdentity/Features/Infrastructure/EFCore/TenantIdentityDbContext.cs +++ b/Source/Modules/TenantIdentity/Features/Infrastructure/EFCore/TenantIdentityDbContext.cs @@ -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 { @@ -78,7 +79,7 @@ public async Task 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; } @@ -88,7 +89,7 @@ public async Task 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; } @@ -101,7 +102,7 @@ public async Task GetTenantExtendedByIdAsync(Guid tenantId) .FirstOrDefaultAsync(t => t.TenantId == tenantId); if (tenant == null) { - throw new NotFoundException(); + throw Errors.NotFound(nameof(Tenant), tenantId); } return tenant; } diff --git a/Source/Modules/TenantIdentity/Features/Modules.TenantIdentity.Features.csproj b/Source/Modules/TenantIdentity/Features/Modules.TenantIdentity.Features.csproj index 2c11eab3..05e8361d 100644 --- a/Source/Modules/TenantIdentity/Features/Modules.TenantIdentity.Features.csproj +++ b/Source/Modules/TenantIdentity/Features/Modules.TenantIdentity.Features.csproj @@ -18,7 +18,6 @@ - diff --git a/Source/Modules/TenantIdentity/Web/Client/Modules.TenantIdentity.Web.Client.csproj b/Source/Modules/TenantIdentity/Web/Client/Modules.TenantIdentity.Web.Client.csproj index 34a92c77..4799c6a5 100644 --- a/Source/Modules/TenantIdentity/Web/Client/Modules.TenantIdentity.Web.Client.csproj +++ b/Source/Modules/TenantIdentity/Web/Client/Modules.TenantIdentity.Web.Client.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -12,7 +12,7 @@ - + diff --git a/Source/Modules/TenantIdentity/Web/Server/Controllers/Infrastructure/IdentityOperationsController.cs b/Source/Modules/TenantIdentity/Web/Server/Controllers/Infrastructure/IdentityOperationsController.cs index f9c5dced..b4eaefdf 100644 --- a/Source/Modules/TenantIdentity/Web/Server/Controllers/Infrastructure/IdentityOperationsController.cs +++ b/Source/Modules/TenantIdentity/Web/Server/Controllers/Infrastructure/IdentityOperationsController.cs @@ -42,7 +42,7 @@ public ActionResult GetClaimsOfCurrentUser() } [HttpGet("selectTenant/{TenantId}")] - public async Task SetTenantForCurrentUser(Guid tenantId, [FromQuery] string redirectUri) + public async Task SetTenantForCurrentUser([FromRoute] Guid tenantId, [FromQuery] string redirectUri) { var user = await queryDispatcher.DispatchAsync(new GetUserById { }); diff --git a/Source/Shared/Features/Domain/Attributes/JoiningTableAttribute.cs b/Source/Shared/Features/Domain/Attributes/JoiningTableAttribute.cs deleted file mode 100644 index 8322141e..00000000 --- a/Source/Shared/Features/Domain/Attributes/JoiningTableAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Shared.Features.Domain.Attributes -{ - public class JoiningTableAttribute : Attribute - { - public JoiningTableAttribute(params string[] tables) - { - - } - } -} diff --git a/Source/Shared/Features/Domain/Attributes/NotDatabasePersistedAttribute.cs b/Source/Shared/Features/Domain/Attributes/NotDatabasePersistedAttribute.cs deleted file mode 100644 index 6a6c4bc9..00000000 --- a/Source/Shared/Features/Domain/Attributes/NotDatabasePersistedAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Shared.Features.Domain.Attributes -{ - public class NotDatabasePersistedAttribute : Attribute - { - } -} diff --git a/Source/Shared/Features/Domain/Attributes/ValueObjectAttribute.cs b/Source/Shared/Features/Domain/Attributes/ValueObjectAttribute.cs deleted file mode 100644 index 587a555c..00000000 --- a/Source/Shared/Features/Domain/Attributes/ValueObjectAttribute.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Shared.Features.Domain.Attributes -{ - public class ValueObjectAttribute : Attribute - { - } -} diff --git a/Source/Shared/Features/Domain/Exceptions/NotAllowedException.cs b/Source/Shared/Features/Domain/Exceptions/NotAllowedException.cs deleted file mode 100644 index 55603ff9..00000000 --- a/Source/Shared/Features/Domain/Exceptions/NotAllowedException.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Shared.Features.Domain.Exceptions -{ - internal class NotAllowedException : Exception - { - } -} diff --git a/Source/Shared/Features/Domain/Exceptions/NotFoundException.cs b/Source/Shared/Features/Domain/Exceptions/NotFoundException.cs deleted file mode 100644 index 0215495a..00000000 --- a/Source/Shared/Features/Domain/Exceptions/NotFoundException.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Shared.Features.Domain.Exceptions -{ - public class NotFoundException : Exception - { - } -} diff --git a/Source/Shared/Features/EFCore/DbSetExtensions.cs b/Source/Shared/Features/EFCore/DbSetExtensions.cs index b45cdf40..eaab291e 100644 --- a/Source/Shared/Features/EFCore/DbSetExtensions.cs +++ b/Source/Shared/Features/EFCore/DbSetExtensions.cs @@ -12,7 +12,7 @@ public static async Task GetEntityAsync(this DbSet 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) { @@ -27,7 +27,7 @@ public static async Task GetEntityAsync(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) { diff --git a/Source/Shared/Features/Messaging/Commands/ICommandHandler.cs b/Source/Shared/Features/Messaging/Commands/ICommandHandler.cs index 725504d6..48ea9813 100644 --- a/Source/Shared/Features/Messaging/Commands/ICommandHandler.cs +++ b/Source/Shared/Features/Messaging/Commands/ICommandHandler.cs @@ -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 where TCommand : Command { diff --git a/Source/Shared/Features/Server/BaseController.cs b/Source/Shared/Features/Server/BaseController.cs index f379b2ce..279f17e7 100644 --- a/Source/Shared/Features/Server/BaseController.cs +++ b/Source/Shared/Features/Server/BaseController.cs @@ -8,6 +8,16 @@ namespace Shared.Features.Server { + public class BaseController : BaseController + { + protected readonly TModule module; + + public BaseController(IServiceProvider serviceProvider) : base(serviceProvider) + { + module = serviceProvider.GetService(); + } + } + public class BaseController : ControllerBase { protected readonly IExecutionContext executionContext; diff --git a/Source/Shared/Kernel/Errors/Errors.cs b/Source/Shared/Kernel/Errors/Errors.cs index 4a6012df..44ed7edc 100644 --- a/Source/Shared/Kernel/Errors/Errors.cs +++ b/Source/Shared/Kernel/Errors/Errors.cs @@ -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(); } } diff --git a/Source/Shared/Kernel/Errors/Exceptions/NotFoundException.cs b/Source/Shared/Kernel/Errors/Exceptions/NotFoundException.cs index f93c1379..868bfdaf 100644 --- a/Source/Shared/Kernel/Errors/Exceptions/NotFoundException.cs +++ b/Source/Shared/Kernel/Errors/Exceptions/NotFoundException.cs @@ -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") { } diff --git a/Source/Web/Server/BuildingBlocks/ExceptionHandling/ExceptionHandler.cs b/Source/Web/Server/BuildingBlocks/ExceptionHandling/ExceptionHandler.cs index 28f2838a..2add0da4 100644 --- a/Source/Web/Server/BuildingBlocks/ExceptionHandling/ExceptionHandler.cs +++ b/Source/Web/Server/BuildingBlocks/ExceptionHandling/ExceptionHandler.cs @@ -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; diff --git a/Source/Web/Server/Web.Server.csproj b/Source/Web/Server/Web.Server.csproj index 8a8269a0..ca4b18af 100644 --- a/Source/Web/Server/Web.Server.csproj +++ b/Source/Web/Server/Web.Server.csproj @@ -23,7 +23,6 @@ -