From 1c277f530d1f00368fb59eed1078cab1819fbd3a Mon Sep 17 00:00:00 2001 From: PascalMarchesseault <97350299+PascalMarchesseault@users.noreply.github.com> Date: Sat, 8 Jun 2024 12:03:20 -0400 Subject: [PATCH] Ajout de PublicCreatorInfo --- .../Queries/GetCreatorInfo/CreatorInfoDto.cs | 9 ++++ .../Queries/GetCreatorInfo/GetCreatorInfo.cs | 32 +++++++++++++ src/Web/Endpoints/GetCreatorInfo.cs | 19 ++++++++ src/Web/wwwroot/api/specification.json | 47 +++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 src/Application/Users/Queries/GetCreatorInfo/CreatorInfoDto.cs create mode 100644 src/Application/Users/Queries/GetCreatorInfo/GetCreatorInfo.cs create 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 new file mode 100644 index 0000000..e03d762 --- /dev/null +++ b/src/Application/Users/Queries/GetCreatorInfo/CreatorInfoDto.cs @@ -0,0 +1,9 @@ +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 new file mode 100644 index 0000000..2f2e7d9 --- /dev/null +++ b/src/Application/Users/Queries/GetCreatorInfo/GetCreatorInfo.cs @@ -0,0 +1,32 @@ +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/Web/Endpoints/GetCreatorInfo.cs b/src/Web/Endpoints/GetCreatorInfo.cs new file mode 100644 index 0000000..e31263f --- /dev/null +++ b/src/Web/Endpoints/GetCreatorInfo.cs @@ -0,0 +1,19 @@ +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/wwwroot/api/specification.json b/src/Web/wwwroot/api/specification.json index e9729d9..670f3b3 100644 --- a/src/Web/wwwroot/api/specification.json +++ b/src/Web/wwwroot/api/specification.json @@ -6,6 +6,38 @@ "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": [ @@ -688,6 +720,21 @@ }, "components": { "schemas": { + "CreatorInfoDto": { + "type": "object", + "additionalProperties": false, + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "userName": { + "type": "string" + } + } + }, "UserDto": { "type": "object", "additionalProperties": false,