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