public SelectWatchNextCommandValidator(
            IWatchNextReader watchNextReader,
            IFilmReader filmReader)
        {
            _watchNextReader = watchNextReader;
            _filmReader      = filmReader;

            When(x => !x.FilmId.HasValue, () =>
            {
                RuleFor(x => x.SelectRandomFilm).Must(x => x == true)
                .WithMessage("Must request a randomised film for watch next when not providing a film by ID.");

                RuleFor(x => x.UserId).NotEmpty()
                .WithMessage("Must specify the user ID when requesting a randomised film for watch next.");
            });

            When(x => x.FilmId.HasValue, () =>
            {
                RuleFor(x => x.SelectRandomFilm).Must(x => x == false)
                .WithMessage("Cannot request a randomised film when a specific film ID is provided.");
            });

            RuleFor(x => x.UserId).MustAsync(UserDoesNotHaveWatchNextSelection)
            .WithMessage("User already has a watch next selection. Mark it as watched or skipped first.");

            RuleFor(x => x.UserId).MustAsync(UserHasUnwatchedFilms)
            .WithMessage("User has no unwatched films. Unable to select a new watch next.");
        }
Beispiel #2
0
 public FilmsController(
     ICurrentUserAccessor currentUserAccessor,
     IFilmReader filmReader,
     IEventService eventService)
 {
     _currentUserAccessor = currentUserAccessor;
     _filmReader          = filmReader;
     _eventService        = eventService;
 }
Beispiel #3
0
 public WatchlistController(
     ICurrentUserAccessor currentUserAccessor,
     IWatchlistReader watchlistReader,
     IFilmReader filmReader)
 {
     _currentUserAccessor = currentUserAccessor;
     _watchlistReader     = watchlistReader;
     _filmReader          = filmReader;
 }
Beispiel #4
0
        public UpdateFilmWatchedCommandValidator(IFilmReader filmReader)
        {
            _filmReader = filmReader;

            RuleFor(x => x.ItemId).MustAsync(FilmExists)
            .NotFoundRule();

            RuleFor(x => x.Watched).Must(x => x == true)
            .WithMessage("You cannot unwatch a film.");
        }
Beispiel #5
0
 public UpdateFilmCommandHandler(
     IFilmReader filmReader,
     IValidator <UpdateFilmCommand> validator,
     IEventService eventService,
     FilmQueueDbUnitOfWork unitOfWork)
 {
     _filmReader   = filmReader;
     _validator    = validator;
     _eventService = eventService;
     _unitOfWork   = unitOfWork;
 }
Beispiel #6
0
        public ExpireWatchNextSelectionCommandValidator(
            IWatchNextReader watchNextReader,
            IFilmReader filmReader)
        {
            _watchNextReader = watchNextReader;
            _filmReader      = filmReader;

            RuleFor(x => x.FilmId).MustAsync(FilmExists)
            .NotFoundRule();

            RuleFor(x => x.FilmId).MustAsync(IsActiveWatchNext)
            .WithMessage("Film is not the active watch next selection.");
        }
 public SelectWatchNextCommandHandler(
     IWatchNextWriter watchNextWriter,
     IFilmReader filmReader,
     IValidator <SelectWatchNextCommand> validator,
     IEventService eventService,
     IWatchNextReader watchNextReader)
 {
     _watchNextWriter = watchNextWriter;
     _filmReader      = filmReader;
     _validator       = validator;
     _eventService    = eventService;
     _watchNextReader = watchNextReader;
 }
Beispiel #8
0
        public UpdateFilmCommandValidator(IFilmReader filmReader)
        {
            _filmReader = filmReader;

            RuleFor(x => x.FilmId).MustAsync(FilmExists)
            .NotFoundRule();

            RuleFor(x => x.Title).NotEmpty()
            .WithMessage("Title is a required field.");

            RuleFor(x => x.Title).MaximumLength(200)
            .WithMessage("Title cannot be longer than 200 characters");

            RuleFor(x => x.RuntimeInMinutes).GreaterThan(0)
            .WithMessage("Runtime is not valid. Must be positive whole number.");
        }