public IActionResult GetAllWordsByCollectionId(int id)
        {
            // Get current User
            var firebaseUser = _utils.GetCurrentUser(User);

            // If this person is an anonymous user, return NotFound
            if (firebaseUser == null)
            {
                return(NotFound());
            }

            try
            {
                // If a user attempts to get an Id not in the db, causes a NullReferenceException error
                List <Word> words = _wordRepo.GetByCollectionId(id);

                // If  collection, return not found
                if (words == null)
                {
                    return(NotFound());
                }

                // If this is not that user's post, don't return it
                if (words[0].UserId != firebaseUser.Id)
                {
                    return(NotFound());
                }

                return(Ok(words));
            }
            catch (NullReferenceException e)
            {
                return(NotFound());
            }
        }
示例#2
0
        public IActionResult GetByUserId()
        {
            var firebaseUser = _utils.GetCurrentUser(User);

            // If this person is an anonymous user, return NotFound
            if (firebaseUser == null)
            {
                return(NotFound());
            }

            List <Project> projects = _projectRepo.Get(firebaseUser.Id);

            if (projects == null)
            {
                return(NotFound());
            }

            return(Ok(projects));
        }
示例#3
0
        public IActionResult GetAll()
        {
            // GetAll is specifically for testing
            // Only User with Id of 1 (me and the test) will be able to access it.
            User attemptingUser = _utils.GetCurrentUser(User);

            if (attemptingUser == null)
            {
                return(NotFound());
            }

            if (attemptingUser.Id != 1)
            {
                return(NotFound());
            }

            List <User> users = _repo.Get();

            return(Ok(users));
        }