65 lines
2.5 KiB
C#
65 lines
2.5 KiB
C#
using FluentValidation;
|
|
using MealPlan.Api.DTOs.Diet;
|
|
|
|
namespace MealPlan.Api.Validators;
|
|
|
|
public class UserDailyGoalsValidator : AbstractValidator<UserDailyGoalsDto>
|
|
{
|
|
public UserDailyGoalsValidator()
|
|
{
|
|
RuleFor(x => x.CalorieGoal).GreaterThanOrEqualTo(0).When(x => x.CalorieGoal.HasValue);
|
|
RuleFor(x => x.ProteinGoalG).GreaterThanOrEqualTo(0).When(x => x.ProteinGoalG.HasValue);
|
|
RuleFor(x => x.FatGoalG).GreaterThanOrEqualTo(0).When(x => x.FatGoalG.HasValue);
|
|
RuleFor(x => x.CarbsGoalG).GreaterThanOrEqualTo(0).When(x => x.CarbsGoalG.HasValue);
|
|
RuleFor(x => x.WaterGoalMl).GreaterThan(0).When(x => x.WaterGoalMl.HasValue);
|
|
}
|
|
}
|
|
|
|
public class LogMealValidator : AbstractValidator<LogMealDto>
|
|
{
|
|
public LogMealValidator()
|
|
{
|
|
RuleFor(x => x.MealCategory).InclusiveBetween(0, 4);
|
|
RuleFor(x => x.Portions).GreaterThan(0);
|
|
RuleFor(x => x.Name).MaximumLength(255).When(x => x.Name != null);
|
|
RuleFor(x => x)
|
|
.Must(x => x.RecipeId.HasValue || (x.CatalogItemId.HasValue && x.Grams is > 0) || !string.IsNullOrWhiteSpace(x.Name))
|
|
.WithMessage("Provide recipeId, catalogItemId with grams, or name.");
|
|
RuleFor(x => x.Grams).GreaterThan(0).When(x => x.CatalogItemId.HasValue);
|
|
RuleFor(x => x.Calories).GreaterThanOrEqualTo(0).When(x => x.Calories.HasValue);
|
|
}
|
|
}
|
|
|
|
public class LogDrinkValidator : AbstractValidator<LogDrinkDto>
|
|
{
|
|
public LogDrinkValidator()
|
|
{
|
|
RuleFor(x => x.VolumeMl).GreaterThan(0);
|
|
RuleFor(x => x.Name).MaximumLength(255).When(x => x.Name != null);
|
|
RuleFor(x => x)
|
|
.Must(x => x.DrinkCatalogId.HasValue || !string.IsNullOrWhiteSpace(x.Name))
|
|
.WithMessage("Provide either drinkCatalogId or name.");
|
|
RuleFor(x => x.Calories).GreaterThanOrEqualTo(0).When(x => x.Calories.HasValue);
|
|
}
|
|
}
|
|
|
|
public class CreateDietReminderValidator : AbstractValidator<CreateDietReminderDto>
|
|
{
|
|
public CreateDietReminderValidator()
|
|
{
|
|
RuleFor(x => x.ReminderType).InclusiveBetween(0, 3);
|
|
RuleFor(x => x.Title).NotEmpty().MaximumLength(120);
|
|
RuleFor(x => x.Message).MaximumLength(500).When(x => x.Message != null);
|
|
RuleFor(x => x.DaysOfWeekMask).InclusiveBetween(1, 127);
|
|
RuleFor(x => x.MealCategory).InclusiveBetween(0, 4).When(x => x.MealCategory.HasValue);
|
|
}
|
|
}
|
|
|
|
public class UpdateDietReminderValidator : AbstractValidator<UpdateDietReminderDto>
|
|
{
|
|
public UpdateDietReminderValidator()
|
|
{
|
|
Include(new CreateDietReminderValidator());
|
|
}
|
|
}
|