mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Add PhotoUpload feature for uploading photos to file storage
Adds UploadPhotoCommand/Handler/Validator and PhotoUploadRepository, invoked via MediatR by other features' commands (e.g. a future CreateBreweryPhoto) rather than exposed through its own controller. Wires the feature and IFileStorageProvider into API.Core.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Features.ImageUploads.Commands.UploadPhoto;
|
||||
|
||||
/// <summary>Validates <see cref="UploadPhotoCommand" />.</summary>
|
||||
public class UploadPhotoValidator : AbstractValidator<UploadPhotoCommand>
|
||||
{
|
||||
public UploadPhotoValidator()
|
||||
{
|
||||
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.Length)
|
||||
.GreaterThan(0)
|
||||
.When(x => x.File is not null)
|
||||
.WithMessage("File cannot be empty.");
|
||||
|
||||
RuleFor(x => x.File.ContentType)
|
||||
.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