Beispiel #1
0
        public async Task <ActionResult <IEnumerable <ComparedPlace> > > GetRecommendedEstablishmentsForPlaylist(string playlistId, double lat, double lon, double distance, int page = 1, int pageSize = 25)
        {
            string userId = GetUserId();
            var    client = new HttpClient();

            //Get his spotify token
            var user = await _userService.GetUser(userId);

            var token = user.CurrentToken;
            //Get playlist songs from spotify

            var spotiPlaylist = await _spotify.GetPlaylist(client, token, playlistId);

            if (spotiPlaylist == null)
            {
                return(Unauthorized("Please refresh your spotify token"));
            }
            log.LogInformation("Spoti playlist not null");
            var playlist = new GrooverAdm.Entities.Application.Playlist
            {
                Id              = playlistId,
                Name            = spotiPlaylist.Name,
                SnapshotVersion = spotiPlaylist.Snapshot_id,
                ImageUrl        = spotiPlaylist.Images[0]?.Url,
                Songs           = spotiPlaylist.Tracks.Items.Select(s =>
                                                                    new GrooverAdm.Entities.Application.Song
                {
                    Artists = s.Track.Artists.Select(a => new GrooverAdm.Entities.Application.Artist {
                        Id = a.Id, Name = a.Name
                    }).ToList(),
                    Id   = s.Track.Id,
                    Name = s.Track.Name
                }).ToList()
            };

            //Match with storedSongs in Db for tags
            var places = await _placesService.GetRecommendedPlaces(page, pageSize, new Geolocation(lat, lon), distance, playlist, token);

            log.LogInformation(places.ToString());
            return(Ok(places));
        }