Esempio n. 1
0
        public async Task <IEnumerable <MovieBaseDto> > Handle(GetMoviesQuery request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Getting movie base information from movie repository");
            try
            {
                var moviesDto = new List <MovieBaseDto>();
                var movies    = await _movieCacheRepository.Select(m => m != null);

                var moviesCounter = movies.Count();

                if (moviesCounter == 0)
                {
                    throw new ArgumentException($"No movies found.");
                }
                foreach (var movie in movies)
                {
                    moviesDto.Add(_movieMapper.MapMovieBaseDto(movie));
                }
                return(moviesDto.OrderByDescending(m => m.LastUpdated));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while getting base information for all movies. Error: {ex.Message}, InnerException {ex.InnerException?.Message}, Stack {ex.StackTrace}");
            }
            return(null);
        }
Esempio n. 2
0
        public async Task <MovieDto> Handle(GetMovieQuery request, CancellationToken cancellationToken)
        {
            var movieDto = new MovieDto();

            try
            {
                _logger.LogInformation("Getting movie details from repository.");
                var movie = await _movieCacheRepository.Select(m => m.id == request.MovieId);

                var moviesCounter = movie.Count();
                if (moviesCounter > 1)
                {
                    throw new ArgumentException($"More than one movie with the same id. Movie Id: {request.MovieId}");
                }
                else if (moviesCounter == 0)
                {
                    throw new KeyNotFoundException($"No movie found with Id: {request.MovieId}");
                }

                movieDto = _movieMapper.MapMovieDto(movie.First());
                //get it from cache
                var cachedData = await _imageRepository.Single(movieDto.Id);

                if (cachedData != null)
                {
                    movieDto.KeyArtImages = cachedData.KeyArtImages;
                    movieDto.CardImages   = cachedData.CardImages;
                }
                else
                {
                    movieDto.KeyArtImages = new Keyartimage[0];
                    movieDto.CardImages   = new Cardimage[0];
                }
                return(movieDto);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while getting Cached image details. Error: {ex.Message}, InnerException {ex.InnerException?.Message}, Stack {ex.StackTrace}");
            }
            return(null);
        }