* Extended functionalities
* Added different UIs
This commit is contained in:
36
MealPlan.Api/Validators/CreateRecipeValidator.cs
Normal file
36
MealPlan.Api/Validators/CreateRecipeValidator.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using FluentValidation;
|
||||
using MealPlan.Api.DTOs.Recipe;
|
||||
|
||||
namespace MealPlan.Api.Validators;
|
||||
|
||||
public class CreateRecipeValidator : AbstractValidator<CreateRecipeDto>
|
||||
{
|
||||
public CreateRecipeValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty().MaximumLength(255);
|
||||
RuleFor(x => x.MealCategory).InclusiveBetween(0, 3);
|
||||
RuleFor(x => x.Calories).GreaterThanOrEqualTo(0).When(x => x.Calories.HasValue);
|
||||
RuleFor(x => x.PrepTimeMinutes).GreaterThanOrEqualTo(0).When(x => x.PrepTimeMinutes.HasValue);
|
||||
RuleForEach(x => x.Ingredients).SetValidator(new CreateIngredientValidator());
|
||||
RuleForEach(x => x.Steps).SetValidator(new CreateRecipeStepValidator());
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateIngredientValidator : AbstractValidator<CreateIngredientDto>
|
||||
{
|
||||
public CreateIngredientValidator()
|
||||
{
|
||||
RuleFor(x => x.Name).NotEmpty().MaximumLength(255);
|
||||
RuleFor(x => x.Unit).MaximumLength(50).When(x => x.Unit != null);
|
||||
RuleFor(x => x.AmountGrams).GreaterThanOrEqualTo(0).When(x => x.AmountGrams.HasValue);
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateRecipeStepValidator : AbstractValidator<CreateRecipeStepDto>
|
||||
{
|
||||
public CreateRecipeStepValidator()
|
||||
{
|
||||
RuleFor(x => x.StepNumber).GreaterThan(0);
|
||||
RuleFor(x => x.Description).NotEmpty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user