public List <Track> SearchTrack(string name, SearchEnum type) { var responseService = _searchService.Search(name, type.ToString()); var arrItem = ((TrackSearch)responseService).tracks.items; List <Track> listTrack = new List <Track>(); for (int i = 0; i < arrItem.Length; i++) { var trackFeatures = _searchService.TrackFeatures(arrItem[i].id); Track track = new Track() { name = arrItem[i].name, id = arrItem[i].id, trackLength = arrItem[i].duration_ms, albumName = arrItem[i].album.name, artistName = arrItem[i].artists[0].name, previewUrl = arrItem[i].preview_url, favorite = false, type = arrItem[i].type, images = ImageMapper.ImageMapping(arrItem[i].album.images), }; track.TrackMapping(trackFeatures); listTrack.Add(track); } return(listTrack); }
public List <Artist> SearchArtist(string name, SearchEnum type) { var responseService = _searchService.Search(name, type.ToString()); var arrItem = ((ArtistSearch)responseService).artists.items; List <Artist> listArtista = new List <Artist>(); for (int i = 0; i < arrItem.Length; i++) { var alb = new ArtistBusiness(); Artist artist = new Artist() { name = arrItem[i].name, id = arrItem[i].id, type = arrItem[i].type, genres = arrItem[i].genres, popularity = arrItem[i].popularity, images = ImageMapper.ImageMapping(arrItem[i].images) }; listArtista.Add(artist); } return(listArtista); }
public List <Album> SearchAlbum(string name, SearchEnum type) { var responseService = _searchService.Search(name, type.ToString()); var arrItem = ((AlbumSearch)responseService).albums.items; List <Album> listAlbum = new List <Album>(); for (int i = 0; i < arrItem.Length; i++) { var tr = new AlbumBusiness(); Album album = new Album() { name = arrItem[i].name, id = arrItem[i].id, type = arrItem[i].album_type, totalTracks = arrItem[i].total_tracks, albumArtist = arrItem[i].artists[0].name, images = ImageMapper.ImageMapping(arrItem[i].images) }; listAlbum.Add(album); } return(listAlbum); }
public async Task <IActionResult> Get(string queryString, string url, SearchEnum searchProvicer) { if (string.IsNullOrEmpty(queryString) || string.IsNullOrEmpty(url)) { return(BadRequest("QueryString or Url should not be empty.")); } var cacheKey = queryString.ToLower() + "_" + url.ToLower() + "_" + searchProvicer.ToString().ToLower(); // TODO : Ideally will use distributed caching like REDIS provided by AWS ElastiCache instead of in memory cache. if (!_memoryCache.TryGetValue(cacheKey, out string rank)) { rank = await _searchFactory.GetSearchProvider(searchProvicer).Search(queryString, url); var cacheExpirationOption = new MemoryCacheEntryOptions { AbsoluteExpiration = DateTime.Now.AddHours(1) }; _memoryCache.Set(cacheKey, rank, cacheExpirationOption); } return(Ok(rank.Split(','))); }