/// <summary>
        /// Returns the closest matching show associated with any of the name values (by title).
        /// </summary>
        /// <param name="names">Titles of the show, should be ordered by priority.</param>
        /// <exception cref="SearchNotFoundException">
        /// Thrown if no value is found from the search.
        /// </exception>
        public async Task <Show> SearchAsync(IEnumerable <string> names)
        {
            if (names == null)
            {
                throw new ArgumentNullException(nameof(names));
            }
            if (!names.Any())
            {
                throw new ArgumentException(nameof(names));
            }

            // DB.
            var dbShows = await _showRepository.FindAsync(names);

            var foundShow = FindExactShow(names, dbShows);

            if (foundShow != null)
            {
                return(foundShow);
            }

            // API.
            var apiShows = await _apiSearch.FindShowAsync(names);

            foundShow = FindExactShow(names, apiShows);
            if (foundShow != null)
            {
                return(await SaveShow(foundShow, names.First()));
            }

            // DB + API 'close' match.
            foundShow = FindSimilarShow(names, dbShows.Concat(apiShows));
            if (foundShow == null)
            {
                throw new SearchNotFoundException(string.Join(", ", names));
            }
            else if (foundShow.Id == 0)
            {
                return(await SaveShow(foundShow, names.First()));
            }
            else
            {
                return(foundShow);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Episode(string episodeName)
        {
            _logger.LogDebug($"Episode Search Request: {episodeName ?? "NULL"}");

            if (string.IsNullOrWhiteSpace(episodeName))
            {
                return(BadRequest($"Search value cannot be empty."));
            }

            try {
                var episode = await _episodeSearch.SearchAsync(episodeName);

                var show = await _showRepo.FindAsync(episode.ShowId);

                _logger.LogDebug($"Found Episode for Show {show.GetPrimaryTitle()} (ID: {show.Id}), Episode Number {episode.EpisodeNumber} (ID: {episode.Id})");
                return(Ok(new EpisodeSearchResponse(episode, show)));
            }
            catch (SearchNotFoundException) {
                _logger.LogInformation($"Could not find result for Search Request: {episodeName}");
                return(NotFound($"No results found for: {episodeName}"));
            };
        }
        /// <summary>
        /// Returns model of show by id
        /// </summary>
        /// <param name="id">Id of existing show</param>
        /// <returns></returns>
        public async Task <ShowModel> GetShowById(string id)
        {
            var res = await _seasonRepository.FindByShowId(id);

            return(await _showRepository.FindAsync(id));
        }
Beispiel #4
0
 public async Task <Maybe <Show> > GetShowAsync(int id, CancellationToken cancellationToken)
 {
     return(await _showRepository.FindAsync(id, cancellationToken));
 }