mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using FluentValidation;
|
|
|
|
namespace Features.Breweries.Commands.CreateBrewery;
|
|
|
|
/// <summary>
|
|
/// Applies creation rules to <see cref="CreateBreweryCommand" />.
|
|
/// </summary>
|
|
public class CreateBreweryValidator : AbstractValidator<CreateBreweryCommand>
|
|
{
|
|
public CreateBreweryValidator()
|
|
{
|
|
RuleFor(x => x.PostedById).NotEmpty().WithMessage("PostedById is required.");
|
|
|
|
RuleFor(x => x.BreweryName)
|
|
.NotEmpty()
|
|
.WithMessage("Brewery name is required.")
|
|
.MaximumLength(256)
|
|
.WithMessage("Brewery name cannot exceed 256 characters.");
|
|
|
|
RuleFor(x => x.Description)
|
|
.NotEmpty()
|
|
.WithMessage("Description is required.")
|
|
.MaximumLength(512)
|
|
.WithMessage("Description cannot exceed 512 characters.");
|
|
|
|
RuleFor(x => x.Location).NotNull().WithMessage("Location is required.");
|
|
|
|
RuleFor(x => x.Location.CityId)
|
|
.NotEmpty()
|
|
.WithMessage("CityId is required.")
|
|
.When(x => x.Location != null);
|
|
|
|
RuleFor(x => x.Location.AddressLine1)
|
|
.NotEmpty()
|
|
.WithMessage("Address line 1 is required.")
|
|
.MaximumLength(256)
|
|
.WithMessage("Address line 1 cannot exceed 256 characters.")
|
|
.When(x => x.Location != null);
|
|
|
|
RuleFor(x => x.Location.PostalCode)
|
|
.NotEmpty()
|
|
.WithMessage("Postal code is required.")
|
|
.MaximumLength(20)
|
|
.WithMessage("Postal code cannot exceed 20 characters.")
|
|
.When(x => x.Location != null);
|
|
}
|
|
}
|