From 48dcae22a3cfd60f678f678b8b929a0c0363d3b6 Mon Sep 17 00:00:00 2001 From: PascalMarchesseault <97350299+PascalMarchesseault@users.noreply.github.com> Date: Sun, 9 Jun 2024 23:03:33 -0400 Subject: [PATCH] Merge - Geminimal & CreatorInfo --- .../Queries/GetCreatorInfo/CreatorInfoDto.cs | 9 --- .../Queries/GetCreatorInfo/GetCreatorInfo.cs | 32 ----------- .../Queries/GetMinimalUser/GetMinimalUser.cs | 28 ++++++--- .../Queries/GetMinimalUser/MinimalUserDto.cs | 2 +- src/Web/Endpoints/GetCreatorInfo.cs | 19 ------- src/Web/Endpoints/Users.cs | 4 +- src/Web/wwwroot/api/specification.json | 57 +++---------------- 7 files changed, 34 insertions(+), 117 deletions(-) delete mode 100644 src/Application/Users/Queries/GetCreatorInfo/CreatorInfoDto.cs delete mode 100644 src/Application/Users/Queries/GetCreatorInfo/GetCreatorInfo.cs delete mode 100644 src/Web/Endpoints/GetCreatorInfo.cs diff --git a/src/Application/Users/Queries/GetCreatorInfo/CreatorInfoDto.cs b/src/Application/Users/Queries/GetCreatorInfo/CreatorInfoDto.cs deleted file mode 100644 index e03d762..0000000 --- a/src/Application/Users/Queries/GetCreatorInfo/CreatorInfoDto.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Hutopy.Application.Users.Queries.GetCreatorInfo; - -public class CreatorInfoDto -{ - public required string FirstName { get; init; } - public required string LastName { get; init; } - public string UserName { get; init; } = String.Empty; - -} diff --git a/src/Application/Users/Queries/GetCreatorInfo/GetCreatorInfo.cs b/src/Application/Users/Queries/GetCreatorInfo/GetCreatorInfo.cs deleted file mode 100644 index 2f2e7d9..0000000 --- a/src/Application/Users/Queries/GetCreatorInfo/GetCreatorInfo.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Hutopy.Application.Common.Interfaces; - -namespace Hutopy.Application.Users.Queries.GetCreatorInfo; - -public record GetCreatorInfoQuery : IRequest -{ - public string UserName { get; set; } = string.Empty; -}; - - -public class GetCreatorInfoHandler( - IIdentityService identityService - ) - : IRequestHandler -{ - public async Task Handle(GetCreatorInfoQuery request, CancellationToken cancellationToken) - { - - var userName = await identityService.GetUserByUserNameAsync(request.UserName); - var creatorInfo = new CreatorInfoDto - { - - FirstName = userName?.FirstName ?? "", - LastName = userName?.LastName ?? "", - UserName = userName?.UserName ?? "", - - }; - return creatorInfo; - } - - -} diff --git a/src/Application/Users/Queries/GetMinimalUser/GetMinimalUser.cs b/src/Application/Users/Queries/GetMinimalUser/GetMinimalUser.cs index 5fd288d..e7e5940 100644 --- a/src/Application/Users/Queries/GetMinimalUser/GetMinimalUser.cs +++ b/src/Application/Users/Queries/GetMinimalUser/GetMinimalUser.cs @@ -1,10 +1,12 @@ using Hutopy.Application.Common.Interfaces; +using Hutopy.Application.Common.Models; namespace Hutopy.Application.Users.Queries.GetMinimalUser; public record GetMinimalUserQuery : IRequest { - public string UserId { get; set; } = string.Empty; + public string? UserId { get; set; } = string.Empty; + public string? UserName { get; set; } = string.Empty; }; public class GetMinimalUserQueryHandler( @@ -14,15 +16,27 @@ public class GetMinimalUserQueryHandler( { public async Task Handle(GetMinimalUserQuery request, CancellationToken cancellationToken) { - var identityUser = await identityService.FindUserByIdAsync(request.UserId); - + UserModel? identityUser = null; + + if (request.UserId != string.Empty) + { + identityUser = await identityService.FindUserByIdAsync(request.UserId); + + } + + if (request.UserName != string.Empty) + { + identityUser = await identityService.GetUserByUserNameAsync(request.UserName); + } + + var user = new MinimalUserDto { - FirstName = identityUser?.FirstName ?? "", - LastName = identityUser?.LastName ?? "", - UserName = identityUser?.UserName ?? "" + FirstName = identityUser?.FirstName ?? string.Empty, + LastName = identityUser?.LastName ?? string.Empty, + UserName = identityUser?.UserName ?? string.Empty }; return user; } -} +} \ No newline at end of file diff --git a/src/Application/Users/Queries/GetMinimalUser/MinimalUserDto.cs b/src/Application/Users/Queries/GetMinimalUser/MinimalUserDto.cs index 0b01fba..97fa6a1 100644 --- a/src/Application/Users/Queries/GetMinimalUser/MinimalUserDto.cs +++ b/src/Application/Users/Queries/GetMinimalUser/MinimalUserDto.cs @@ -4,5 +4,5 @@ public class MinimalUserDto { public required string FirstName { get; init; } public required string LastName { get; init; } - public string UserName { get; init; } = String.Empty; + public required string UserName { get; init; } = String.Empty; } diff --git a/src/Web/Endpoints/GetCreatorInfo.cs b/src/Web/Endpoints/GetCreatorInfo.cs deleted file mode 100644 index e31263f..0000000 --- a/src/Web/Endpoints/GetCreatorInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Hutopy.Application.Users.Queries; -using Hutopy.Application.Users.Queries.GetCreatorInfo; - - -namespace Hutopy.Web.Endpoints; - -public class GetCreatorInfo : EndpointGroupBase -{ - public override void Map(WebApplication app) - { - app.MapGroup(this) - .MapGet(GetSelectedCreatorInfo); - } - - private static async Task GetSelectedCreatorInfo(ISender sender, [AsParameters] GetCreatorInfoQuery query) - { - return await sender.Send(query); - } -} diff --git a/src/Web/Endpoints/Users.cs b/src/Web/Endpoints/Users.cs index 32b8acc..b0b9c59 100644 --- a/src/Web/Endpoints/Users.cs +++ b/src/Web/Endpoints/Users.cs @@ -12,15 +12,17 @@ public class Users : EndpointGroupBase .MapPost(CreateUser) .MapGet(GetMinimalUser) .MapIdentityApi(); + } private static async Task CreateUser(ISender sender, CreateUserCommand command) { return await sender.Send(command); } - + private static async Task GetMinimalUser(ISender sender, [AsParameters] GetMinimalUserQuery query) { return await sender.Send(query); } + } diff --git a/src/Web/wwwroot/api/specification.json b/src/Web/wwwroot/api/specification.json index 670f3b3..ece282e 100644 --- a/src/Web/wwwroot/api/specification.json +++ b/src/Web/wwwroot/api/specification.json @@ -6,38 +6,6 @@ "version": "1.0.0" }, "paths": { - "/api/GetCreatorInfo": { - "get": { - "tags": [ - "GetCreatorInfo" - ], - "operationId": "GetSelectedCreatorInfo", - "parameters": [ - { - "name": "UserName", - "in": "query", - "required": true, - "schema": { - "type": "string", - "nullable": true - }, - "x-position": 1 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/CreatorInfoDto" - } - } - } - } - } - } - }, "/api/GetMyUser": { "get": { "tags": [ @@ -283,12 +251,20 @@ { "name": "UserId", "in": "query", - "required": true, "schema": { "type": "string", "nullable": true }, "x-position": 1 + }, + { + "name": "UserName", + "in": "query", + "schema": { + "type": "string", + "nullable": true + }, + "x-position": 2 } ], "responses": { @@ -720,21 +696,6 @@ }, "components": { "schemas": { - "CreatorInfoDto": { - "type": "object", - "additionalProperties": false, - "properties": { - "firstName": { - "type": "string" - }, - "lastName": { - "type": "string" - }, - "userName": { - "type": "string" - } - } - }, "UserDto": { "type": "object", "additionalProperties": false,