Ejemplo n.º 1
0
        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());
            }
        }