Files
MetaCourseApi/MetaCourse.Api/Validators/Topics/CreateTopicDtoValidator.cs
T
2026-05-05 10:39:43 +02:00

29 lines
979 B
C#

using FastEndpoints;
using FluentValidation;
using MetaCourse.Api.DTOs.Topics;
namespace MetaCourse.Api.Validators.Topics;
public class CreateTopicDtoValidator : Validator<CreateTopicDto>
{
public CreateTopicDtoValidator()
{
RuleFor(x => x.CourseId)
.NotEqual(Guid.Empty).WithMessage("L'identifiant du cours est invalide.");
RuleFor(x => x.Title)
.NotEmpty().WithMessage("Le titre est requis.")
.MinimumLength(2).WithMessage("Le titre doit contenir au moins 2 caractères.")
.MaximumLength(200).WithMessage("Le titre ne peut pas dépasser 200 caractères.");
When(x => x.Description != null, () =>
{
RuleFor(x => x.Description)
.MaximumLength(1000).WithMessage("La description ne peut pas dépasser 1000 caractères.");
});
RuleFor(x => x.Position)
.GreaterThan(0).WithMessage("La position doit être supérieure à 0.");
}
}