Wip fonctionnement upload image Présentation
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Hutopy.Web.Features.Contents.Data;
|
using Hutopy.Web.Common.BlobStorage;
|
||||||
|
using Hutopy.Web.Features.Contents.Data;
|
||||||
|
|
||||||
namespace Hutopy.Web.Features.Contents.Handlers;
|
namespace Hutopy.Web.Features.Contents.Handlers;
|
||||||
|
|
||||||
@@ -8,29 +9,32 @@ public record ChangePresentationInfosRequest(
|
|||||||
string? PhoneNumber,
|
string? PhoneNumber,
|
||||||
string? Email,
|
string? Email,
|
||||||
string? Title,
|
string? Title,
|
||||||
string? MainImageUrl,
|
|
||||||
string? MainImageText,
|
string? MainImageText,
|
||||||
string? MainVideoText,
|
string? MainVideoText,
|
||||||
string? ImagesSubtitle,
|
string? ImagesSubtitle,
|
||||||
string? Image1Url,
|
|
||||||
string? Image2Url,
|
|
||||||
string? Image3Url,
|
|
||||||
string? Image4Url,
|
|
||||||
string? ImagesText,
|
string? ImagesText,
|
||||||
string? VideoSubtitle,
|
string? VideoSubtitle,
|
||||||
string? VideoSubtitleMain,
|
string? VideoSubtitleMain,
|
||||||
string? VideoUrlMain,
|
string? VideoUrlMain,
|
||||||
string? VideoUrl,
|
string? VideoUrl,
|
||||||
string? VideoText);
|
string? VideoText,
|
||||||
|
IFormFile? MainImage,
|
||||||
|
IFormFile? Image1,
|
||||||
|
IFormFile? Image2,
|
||||||
|
IFormFile? Image3,
|
||||||
|
IFormFile? Image4);
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public class ChangePresentationInfosHandler(
|
public class ChangePresentationInfosHandler(
|
||||||
ContentDbContext context)
|
ContentDbContext context,
|
||||||
|
AzureBlobStorage blobStorage)
|
||||||
: Endpoint<ChangePresentationInfosRequest>
|
: Endpoint<ChangePresentationInfosRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/creators/{CreatorId}/presentation-infos");
|
Post("/api/creators/{CreatorId}/presentation-infos");
|
||||||
Options(o => o.WithTags("Creators"));
|
Options(o => o.WithTags("Creators"));
|
||||||
|
AllowFileUploads();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(
|
public override async Task HandleAsync(
|
||||||
@@ -40,30 +44,51 @@ public class ChangePresentationInfosHandler(
|
|||||||
var creator = await context
|
var creator = await context
|
||||||
.Creators
|
.Creators
|
||||||
.Include(c => c.PresentationInfos)
|
.Include(c => c.PresentationInfos)
|
||||||
.SingleAsync(
|
.SingleOrDefaultAsync(
|
||||||
c => c.Id == request.CreatorId,
|
c => c.Id == request.CreatorId,
|
||||||
cancellationToken: ct);
|
cancellationToken: ct);
|
||||||
|
|
||||||
creator.PresentationInfos.PhoneNumber = request.PhoneNumber ?? "";
|
if (creator is null)
|
||||||
creator.PresentationInfos.Email = request.Email ?? "";
|
{
|
||||||
creator.PresentationInfos.Title = request.Title ?? "";
|
await SendNotFoundAsync(ct);
|
||||||
creator.PresentationInfos.MainImageUrl = request.MainImageUrl ?? "";
|
return;
|
||||||
creator.PresentationInfos.MainImageText = request.MainImageText ?? "";
|
}
|
||||||
creator.PresentationInfos.MainVideoText = request.MainVideoText ?? "";
|
|
||||||
creator.PresentationInfos.ImagesSubtitle = request.ImagesSubtitle ?? "";
|
|
||||||
creator.PresentationInfos.Image1Url = request.Image1Url ?? "";
|
|
||||||
creator.PresentationInfos.Image2Url = request.Image2Url ?? "";
|
|
||||||
creator.PresentationInfos.Image3Url = request.Image3Url ?? "";
|
|
||||||
creator.PresentationInfos.Image4Url = request.Image4Url ?? "";
|
|
||||||
creator.PresentationInfos.ImagesText = request.ImagesText ?? "";
|
|
||||||
creator.PresentationInfos.VideoSubtitle = request.VideoSubtitle ?? "";
|
|
||||||
creator.PresentationInfos.VideoSubtitleMain = request.VideoSubtitleMain ?? "";
|
|
||||||
creator.PresentationInfos.VideoUrlMain = request.VideoUrlMain ?? "";
|
|
||||||
creator.PresentationInfos.VideoUrl = request.VideoUrl ?? "";
|
|
||||||
creator.PresentationInfos.VideoText = request.VideoText ?? "";
|
|
||||||
|
|
||||||
await context.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
|
// Upload images if provided and update URLs
|
||||||
|
async Task<string?> UploadFileAsync(IFormFile? file, string subDirectory, string fileName)
|
||||||
|
{
|
||||||
|
if (file is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return await blobStorage.UploadFileAsync(
|
||||||
|
ContainerNames.Creators,
|
||||||
|
$"{request.CreatorId}/{subDirectory}/{fileName}",
|
||||||
|
file.OpenReadStream(),
|
||||||
|
file.ContentType,
|
||||||
|
ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
creator.PresentationInfos.MainImageUrl = await UploadFileAsync(request.MainImage, "Profile", "MainImage") ?? creator.PresentationInfos.MainImageUrl;
|
||||||
|
creator.PresentationInfos.Image1Url = await UploadFileAsync(request.Image1, "Profile", "Image1") ?? creator.PresentationInfos.Image1Url;
|
||||||
|
creator.PresentationInfos.Image2Url = await UploadFileAsync(request.Image2, "Profile", "Image2") ?? creator.PresentationInfos.Image2Url;
|
||||||
|
creator.PresentationInfos.Image3Url = await UploadFileAsync(request.Image3, "Profile", "Image3") ?? creator.PresentationInfos.Image3Url;
|
||||||
|
creator.PresentationInfos.Image4Url = await UploadFileAsync(request.Image4, "Profile", "Image4") ?? creator.PresentationInfos.Image4Url;
|
||||||
|
|
||||||
|
// Update other fields
|
||||||
|
creator.PresentationInfos.PhoneNumber = request.PhoneNumber ?? creator.PresentationInfos.PhoneNumber;
|
||||||
|
creator.PresentationInfos.Email = request.Email ?? creator.PresentationInfos.Email;
|
||||||
|
creator.PresentationInfos.Title = request.Title ?? creator.PresentationInfos.Title;
|
||||||
|
creator.PresentationInfos.MainImageText = request.MainImageText ?? creator.PresentationInfos.MainImageText;
|
||||||
|
creator.PresentationInfos.MainVideoText = request.MainVideoText ?? creator.PresentationInfos.MainVideoText;
|
||||||
|
creator.PresentationInfos.ImagesSubtitle = request.ImagesSubtitle ?? creator.PresentationInfos.ImagesSubtitle;
|
||||||
|
creator.PresentationInfos.ImagesText = request.ImagesText ?? creator.PresentationInfos.ImagesText;
|
||||||
|
creator.PresentationInfos.VideoSubtitle = request.VideoSubtitle ?? creator.PresentationInfos.VideoSubtitle;
|
||||||
|
creator.PresentationInfos.VideoSubtitleMain = request.VideoSubtitleMain ?? creator.PresentationInfos.VideoSubtitleMain;
|
||||||
|
creator.PresentationInfos.VideoUrlMain = request.VideoUrlMain ?? creator.PresentationInfos.VideoUrlMain;
|
||||||
|
creator.PresentationInfos.VideoUrl = request.VideoUrl ?? creator.PresentationInfos.VideoUrl;
|
||||||
|
creator.PresentationInfos.VideoText = request.VideoText ?? creator.PresentationInfos.VideoText;
|
||||||
|
|
||||||
|
await context.SaveChangesAsync(ct);
|
||||||
await SendOkAsync(ct);
|
await SendOkAsync(ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user