initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using Indotalent.Data.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Indotalent.Features.Profile.Avatar.Cqrs;
|
||||
|
||||
public class GetAvatarInfoResponse
|
||||
{
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string? FullName { get; set; }
|
||||
public string? AvatarFile { get; set; }
|
||||
}
|
||||
|
||||
public record GetAvatarInfoQuery(string UserId) : IRequest<GetAvatarInfoResponse?>;
|
||||
|
||||
public class GetAvatarInfoHandler : IRequestHandler<GetAvatarInfoQuery, GetAvatarInfoResponse?>
|
||||
{
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
|
||||
public GetAvatarInfoHandler(UserManager<ApplicationUser> userManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public async Task<GetAvatarInfoResponse?> Handle(GetAvatarInfoQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await _userManager.FindByIdAsync(request.UserId);
|
||||
if (user == null) return null;
|
||||
|
||||
return new GetAvatarInfoResponse
|
||||
{
|
||||
Id = user.Id,
|
||||
FullName = user.FullName,
|
||||
AvatarFile = user.AvatarFile
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user