mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Wire SeaweedFS credentials through to the api.core dev container
api.core now waits on seaweedfs and receives its service URL and credentials so the file storage provider can connect.
This commit is contained in:
@@ -6,8 +6,10 @@ using MediatR;
|
||||
namespace Features.ImageUploads.Commands.UploadPhoto;
|
||||
|
||||
/// <summary>Handles <see cref="UploadPhotoCommand" />.</summary>
|
||||
public class UploadPhotoHandler(IFileStorageProvider fileStorageProvider, IPhotoUploadRepository photoUploadRepository)
|
||||
: IRequestHandler<UploadPhotoCommand, Guid>
|
||||
public class UploadPhotoHandler(
|
||||
IFileStorageProvider fileStorageProvider,
|
||||
IPhotoUploadRepository photoUploadRepository
|
||||
) : IRequestHandler<UploadPhotoCommand, Guid>
|
||||
{
|
||||
public async Task<Guid> Handle(UploadPhotoCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -16,7 +18,6 @@ public class UploadPhotoHandler(IFileStorageProvider fileStorageProvider, IPhoto
|
||||
|
||||
await using Stream stream = request.File.OpenReadStream();
|
||||
|
||||
|
||||
await fileStorageProvider.UploadAsync(
|
||||
key,
|
||||
stream,
|
||||
@@ -24,16 +25,9 @@ public class UploadPhotoHandler(IFileStorageProvider fileStorageProvider, IPhoto
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
Photo photo = new() { Hyperlink = key, UploadedById = request.UploadedById };
|
||||
|
||||
Photo photo = new()
|
||||
{
|
||||
Hyperlink = key,
|
||||
UploadedById = request.UploadedById,
|
||||
};
|
||||
|
||||
|
||||
await photoUploadRepository.CreateAsync(photo,cancellationToken);
|
||||
|
||||
await photoUploadRepository.CreateAsync(photo, cancellationToken);
|
||||
|
||||
return photoId;
|
||||
}
|
||||
|
||||
@@ -7,18 +7,11 @@ public class UploadPhotoValidator : AbstractValidator<UploadPhotoCommand>
|
||||
{
|
||||
public UploadPhotoValidator()
|
||||
{
|
||||
RuleFor(x => x.UploadedById)
|
||||
.NotEmpty()
|
||||
.WithMessage("UploadedById is required.");
|
||||
RuleFor(x => x.UploadedById).NotEmpty().WithMessage("UploadedById is required.");
|
||||
|
||||
RuleFor(x => x.File)
|
||||
.NotNull()
|
||||
.WithMessage("File is required.");
|
||||
|
||||
RuleFor(x => x.Key)
|
||||
.NotEmpty()
|
||||
.WithMessage("Key is required.");
|
||||
RuleFor(x => x.File).NotNull().WithMessage("File is required.");
|
||||
|
||||
RuleFor(x => x.Key).NotEmpty().WithMessage("Key is required.");
|
||||
|
||||
RuleFor(x => x.File.Length)
|
||||
.GreaterThan(0)
|
||||
@@ -26,7 +19,9 @@ public class UploadPhotoValidator : AbstractValidator<UploadPhotoCommand>
|
||||
.WithMessage("File cannot be empty.");
|
||||
|
||||
RuleFor(x => x.File.ContentType)
|
||||
.Must(contentType => contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
|
||||
.Must(contentType =>
|
||||
contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)
|
||||
)
|
||||
.When(x => x.File is not null)
|
||||
.WithMessage("File must be an image.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user