public async Task <ChuckNorrisQuote[]> Search(CancellationToken ct, string searchTerm) { if (string.IsNullOrEmpty(searchTerm)) { return(Array.Empty <ChuckNorrisQuote>()); } var response = await _chuckNorrisEndpoint.Search(ct, searchTerm); var settings = await _applicationSettingsService.GetCurrent(ct); return(response .Quotes .Safe() .Select(d => new ChuckNorrisQuote(d, settings.FavoriteQuotes.ContainsKey(d.Id))) .ToArray()); }
public async Task <ChuckNorrisQuote[]> Search(CancellationToken ct, string searchTerm) { // If the search term does not contain at least 3 characters, the API returns an exception. // It must be handle on app side. if (string.IsNullOrEmpty(searchTerm) || searchTerm.Length < 3) { return(Array.Empty <ChuckNorrisQuote>()); } var response = await _chuckNorrisEndpoint.Search(ct, searchTerm); var settings = await _applicationSettingsService.GetCurrent(ct); return(response .Quotes .Safe() .Select(d => new ChuckNorrisQuote(d, settings.FavoriteQuotes.ContainsKey(d.Id))) .ToArray()); }