예제 #1
0
        public async Task <ActionResult> GetUserPhotoList(string userId)
        {
            Player player = Player;

            if (player is null)
            {
                _logger.LogWarning("Could not get current player for host {host}", Request.Host);
                return(Unauthorized());
            }

            var targetId = await _userDb.GetInternalIdOfUserAsync(userId);

            if (targetId is null)
            {
                return(NotFound());
            }

            if (!await _friendsDb.IsFriendedToUser(player.Data.Id, targetId.Value))
            {
                return(Forbid());
            }

            var photos = await _photoDb.GetAllPhotosOfUser(targetId.Value);

            var list = new PhotoList();

            foreach (var photo in photos)
            {
                var photoModel = new Photo();
                photoModel.PhotoId    = photo.Id;
                photoModel.CarName    = photo.CarName;
                photoModel.Comment    = photo.Comment;
                photoModel.CreateTime = photo.CreateTime;
                photoModel.Place      = photo.Place;
                photoModel.UserId     = userId;
                list.Photos.Add(photoModel);
            }

            return(Ok(list));
        }
예제 #2
0
        public async Task <ActionResult> Get(string userId)
        {
            var currentPlayer = Player;

            if (currentPlayer is null)
            {
                _logger.LogWarning("Unable to get current player for host '{host}'", Request.Host);
                return(Unauthorized());
            }

            UserProfile userProfile;

            // Is it self?
            if (currentPlayer?.Data?.PSNUserId?.Equals(userId) is true)
            {
                userProfile = UserProfile.FromDatabaseObject(currentPlayer.Data);
            }
            else
            {
                // Possible friend - Check if they're a friend before allowing to get their profile
                UserDTO userData = await _userDb.GetByPSNUserIdAsync(userId);

                if (!await _friendsDb.IsFriendedToUser(currentPlayer.Data.Id, userData.Id))
                {
                    return(Forbid());
                }

                userProfile = UserProfile.FromDatabaseObject(userData);
            }

            userProfile.BandUp         = 1024;
            userProfile.BandDown       = 1024;
            userProfile.BandUpdateTime = DateTime.Now.ToRfc3339String();
            userProfile.BandTest       = 1024;
            return(Ok(userProfile));
        }