26 lines
993 B
C#
26 lines
993 B
C#
using Hutopy.Application.AzureBlobStorage.Constants;
|
|
using Hutopy.Application.Common.Interfaces;
|
|
|
|
namespace Hutopy.Application.Users.Commands;
|
|
|
|
public class UploadProfilePictureCommand : IRequest<string>
|
|
{
|
|
public required Stream ProfilePicture { get; init; }
|
|
}
|
|
|
|
public class UploadProfilePictureCommandHandler(IIdentityService identityService, IAzureBlobStorageService azureBlobStorageService) : IRequestHandler<UploadProfilePictureCommand, string>
|
|
{
|
|
public async Task<string> Handle(UploadProfilePictureCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var identityUser = await identityService.GetCurrentUserAsync();
|
|
var currentUserId = new Guid(identityUser?.Id ?? "").ToString();
|
|
|
|
var blobName = $"{currentUserId}/{SubDirectoryNames.Profile}/{CommonFileNames.ProfilePicture}";
|
|
|
|
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.ProfilePicture);
|
|
|
|
return url;
|
|
}
|
|
}
|
|
|