-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateMovieRequestValidator.cs
More file actions
35 lines (28 loc) · 1.16 KB
/
Copy pathCreateMovieRequestValidator.cs
File metadata and controls
35 lines (28 loc) · 1.16 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
using FluentValidation;
using SmartMovieCatalog.Contracts.Movies;
namespace SmartMovieCatalog.Api.Features.Movies.CreateMovie;
public sealed class CreateMovieRequestValidator : AbstractValidator<CreateMovieRequest>
{
public CreateMovieRequestValidator()
{
RuleFor(request => request.Title)
.NotEmpty();
RuleFor(request => request.ReleaseYear)
.NotNull()
.InclusiveBetween(1888, DateTimeOffset.UtcNow.Year + 1);
RuleFor(request => request.CountryCode)
.NotEmpty()
.Must(countryCode => countryCode is not null &&
countryCode.Trim().Length == 2 &&
countryCode.Trim().All(char.IsLetter))
.WithMessage("Country code must contain exactly two letters.");
RuleFor(request => request.OriginalLanguage)
.NotEmpty();
RuleForEach(request => request.Genres)
.Must(genre => !string.IsNullOrWhiteSpace(genre))
.WithMessage("Genre must not be empty.");
RuleFor(request => request.DurationMinutes)
.GreaterThan(0)
.When(request => request.DurationMinutes.HasValue);
}
}