Split creators out of identity
This commit is contained in:
49
src/Web/Features/Contents/Handlers/ChangeBanner.cs
Normal file
49
src/Web/Features/Contents/Handlers/ChangeBanner.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
|
||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||
|
||||
public record ChangeBannerRequest(
|
||||
Guid CreatorId,
|
||||
IFormFile File);
|
||||
|
||||
public class ChangeBannerHandler(
|
||||
IHttpContextAccessor contextAccessor,
|
||||
ContentDbContext context,
|
||||
IAzureBlobStorageService azureBlobStorageService)
|
||||
: Endpoint<ChangeBannerRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/creators/{CreatorId}/banner");
|
||||
Options(o => o.WithTags("Contents"));
|
||||
AllowFileUploads();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(ChangeBannerRequest request, CancellationToken ct)
|
||||
{
|
||||
var creator = await context
|
||||
.Creators
|
||||
.Include(c => c.StoredDataUrls)
|
||||
.SingleAsync(
|
||||
c => c.Id == request.CreatorId,
|
||||
cancellationToken: ct);
|
||||
|
||||
var contentType = contextAccessor.EnsureContentType();
|
||||
|
||||
var blobUrl = await azureBlobStorageService.UploadFileAsync(
|
||||
ContainerNames.Users,
|
||||
$"{request.CreatorId}/{SubDirectoryNames.Profile}/{CommonFileNames.BannerPicture}",
|
||||
request.File.OpenReadStream(),
|
||||
contentType,
|
||||
ct);
|
||||
|
||||
await context.SaveChangesAsync(ct);
|
||||
|
||||
await SendOkAsync(blobUrl, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user