Adds ChangePortrait for User

This commit is contained in:
2024-09-04 13:52:47 -04:00
parent f12418bc79
commit 3e341e0019
5 changed files with 103 additions and 48 deletions

View File

@@ -1,35 +0,0 @@
using Hutopy.Application.AzureBlobStorage.Constants;
using Hutopy.Application.Common.Interfaces;
using Microsoft.AspNetCore.Http;
namespace Hutopy.Application.Users.Commands;
/// <summary>
/// Upload a profile picture. If the user has the url already, set the ProfilePictureUrl in the user only without upload.
/// </summary>
public class UploadProfilePictureCommand : IRequest<IResult>
{
public required IFormFile File { get; init; }
}
public class UploadProfilePictureCommandHandler(
IHttpContextAccessor contextAccessor,
IIdentityService identityService,
IBlobStorage blobStorage) : IRequestHandler<UploadProfilePictureCommand, IResult>
{
public async Task<IResult> Handle(UploadProfilePictureCommand request, CancellationToken ct)
{
var identityUser = await identityService.GetCurrentUserAsync();
var url = await blobStorage.UploadFileAsync(
ContainerNames.Users,
$"{identityUser.Id}/{SubDirectoryNames.Profile}/{CommonFileNames.ProfilePicture}",
request.File.OpenReadStream(),
request.File.ContentType,
ct);
await identityService.UpdateCurrentUserPortraitUrlAsync(url);
return Results.Ok(url);
}
}