photo validators fixed
This commit is contained in:
@@ -2,19 +2,19 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
|
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
|
||||||
using WatchIt.Common.Model.Media;
|
using WatchIt.Common.Model.Media;
|
||||||
using WatchIt.Database;
|
using WatchIt.Database;
|
||||||
|
using WatchIt.WebAPI.Validators.Photos;
|
||||||
|
|
||||||
namespace WatchIt.WebAPI.Validators.Media;
|
namespace WatchIt.WebAPI.Validators.Media;
|
||||||
|
|
||||||
public class MediaPhotoRequestValidator : AbstractValidator<MediaPhotoRequest>
|
public class MediaPhotoRequestValidator : AbstractValidator<MediaPhotoRequest>
|
||||||
{
|
{
|
||||||
public MediaPhotoRequestValidator(DatabaseContext database)
|
public MediaPhotoRequestValidator()
|
||||||
{
|
{
|
||||||
RuleFor(x => x.Image).NotEmpty();
|
RuleFor(x => x.Image).NotEmpty();
|
||||||
RuleFor(x => x.MimeType).Matches(@"\w+/.+").WithMessage("Incorrect mimetype");
|
RuleFor(x => x.MimeType).Matches(@"\w+/.+").WithMessage("Incorrect mimetype");
|
||||||
When(x => x.Background is not null, () =>
|
When(x => x.Background is not null, () =>
|
||||||
{
|
{
|
||||||
RuleFor(x => x.Background!.FirstGradientColor).Must(x => x.Length == 3).WithMessage("First gradient color has to be 3 byte long");
|
RuleFor(x => x.Background!).SetValidator(new PhotoBackgroundDataValidator());
|
||||||
RuleFor(x => x.Background!.SecondGradientColor).Must(x => x.Length == 3).WithMessage("Second gradient color has to be 3 byte long");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using WatchIt.Common.Model.Photos;
|
||||||
|
|
||||||
|
namespace WatchIt.WebAPI.Validators.Photos;
|
||||||
|
|
||||||
|
public class PhotoBackgroundDataRequestValidator : AbstractValidator<PhotoBackgroundDataRequest>
|
||||||
|
{
|
||||||
|
public PhotoBackgroundDataRequestValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x).SetValidator(new PhotoBackgroundDataValidator());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using WatchIt.Common.Model.Photos;
|
||||||
|
|
||||||
|
namespace WatchIt.WebAPI.Validators.Photos;
|
||||||
|
|
||||||
|
public class PhotoBackgroundDataValidator : AbstractValidator<PhotoBackgroundData>
|
||||||
|
{
|
||||||
|
public PhotoBackgroundDataValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.FirstGradientColor).Must(x => x.Length == 3).WithMessage("First gradient color has to be 3 byte long");
|
||||||
|
RuleFor(x => x.SecondGradientColor).Must(x => x.Length == 3).WithMessage("Second gradient color has to be 3 byte long");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user