using Domain.Entities; using Features.ImageUploads.Repository; using Features.ImageUploads.Services; using MediatR; namespace Features.ImageUploads.Commands.UploadPhoto; /// Handles . public class UploadPhotoHandler( IFileStorageProvider fileStorageProvider, IPhotoUploadRepository photoUploadRepository ) : IRequestHandler { public async Task Handle(UploadPhotoCommand request, CancellationToken cancellationToken) { Guid photoId = Guid.NewGuid(); string key = $"{request.Key}/{photoId}"; await using Stream stream = request.File.OpenReadStream(); await fileStorageProvider.UploadAsync( key, stream, request.File.ContentType, cancellationToken ); Photo photo = new() { PhotoId = photoId, Hyperlink = key, UploadedById = request.UploadedById, }; await photoUploadRepository.CreateAsync(photo, cancellationToken); return photoId; } }