Merge - Geminimal & CreatorInfo

This commit is contained in:
PascalMarchesseault
2024-06-09 23:03:33 -04:00
parent 1c277f530d
commit 48dcae22a3
7 changed files with 34 additions and 117 deletions

View File

@@ -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;
}

View File

@@ -1,32 +0,0 @@
using Hutopy.Application.Common.Interfaces;
namespace Hutopy.Application.Users.Queries.GetCreatorInfo;
public record GetCreatorInfoQuery : IRequest<CreatorInfoDto>
{
public string UserName { get; set; } = string.Empty;
};
public class GetCreatorInfoHandler(
IIdentityService identityService
)
: IRequestHandler<GetCreatorInfoQuery, CreatorInfoDto>
{
public async Task<CreatorInfoDto> 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;
}
}

View File

@@ -1,10 +1,12 @@
using Hutopy.Application.Common.Interfaces;
using Hutopy.Application.Common.Models;
namespace Hutopy.Application.Users.Queries.GetMinimalUser;
public record GetMinimalUserQuery : IRequest<MinimalUserDto>
{
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<MinimalUserDto> 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;
}
}
}

View File

@@ -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;
}

View File

@@ -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<CreatorInfoDto> GetSelectedCreatorInfo(ISender sender, [AsParameters] GetCreatorInfoQuery query)
{
return await sender.Send(query);
}
}

View File

@@ -12,15 +12,17 @@ public class Users : EndpointGroupBase
.MapPost(CreateUser)
.MapGet(GetMinimalUser)
.MapIdentityApi<ApplicationUser>();
}
private static async Task<Guid> CreateUser(ISender sender, CreateUserCommand command)
{
return await sender.Send(command);
}
private static async Task<MinimalUserDto> GetMinimalUser(ISender sender, [AsParameters] GetMinimalUserQuery query)
{
return await sender.Send(query);
}
}

View File

@@ -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,