Adds ChangeBanner for Creators

This commit is contained in:
Jonathan Bourdon
2024-08-05 16:32:00 -04:00
parent e617b5ffd3
commit 8f0ed2644b
8 changed files with 30 additions and 56 deletions

View File

@@ -1,7 +1,6 @@
using FastEndpoints;
using Hutopy.Application.AzureBlobStorage.Constants;
using Hutopy.Application.Common.Interfaces;
using Hutopy.Application.Utils;
using Hutopy.Web.Features.Contents.Data;
using Microsoft.EntityFrameworkCore;
@@ -14,7 +13,7 @@ public record ChangeBannerRequest(
public class ChangeBannerHandler(
IHttpContextAccessor contextAccessor,
ContentDbContext context,
IAzureBlobStorageService azureBlobStorageService)
IBlobStorage blobStorage)
: Endpoint<ChangeBannerRequest>
{
public override void Configure()
@@ -29,21 +28,27 @@ public class ChangeBannerHandler(
var creator = await context
.Creators
.Include(c => c.StoredDataUrls)
.SingleAsync(
.SingleOrDefaultAsync(
c => c.Id == request.CreatorId,
cancellationToken: ct);
var contentType = contextAccessor.EnsureContentType();
var blobUrl = await azureBlobStorageService.UploadFileAsync(
if (creator is null)
{
await SendNotFoundAsync(ct);
return;
}
var blobUrl = await blobStorage.UploadFileAsync(
ContainerNames.Users,
$"{request.CreatorId}/{SubDirectoryNames.Profile}/{CommonFileNames.BannerPicture}",
request.File.OpenReadStream(),
contentType,
request.File.ContentType,
ct);
creator.StoredDataUrls.BannerPictureUrl = blobUrl;
await context.SaveChangesAsync(ct);
await SendOkAsync(blobUrl, ct);
}
}