public async Task <List <MovieListItemDataModel> > SearchAsync(MovieSearchFilter searchFilter)
        {
            var query = collection.AsQueryable();

            query = ApplyFilters(query, searchFilter);

            return
                (await query.OrderByDescending(doc => doc.CreateAt)
                 .Select(doc => new MovieListItemDataModel
            {
                Id = doc.MovieId,
                Title = doc.Title,
                Cover = doc.Cover != null ? doc.Cover.FileName : string.Empty,
                Description = doc.Description,
                Duration = doc.Duration,
                ImdbRating = doc.Imdb != null ? doc.Imdb.Rating : 0,
                Year = doc.Year
            }).ToListAsync());
        }
        public async Task <IActionResult> SearchAsync([FromQuery] MovieSearchFilter searchFilter)
        {
            var result = await repository.SearchAsync(searchFilter);

            return(Ok(result));
        }
        private IMongoQueryable <MovieDataModel> ApplyFilters(IMongoQueryable <MovieDataModel> query, MovieSearchFilter searchFilter)
        {
            if (!string.IsNullOrWhiteSpace(searchFilter.SearchValue))
            {
                query = query.Where(doc => doc.Title.Contains(searchFilter.SearchValue));
            }

            if (searchFilter.AvailableIn != null && searchFilter.AvailableIn.Any())
            {
                query = query.Where(doc => doc.AvailableIn.Any(lang => searchFilter.AvailableIn.Contains(lang.Code)));
            }

            if (searchFilter.Years != null && searchFilter.Years.Any())
            {
                query = query.Where(doc => searchFilter.Years.Contains(doc.Year));
            }

            if (searchFilter.Countries != null && searchFilter.Countries.Any())
            {
                query = query.Where(doc => doc.Countries.Any(country => searchFilter.Countries.Contains(country.Code)));
            }

            if (searchFilter.Studios != null && searchFilter.Studios.Any())
            {
                query = query.Where(doc => doc.Studios.Any(studio => searchFilter.Studios.Contains(studio.UId)));
            }

            if (searchFilter.ImdbFrom != null)
            {
                query = query.Where(doc => doc.Imdb.Rating >= searchFilter.ImdbFrom);
            }

            if (searchFilter.ImdbTo != null)
            {
                query = query.Where(doc => doc.Imdb.Rating <= searchFilter.ImdbTo);
            }

            return(query);
        }