Initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using FastEndpoints;
|
||||
using FluentValidation;
|
||||
using MetaCourse.Api.DTOs.Topics;
|
||||
|
||||
namespace MetaCourse.Api.Validators.Topics;
|
||||
|
||||
public class UpdateTopicDtoValidator : Validator<UpdateTopicDto>
|
||||
{
|
||||
public UpdateTopicDtoValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
.NotEqual(Guid.Empty).WithMessage("L'identifiant 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.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user