From 5c81ec7adfbea3e605b24c4b32db8e773f2c123a Mon Sep 17 00:00:00 2001 From: Akber Date: Wed, 7 Feb 2024 17:49:31 +0400 Subject: [PATCH] Add gender endpoind from Idenitty api. --- .../Configurations/MessageBusServiceInstaller.cs | 7 ++----- .../Configurations/MessageBusServiceInstaller.cs | 2 +- .../Identity/Identity.App/Identity.App.csproj | 1 + .../Users/Queries/GetGenders/GetGendersQuery.cs | 3 +++ .../Queries/GetGenders/GetGendersQueryHandler.cs | 12 ++++++++++++ .../Queries/GetGenders/GetGendersQueryResponse.cs | 3 +++ .../Users/Queries/GetRoles/GetRolesQuery.cs | 2 +- .../V1/Controllers/UserController.cs | 11 +++++++++++ 8 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQuery.cs create mode 100644 crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQueryHandler.cs create mode 100644 crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQueryResponse.cs diff --git a/crs/Services/Email/Email.App/Configurations/MessageBusServiceInstaller.cs b/crs/Services/Email/Email.App/Configurations/MessageBusServiceInstaller.cs index 71f3957..62559fc 100644 --- a/crs/Services/Email/Email.App/Configurations/MessageBusServiceInstaller.cs +++ b/crs/Services/Email/Email.App/Configurations/MessageBusServiceInstaller.cs @@ -2,12 +2,10 @@ internal sealed class MessageBusServiceInstaller : IServiceInstaller { - public void Install(IServiceCollection services, IConfiguration configuration) - { + public void Install(IServiceCollection services, IConfiguration configuration) => services.AddMassTransit(configure => { configure.SetKebabCaseEndpointNameFormatter(); - configure.AddConsumers(MessageBus.AssemblyReference.Assembly); configure.UsingRabbitMq((context, configurator) => { configurator.Host("rabbitmq", "/", hostConfigurator => @@ -19,7 +17,6 @@ public void Install(IServiceCollection services, IConfiguration configuration) configurator.ConfigureEndpoints(context); }); - configure.AddConsumers(App.AssemblyReference.Assembly); + configure.AddConsumers(MessageBus.AssemblyReference.Assembly); }); - } } diff --git a/crs/Services/Identity/Identity.App/Configurations/MessageBusServiceInstaller.cs b/crs/Services/Identity/Identity.App/Configurations/MessageBusServiceInstaller.cs index 453e3d2..1983e0d 100644 --- a/crs/Services/Identity/Identity.App/Configurations/MessageBusServiceInstaller.cs +++ b/crs/Services/Identity/Identity.App/Configurations/MessageBusServiceInstaller.cs @@ -19,7 +19,7 @@ public void Install(IServiceCollection services, IConfiguration configuration) configurator.ConfigureEndpoints(context); }); - configure.AddConsumers(App.AssemblyReference.Assembly); + configure.AddConsumers(MessageBus.AssemblyReference.Assembly); }); services.AddTransient(); diff --git a/crs/Services/Identity/Identity.App/Identity.App.csproj b/crs/Services/Identity/Identity.App/Identity.App.csproj index 5252d13..fd903f0 100644 --- a/crs/Services/Identity/Identity.App/Identity.App.csproj +++ b/crs/Services/Identity/Identity.App/Identity.App.csproj @@ -51,6 +51,7 @@ + diff --git a/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQuery.cs b/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQuery.cs new file mode 100644 index 0000000..5af6299 --- /dev/null +++ b/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQuery.cs @@ -0,0 +1,3 @@ +namespace Identity.Application.Users.Queries.GetGenders; + +public sealed record GetGendersQuery() : IQuery; diff --git a/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQueryHandler.cs b/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQueryHandler.cs new file mode 100644 index 0000000..8fd8673 --- /dev/null +++ b/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQueryHandler.cs @@ -0,0 +1,12 @@ + +namespace Identity.Application.Users.Queries.GetGenders; + +internal sealed class GetRolesQueryHandler : IQueryHandler +{ + public Task> Handle(GetGendersQuery request, CancellationToken cancellationToken) + { + var roles = Gender.GetNames(); + var response = Result.Success(new GetGendersQueryResponse(roles)); + return Task.FromResult(response); + } +} diff --git a/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQueryResponse.cs b/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQueryResponse.cs new file mode 100644 index 0000000..004d8ff --- /dev/null +++ b/crs/Services/Identity/Identity.Application/Users/Queries/GetGenders/GetGendersQueryResponse.cs @@ -0,0 +1,3 @@ +namespace Identity.Application.Users.Queries.GetGenders; + +public sealed record GetGendersQueryResponse(IEnumerable Genders) \ No newline at end of file diff --git a/crs/Services/Identity/Identity.Application/Users/Queries/GetRoles/GetRolesQuery.cs b/crs/Services/Identity/Identity.Application/Users/Queries/GetRoles/GetRolesQuery.cs index c952b45..1cd2949 100644 --- a/crs/Services/Identity/Identity.Application/Users/Queries/GetRoles/GetRolesQuery.cs +++ b/crs/Services/Identity/Identity.Application/Users/Queries/GetRoles/GetRolesQuery.cs @@ -1,3 +1,3 @@ namespace Identity.Application.Users.Queries.GetRoles; -public sealed class GetRolesQuery() : IQuery; +public sealed record GetRolesQuery() : IQuery; diff --git a/crs/Services/Identity/Identity.Presentation/V1/Controllers/UserController.cs b/crs/Services/Identity/Identity.Presentation/V1/Controllers/UserController.cs index 501c1d7..77a8ad5 100644 --- a/crs/Services/Identity/Identity.Presentation/V1/Controllers/UserController.cs +++ b/crs/Services/Identity/Identity.Presentation/V1/Controllers/UserController.cs @@ -3,6 +3,7 @@ using Identity.Application.Users.Commands.Register; using Identity.Application.Users.Commands.RetryConfirmEmailSend; using Identity.Application.Users.Commands.UpdateRefreshToken; +using Identity.Application.Users.Queries.GetGenders; using Identity.Application.Users.Queries.GetRoles; using Identity.Presentation.V1.Models; @@ -89,4 +90,14 @@ public async Task GetRoles() return result.IsSuccess ? Ok(result.Value) : HandleFailure(result); } + + [HttpGet("genders")] + public async Task GetGenders() + { + var query = new GetGendersQuery(); + + var result = await _sender.Send(query); + return result.IsSuccess ? Ok(result.Value) + : HandleFailure(result); + } }