Adds ChangePortrait for User
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user