-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMenuReviewValidators.cs
More file actions
42 lines (37 loc) · 1.48 KB
/
Copy pathMenuReviewValidators.cs
File metadata and controls
42 lines (37 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace BuberDinner.Application.MenuReviews.Validators;
using BuberDinner.Application.MenuReviews.Commands;
using FluentValidation;
/// <summary>
/// Validates <see cref="SubmitMenuReviewCommand"/> at the Trellis Mediator
/// <c>ValidationBehavior</c> stage — runs BEFORE the handler, short-circuits to
/// 422 Problem Details on failure with one field violation per offending property.
/// Wired by <c>services.AddTrellisFluentValidation(typeof(SubmitMenuReviewCommandValidator).Assembly)</c>.
/// </summary>
public sealed class SubmitMenuReviewCommandValidator : AbstractValidator<SubmitMenuReviewCommand>
{
public SubmitMenuReviewCommandValidator()
{
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage("Rating must be between 1 and 5.");
RuleFor(x => x.Comment)
.NotEmpty()
.WithMessage("Comment is required.")
.MaximumLength(1000)
.WithMessage("Comment must not exceed 1000 characters.");
}
}
public sealed class UpdateMenuReviewCommandValidator : AbstractValidator<UpdateMenuReviewCommand>
{
public UpdateMenuReviewCommandValidator()
{
RuleFor(x => x.Rating)
.InclusiveBetween(1, 5)
.WithMessage("Rating must be between 1 and 5.");
RuleFor(x => x.Comment)
.NotEmpty()
.WithMessage("Comment is required.")
.MaximumLength(1000)
.WithMessage("Comment must not exceed 1000 characters.");
}
}