diff --git a/CleanArchitecture.Api/Program.cs b/CleanArchitecture.Api/Program.cs index 14fc644..8bb5488 100644 --- a/CleanArchitecture.Api/Program.cs +++ b/CleanArchitecture.Api/Program.cs @@ -38,7 +38,7 @@ if (builder.Environment.IsProduction()) .AddSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")!) .AddRedis(builder.Configuration["RedisHostName"]!, "Redis") .AddRabbitMQ( - rabbitConnectionString: $"amqp://{rabbitUser}:{rabbitPass}@{rabbitHost}", + $"amqp://{rabbitUser}:{rabbitPass}@{rabbitHost}", name: "RabbitMQ"); } diff --git a/CleanArchitecture.Application/Extensions/QueryableExtensions.cs b/CleanArchitecture.Application/Extensions/QueryableExtensions.cs index 55b9d53..35e5a55 100644 --- a/CleanArchitecture.Application/Extensions/QueryableExtensions.cs +++ b/CleanArchitecture.Application/Extensions/QueryableExtensions.cs @@ -28,7 +28,7 @@ public static class QueryableExtensions var sorted = GetFirstOrderLevelQuery(query, sort.Parameters.First(), fieldExpressions); - for (int i = 1; i < sort.Parameters.Count; i++) + for (var i = 1; i < sort.Parameters.Count; i++) { sorted = GetMultiLevelOrderedQuery(sorted, sort.Parameters[i], fieldExpressions); } @@ -38,7 +38,7 @@ public static class QueryableExtensions private static IOrderedQueryable GetFirstOrderLevelQuery( IQueryable query, - SortParameter @param, + SortParameter param, Dictionary>> fieldExpressions) { if (!fieldExpressions.TryGetValue(param.ParameterName, out var fieldExpression)) @@ -56,7 +56,7 @@ public static class QueryableExtensions private static IOrderedQueryable GetMultiLevelOrderedQuery( IOrderedQueryable query, - SortParameter @param, + SortParameter param, Dictionary>> fieldExpressions) { if (!fieldExpressions.TryGetValue(param.ParameterName, out var fieldExpression)) diff --git a/CleanArchitecture.Application/Extensions/ServiceCollectionExtensions.cs b/CleanArchitecture.Application/Extensions/ServiceCollectionExtensions.cs index a8a9fda..c7d053c 100644 --- a/CleanArchitecture.Application/Extensions/ServiceCollectionExtensions.cs +++ b/CleanArchitecture.Application/Extensions/ServiceCollectionExtensions.cs @@ -43,7 +43,7 @@ public static class ServiceCollectionExtensions { services.AddScoped, TenantViewModelSortProvider>(); services.AddScoped, UserViewModelSortProvider>(); - + return services; } } \ No newline at end of file diff --git a/CleanArchitecture.Application/Interfaces/ITenantService.cs b/CleanArchitecture.Application/Interfaces/ITenantService.cs index 109e114..47d7e9d 100644 --- a/CleanArchitecture.Application/Interfaces/ITenantService.cs +++ b/CleanArchitecture.Application/Interfaces/ITenantService.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using CleanArchitecture.Application.SortProviders; using CleanArchitecture.Application.ViewModels; using CleanArchitecture.Application.ViewModels.Sorting; using CleanArchitecture.Application.ViewModels.Tenants; diff --git a/CleanArchitecture.Application/Interfaces/IUserService.cs b/CleanArchitecture.Application/Interfaces/IUserService.cs index 7544715..3d1ecaa 100644 --- a/CleanArchitecture.Application/Interfaces/IUserService.cs +++ b/CleanArchitecture.Application/Interfaces/IUserService.cs @@ -10,11 +10,13 @@ public interface IUserService { public Task GetUserByUserIdAsync(Guid userId); public Task GetCurrentUserAsync(); + public Task> GetAllUsersAsync( PageQuery query, bool includeDeleted, string searchTerm = "", SortQuery? sortQuery = null); + public Task CreateUserAsync(CreateUserViewModel user); public Task UpdateUserAsync(UpdateUserViewModel user); public Task DeleteUserAsync(Guid userId); diff --git a/CleanArchitecture.Application/Queries/Tenants/GetAll/GetAllTenantsQueryHandler.cs b/CleanArchitecture.Application/Queries/Tenants/GetAll/GetAllTenantsQueryHandler.cs index 6e2b558..a097c13 100644 --- a/CleanArchitecture.Application/Queries/Tenants/GetAll/GetAllTenantsQueryHandler.cs +++ b/CleanArchitecture.Application/Queries/Tenants/GetAll/GetAllTenantsQueryHandler.cs @@ -15,8 +15,8 @@ namespace CleanArchitecture.Application.Queries.Tenants.GetAll; public sealed class GetAllTenantsQueryHandler : IRequestHandler> { - private readonly ITenantRepository _tenantRepository; private readonly ISortingExpressionProvider _sortingExpressionProvider; + private readonly ITenantRepository _tenantRepository; public GetAllTenantsQueryHandler( ITenantRepository tenantRepository, diff --git a/CleanArchitecture.Application/Queries/Users/GetAll/GetAllUsersQueryHandler.cs b/CleanArchitecture.Application/Queries/Users/GetAll/GetAllUsersQueryHandler.cs index 4271ae3..18f2df3 100644 --- a/CleanArchitecture.Application/Queries/Users/GetAll/GetAllUsersQueryHandler.cs +++ b/CleanArchitecture.Application/Queries/Users/GetAll/GetAllUsersQueryHandler.cs @@ -15,8 +15,8 @@ namespace CleanArchitecture.Application.Queries.Users.GetAll; public sealed class GetAllUsersQueryHandler : IRequestHandler> { - private readonly IUserRepository _userRepository; private readonly ISortingExpressionProvider _sortingExpressionProvider; + private readonly IUserRepository _userRepository; public GetAllUsersQueryHandler( IUserRepository userRepository, diff --git a/CleanArchitecture.Application/Services/TenantService.cs b/CleanArchitecture.Application/Services/TenantService.cs index ca3ae0a..e9bd707 100644 --- a/CleanArchitecture.Application/Services/TenantService.cs +++ b/CleanArchitecture.Application/Services/TenantService.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using CleanArchitecture.Application.Interfaces; using CleanArchitecture.Application.Queries.Tenants.GetAll; using CleanArchitecture.Application.Queries.Tenants.GetTenantById; -using CleanArchitecture.Application.SortProviders; using CleanArchitecture.Application.ViewModels; using CleanArchitecture.Application.ViewModels.Sorting; using CleanArchitecture.Application.ViewModels.Tenants; diff --git a/CleanArchitecture.Application/SortProviders/TenantViewModelSortProvider.cs b/CleanArchitecture.Application/SortProviders/TenantViewModelSortProvider.cs index e3afb0d..e8a5b53 100644 --- a/CleanArchitecture.Application/SortProviders/TenantViewModelSortProvider.cs +++ b/CleanArchitecture.Application/SortProviders/TenantViewModelSortProvider.cs @@ -12,9 +12,9 @@ public sealed class TenantViewModelSortProvider : ISortingExpressionProvider>> s_expressions = new() { { "id", tenant => tenant.Id }, - { "name", tenant => tenant.Name }, + { "name", tenant => tenant.Name } }; - + public Dictionary>> GetSortingExpressions() { return s_expressions; diff --git a/CleanArchitecture.Application/SortProviders/UserViewModelSortProvider.cs b/CleanArchitecture.Application/SortProviders/UserViewModelSortProvider.cs index d369a67..cfff203 100644 --- a/CleanArchitecture.Application/SortProviders/UserViewModelSortProvider.cs +++ b/CleanArchitecture.Application/SortProviders/UserViewModelSortProvider.cs @@ -19,7 +19,7 @@ public sealed class UserViewModelSortProvider : ISortingExpressionProvider user.Role }, { "status", user => user.Status } }; - + public Dictionary>> GetSortingExpressions() { return s_expressions; diff --git a/CleanArchitecture.Application/ViewModels/Sorting/SortQuery.cs b/CleanArchitecture.Application/ViewModels/Sorting/SortQuery.cs index 550925e..3be687c 100644 --- a/CleanArchitecture.Application/ViewModels/Sorting/SortQuery.cs +++ b/CleanArchitecture.Application/ViewModels/Sorting/SortQuery.cs @@ -6,34 +6,9 @@ namespace CleanArchitecture.Application.ViewModels.Sorting; public sealed class SortQuery { - private readonly struct QueryInfo - { - public readonly short PlusSignIndex; - public readonly short MinusSignIndex; - public readonly short FirstSpaceIndex; - public readonly short OpeningBracketIndex; - public readonly short ClosingBracketIndex; - - public QueryInfo( - short plusSignIndex, - short minusSignIndex, - short firstSpaceIndex, - short openingBracketIndex, - short closingBracketIndex) - { - PlusSignIndex = plusSignIndex; - MinusSignIndex = minusSignIndex; - FirstSpaceIndex = firstSpaceIndex; - OpeningBracketIndex = openingBracketIndex; - ClosingBracketIndex = closingBracketIndex; - } - } - private string? _query = string.Empty; - private ReadOnlyCollection _parameters = new(Array.Empty()); - - public ReadOnlyCollection Parameters => _parameters; + public ReadOnlyCollection Parameters { get; private set; } = new(Array.Empty()); [FromQuery(Name = "order_by")] public string? Query @@ -42,7 +17,7 @@ public sealed class SortQuery set { _query = value; - _parameters = ParseQuery(_query); + Parameters = ParseQuery(_query); } } @@ -68,7 +43,7 @@ public sealed class SortQuery var @params = value.Split(','); var parsedParams = new SortParameter[@params.Length]; - for (int i = 0; i < @params.Length; i++) + for (var i = 0; i < @params.Length; i++) { parsedParams[i] = GetParam(@params[i]); } @@ -114,7 +89,8 @@ public sealed class SortQuery { return new SortParameter(paramName, SortOrder.Ascending); } - else if (orderName == "desc" || orderName == "descending") + + if (orderName == "desc" || orderName == "descending") { return new SortParameter(paramName, SortOrder.Descending); } @@ -137,10 +113,8 @@ public sealed class SortQuery { return new SortParameter(value[1..], order); } - else - { - return new SortParameter(value[..indicatorIndex], order); - } + + return new SortParameter(value[..indicatorIndex], order); } private static SortParameter GetSortParamFromFunctionalStyle(string value, QueryInfo info) @@ -158,7 +132,8 @@ public sealed class SortQuery { return new SortParameter(param, SortOrder.Ascending); } - else if (value.StartsWith("desc(") || value.StartsWith("descending(")) + + if (value.StartsWith("desc(") || value.StartsWith("descending(")) { return new SortParameter(param, SortOrder.Descending); } @@ -288,7 +263,7 @@ public sealed class SortQuery private static int FindNextNonWhitespaceCharacter(string value, int startIndex) { - for (int i = startIndex; i < value.Length; i++) + for (var i = startIndex; i < value.Length; i++) { if (!char.IsWhiteSpace(value[i])) { @@ -298,4 +273,27 @@ public sealed class SortQuery return -1; } + + private readonly struct QueryInfo + { + public readonly short PlusSignIndex; + public readonly short MinusSignIndex; + public readonly short FirstSpaceIndex; + public readonly short OpeningBracketIndex; + public readonly short ClosingBracketIndex; + + public QueryInfo( + short plusSignIndex, + short minusSignIndex, + short firstSpaceIndex, + short openingBracketIndex, + short closingBracketIndex) + { + PlusSignIndex = plusSignIndex; + MinusSignIndex = minusSignIndex; + FirstSpaceIndex = firstSpaceIndex; + OpeningBracketIndex = openingBracketIndex; + ClosingBracketIndex = closingBracketIndex; + } + } } \ No newline at end of file diff --git a/CleanArchitecture.Domain/Rabbitmq/RabbitMqHandler.cs b/CleanArchitecture.Domain/Rabbitmq/RabbitMqHandler.cs index 09c20b0..81cb7bc 100644 --- a/CleanArchitecture.Domain/Rabbitmq/RabbitMqHandler.cs +++ b/CleanArchitecture.Domain/Rabbitmq/RabbitMqHandler.cs @@ -52,7 +52,7 @@ public sealed class RabbitMqHandler : BackgroundService { if (!_configuration.Enabled) { - _logger.LogInformation($"RabbitMQ is disabled. Skipping the creation of exchange {exchangeName}."); + _logger.LogInformation("RabbitMQ is disabled. Skipping the creation of exchange {exchangeName}.", exchangeName); return; } @@ -159,7 +159,7 @@ public sealed class RabbitMqHandler : BackgroundService } catch (Exception ex) { - _logger.LogError(ex, $"Error while handling event in queue {ea.RoutingKey}"); + _logger.LogError(ex, "Error while handling event in queue {RoutingKey}", ea.RoutingKey); } }