diff --git a/CleanArchitecture.Api/Controllers/TenantController.cs b/CleanArchitecture.Api/Controllers/TenantController.cs index 01853a3..0f8a78a 100644 --- a/CleanArchitecture.Api/Controllers/TenantController.cs +++ b/CleanArchitecture.Api/Controllers/TenantController.cs @@ -42,11 +42,9 @@ public sealed class TenantController : ApiController [HttpGet("{id:guid}")] [SwaggerOperation("Get a tenant by id")] [SwaggerResponse(200, "Request successful", typeof(ResponseMessage))] - public async Task GetTenantByIdAsync( - [FromRoute] Guid id, - [FromQuery] bool isDeleted = false) + public async Task GetTenantByIdAsync([FromRoute] Guid id) { - var tenant = await _tenantService.GetTenantByIdAsync(id, isDeleted); + var tenant = await _tenantService.GetTenantByIdAsync(id); return Response(tenant); } diff --git a/CleanArchitecture.Api/Controllers/UserController.cs b/CleanArchitecture.Api/Controllers/UserController.cs index 34d9ad2..dc66b31 100644 --- a/CleanArchitecture.Api/Controllers/UserController.cs +++ b/CleanArchitecture.Api/Controllers/UserController.cs @@ -42,11 +42,9 @@ public sealed class UserController : ApiController [HttpGet("{id:guid}")] [SwaggerOperation("Get a user by id")] [SwaggerResponse(200, "Request successful", typeof(ResponseMessage))] - public async Task GetUserByIdAsync( - [FromRoute] Guid id, - [FromQuery] bool isDeleted = false) + public async Task GetUserByIdAsync([FromRoute] Guid id) { - var user = await _userService.GetUserByUserIdAsync(id, isDeleted); + var user = await _userService.GetUserByUserIdAsync(id); return Response(user); } diff --git a/CleanArchitecture.Application.Tests/Queries/Tenants/GetTenantByIdQueryHandlerTests.cs b/CleanArchitecture.Application.Tests/Queries/Tenants/GetTenantByIdQueryHandlerTests.cs index 230864b..cd3e3ea 100644 --- a/CleanArchitecture.Application.Tests/Queries/Tenants/GetTenantByIdQueryHandlerTests.cs +++ b/CleanArchitecture.Application.Tests/Queries/Tenants/GetTenantByIdQueryHandlerTests.cs @@ -17,21 +17,7 @@ public sealed class GetTenantByIdQueryHandlerTests var tenant = _fixture.SetupTenant(); var result = await _fixture.QueryHandler.Handle( - new GetTenantByIdQuery(tenant.Id, false), - default); - - _fixture.VerifyNoDomainNotification(); - - tenant.Should().BeEquivalentTo(result); - } - - [Fact] - public async Task Should_Get_Deleted_Tenant() - { - var tenant = _fixture.SetupTenant(true); - - var result = await _fixture.QueryHandler.Handle( - new GetTenantByIdQuery(tenant.Id, true), + new GetTenantByIdQuery(tenant.Id), default); _fixture.VerifyNoDomainNotification(); @@ -45,7 +31,7 @@ public sealed class GetTenantByIdQueryHandlerTests var tenant = _fixture.SetupTenant(true); var result = await _fixture.QueryHandler.Handle( - new GetTenantByIdQuery(tenant.Id, false), + new GetTenantByIdQuery(tenant.Id), default); _fixture.VerifyExistingNotification( diff --git a/CleanArchitecture.Application.Tests/Queries/Users/GetUserByIdQueryHandlerTests.cs b/CleanArchitecture.Application.Tests/Queries/Users/GetUserByIdQueryHandlerTests.cs index 4b3aec0..885dcfa 100644 --- a/CleanArchitecture.Application.Tests/Queries/Users/GetUserByIdQueryHandlerTests.cs +++ b/CleanArchitecture.Application.Tests/Queries/Users/GetUserByIdQueryHandlerTests.cs @@ -18,7 +18,7 @@ public sealed class GetUserByIdQueryHandlerTests _fixture.SetupUserAsync(); var result = await _fixture.Handler.Handle( - new GetUserByIdQuery(_fixture.ExistingUserId, false), + new GetUserByIdQuery(_fixture.ExistingUserId), default); _fixture.VerifyNoDomainNotification(); @@ -32,7 +32,7 @@ public sealed class GetUserByIdQueryHandlerTests { _fixture.SetupUserAsync(); - var request = new GetUserByIdQuery(Guid.NewGuid(), false); + var request = new GetUserByIdQuery(Guid.NewGuid()); var result = await _fixture.Handler.Handle( request, default); @@ -51,7 +51,7 @@ public sealed class GetUserByIdQueryHandlerTests _fixture.SetupDeletedUserAsync(); var result = await _fixture.Handler.Handle( - new GetUserByIdQuery(_fixture.ExistingUserId, false), + new GetUserByIdQuery(_fixture.ExistingUserId), default); _fixture.VerifyExistingNotification( diff --git a/CleanArchitecture.Application/Interfaces/ITenantService.cs b/CleanArchitecture.Application/Interfaces/ITenantService.cs index fb47918..ff6756b 100644 --- a/CleanArchitecture.Application/Interfaces/ITenantService.cs +++ b/CleanArchitecture.Application/Interfaces/ITenantService.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using CleanArchitecture.Application.ViewModels; using CleanArchitecture.Application.ViewModels.Tenants; @@ -11,6 +10,6 @@ public interface ITenantService public Task CreateTenantAsync(CreateTenantViewModel tenant); public Task UpdateTenantAsync(UpdateTenantViewModel tenant); public Task DeleteTenantAsync(Guid tenantId); - public Task GetTenantByIdAsync(Guid tenantId, bool deleted); + public Task GetTenantByIdAsync(Guid tenantId); public Task> GetAllTenantsAsync(PageQuery query, string searchTerm = ""); } \ No newline at end of file diff --git a/CleanArchitecture.Application/Interfaces/IUserService.cs b/CleanArchitecture.Application/Interfaces/IUserService.cs index 1d2116b..49e4f91 100644 --- a/CleanArchitecture.Application/Interfaces/IUserService.cs +++ b/CleanArchitecture.Application/Interfaces/IUserService.cs @@ -8,7 +8,7 @@ namespace CleanArchitecture.Application.Interfaces; public interface IUserService { - public Task GetUserByUserIdAsync(Guid userId, bool isDeleted); + public Task GetUserByUserIdAsync(Guid userId); public Task GetCurrentUserAsync(); public Task> GetAllUsersAsync(PageQuery query, string searchTerm = ""); public Task CreateUserAsync(CreateUserViewModel user); diff --git a/CleanArchitecture.Application/Queries/Tenants/GetTenantById/GetTenantByIdQuery.cs b/CleanArchitecture.Application/Queries/Tenants/GetTenantById/GetTenantByIdQuery.cs index 8639dfe..5c5d7bf 100644 --- a/CleanArchitecture.Application/Queries/Tenants/GetTenantById/GetTenantByIdQuery.cs +++ b/CleanArchitecture.Application/Queries/Tenants/GetTenantById/GetTenantByIdQuery.cs @@ -4,4 +4,4 @@ using MediatR; namespace CleanArchitecture.Application.Queries.Tenants.GetTenantById; -public sealed record GetTenantByIdQuery(Guid TenantId, bool IsDeleted) : IRequest; \ No newline at end of file +public sealed record GetTenantByIdQuery(Guid TenantId) : IRequest; \ No newline at end of file diff --git a/CleanArchitecture.Application/Queries/Tenants/GetTenantById/GetTenantByIdQueryHandler.cs b/CleanArchitecture.Application/Queries/Tenants/GetTenantById/GetTenantByIdQueryHandler.cs index 2e22455..652c458 100644 --- a/CleanArchitecture.Application/Queries/Tenants/GetTenantById/GetTenantByIdQueryHandler.cs +++ b/CleanArchitecture.Application/Queries/Tenants/GetTenantById/GetTenantByIdQueryHandler.cs @@ -28,9 +28,7 @@ public sealed class GetTenantByIdQueryHandler : var tenant = _tenantRepository .GetAllNoTracking() .Include(x => x.Users) - .FirstOrDefault(x => - x.Id == request.TenantId && - x.Deleted == request.IsDeleted); + .FirstOrDefault(x => x.Id == request.TenantId && !x.Deleted); if (tenant is null) { diff --git a/CleanArchitecture.Application/Queries/Users/GetUserById/GetUserByIdQuery.cs b/CleanArchitecture.Application/Queries/Users/GetUserById/GetUserByIdQuery.cs index b4edf1e..cc11673 100644 --- a/CleanArchitecture.Application/Queries/Users/GetUserById/GetUserByIdQuery.cs +++ b/CleanArchitecture.Application/Queries/Users/GetUserById/GetUserByIdQuery.cs @@ -4,4 +4,4 @@ using MediatR; namespace CleanArchitecture.Application.Queries.Users.GetUserById; -public sealed record GetUserByIdQuery(Guid UserId, bool IsDeleted) : IRequest; \ No newline at end of file +public sealed record GetUserByIdQuery(Guid UserId) : IRequest; \ No newline at end of file diff --git a/CleanArchitecture.Application/Queries/Users/GetUserById/GetUserByIdQueryHandler.cs b/CleanArchitecture.Application/Queries/Users/GetUserById/GetUserByIdQueryHandler.cs index aa7974f..f0f2b77 100644 --- a/CleanArchitecture.Application/Queries/Users/GetUserById/GetUserByIdQueryHandler.cs +++ b/CleanArchitecture.Application/Queries/Users/GetUserById/GetUserByIdQueryHandler.cs @@ -26,9 +26,7 @@ public sealed class GetUserByIdQueryHandler : { var user = _userRepository .GetAllNoTracking() - .FirstOrDefault(x => - x.Id == request.UserId && - x.Deleted == request.IsDeleted); + .FirstOrDefault(x => x.Id == request.UserId && !x.Deleted); if (user is null) { diff --git a/CleanArchitecture.Application/Services/TenantService.cs b/CleanArchitecture.Application/Services/TenantService.cs index 709cb4b..44eaa67 100644 --- a/CleanArchitecture.Application/Services/TenantService.cs +++ b/CleanArchitecture.Application/Services/TenantService.cs @@ -51,11 +51,11 @@ public sealed class TenantService : ITenantService await _bus.SendCommandAsync(new DeleteTenantCommand(tenantId)); } - public async Task GetTenantByIdAsync(Guid tenantId, bool deleted) + public async Task GetTenantByIdAsync(Guid tenantId) { var cachedTenant = await _distributedCache.GetOrCreateJsonAsync( CacheKeyGenerator.GetEntityCacheKey(tenantId), - async () => await _bus.QueryAsync(new GetTenantByIdQuery(tenantId, deleted)), + async () => await _bus.QueryAsync(new GetTenantByIdQuery(tenantId)), new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromDays(3), diff --git a/CleanArchitecture.Application/Services/UserService.cs b/CleanArchitecture.Application/Services/UserService.cs index eb90bed..4f4522e 100644 --- a/CleanArchitecture.Application/Services/UserService.cs +++ b/CleanArchitecture.Application/Services/UserService.cs @@ -26,14 +26,14 @@ public sealed class UserService : IUserService _user = user; } - public async Task GetUserByUserIdAsync(Guid userId, bool isDeleted) + public async Task GetUserByUserIdAsync(Guid userId) { - return await _bus.QueryAsync(new GetUserByIdQuery(userId, isDeleted)); + return await _bus.QueryAsync(new GetUserByIdQuery(userId)); } public async Task GetCurrentUserAsync() { - return await _bus.QueryAsync(new GetUserByIdQuery(_user.GetUserId(), false)); + return await _bus.QueryAsync(new GetUserByIdQuery(_user.GetUserId())); } public async Task> GetAllUsersAsync(PageQuery query, string searchTerm = "")