示例#1
0
    def get(self, story_uid=None):
        """Get a story or a list of a user's stories"""
        request_args = get_current_request_args()

        user_uid = request_args.get('user_uid')

        if user_uid is not None:
            user = User.get_active(uid=user_uid)
            if user is None:
                raise ResourceNotFound('User not found')
        else:
            user = get_current_user()

        if story_uid is not None:
            story = Story.get_active(uid=story_uid, has_expired=False)
            if story is None:
                raise ResourceNotFound('Story not found')

            return api_success_response(data=story.as_json())

        todays_stories = Story.prepare_get_active(user_id=user.id).filter_by(
            has_expired=False).all()

        return api_success_response(
            [story.as_json() for story in todays_stories])
示例#2
0
    def get(self, post_uid=None):
        """Retrieve a post or a list of posts"""
        request_args = get_current_request_args()

        user_uid = request_args.get('user_uid')

        if user_uid is not None:
            user = User.get_active(uid=user_uid)
            if user is None:
                raise ResourceNotFound('User not found')

        else:
            user = get_current_user()

        if post_uid is not None:
            post = Post.get_active(uid=post_uid, user_id=user.id)
            if post is None:
                raise ResourceNotFound('Post not found')

            return api_success_response(data=post.as_json())

        pagination = Post.get_active(user_id=user.id).paginate()

        return api_success_response(
            [item.as_json() for item in pagination.items],
            meta=pagination.meta
        )
示例#3
0
    def get(self, collection_uid=None):
        """Get a list of a user's collections, or """
        request_args = get_current_request_args()

        user_uid = request_args.get('user_uid')

        if user_uid is not None:
            user = User.get_not_deleted(uid=user_uid)
            if user is None:
                raise ResourceNotFound('User not found')

        else:
            user = get_current_user()

        if collection_uid is not None:
            collection = Collection.get_not_deleted(uid=collection_uid,
                                                    user_id=user.id)

            if collection is None:
                raise ResourceNotFound('Collection not found')

            return api_success_response(collection.as_json())

        pagination = user.collections.paginate()

        return api_success_response(
            data=[collection.as_json() for collection in pagination.items()],
            meta=pagination.meta)
    def get(self, hash_tag):
        """Retrieve posts about an hashtag"""
        request_args = get_current_request_args()

        scope = request_args.get('scope') or DEFAULT_HASH_TAG_FETCH_SCOPE
        if scope not in HASH_TAG_RETRIEVAL_SCOPES:
            raise BadRequest(
                '`scope` must be one of {}'.format(HASH_TAG_RETRIEVAL_SCOPES))

        hash_tag = HashTag.get_not_deleted(hash_tag=hash_tag)
        if hash_tag is None:
            raise ResourceNotFound('Hash tag not found')

        hash_tag_details = {
            'meta': lambda x: {
                'data': None,
                'meta': None
            },
            'posts': lambda y: {
                'data': None,
                'meta': None
            },
            'followers': lambda z: {
                'data': None,
                'meta': None
            }
        }

        scoped_details = hash_tag_details[scope]()

        return api_success_response(**scoped_details)
    def get(self):
        """Get a list of users being followed"""
        user = get_current_user()

        pagination = user.followed.filter(
            followers.c.followed_id == user.id).paginate()

        return api_success_response(
            data=[user.as_json() for user in pagination],
            meta=pagination.meta
        )
    def patch(self, username):
        request_data = get_current_request_data()

        params = self.__validate_user_update_params(request_data)

        user = User.get_active(username=username)
        if user is None:
            raise ResourceNotFound('User not found')

        user = self.edit_existing_user(user, params)

        return api_success_response(user.as_json())
    def get(self):
        current_user = get_current_user()

        pagination = Notification.query.filter(
            user_id=current_user.id).paginate()

        data = []
        for item in pagination.items:
            item.mark_as_read()
            data.append(item.as_json())

        return api_success_response(data=data, meta=pagination.meta)
示例#8
0
    def patch(self, collection_uid):
        request_data = get_current_request_data()

        collection = Collection.get_active(collection_uid)
        if collection is None:
            raise ResourceNotFound('Collection not found')

        params = self.__validate_collection_update_params(request_data)

        collection = self.edit_collection(collection, params)

        return api_success_response(collection.as_json())
示例#9
0
    def put(self, collection_uid, post_uid):
        """Add a post to a collection"""
        collection = Collection.get_not_deleted(uid=collection_uid)
        if collection is None:
            raise ResourceNotFound('Collection not found')

        post = Post.get_not_deleted(uid=post_uid)
        if post is None:
            raise ResourceNotFound('Post not found')

        post.update(collection_id=collection.id)

        return api_success_response()
示例#10
0
    def get(self):
        """Get the stories for a user's timeline"""
        user = get_current_user()

        followed = Story.query.join(
            followers, (followers.c.followed_id == Story.user_id)).filter(
                followers.c.follower_id == user.id)

        own = Story.query.filter_by(user_id=user.id)

        pagination = followed.union(own).paginate()

        return api_success_response(
            data=[item.as_json() for item in pagination.items],
            meta=pagination.meta)
示例#11
0
    def patch(self, post_uid):
        """Edit a post"""
        request_data = get_current_request_data()

        post = Post.get_active(uid=post_uid)
        if post is None:
            raise ResourceNotFound('Post not found')

        if post.user != get_current_user():
            raise UnauthorizedError()

        params = self.__validate_post_edit_params(request_data)

        self.edit_post(post, params)

        return api_success_response(post.as_json())
示例#12
0
    def get(self):
        """Get all the posts for a timeline"""
        user = get_current_user()

        followed = Post.query.join(
            followers, (followers.c.followed_id == Post.user_id)
        ).filter(
            followers.c.follower_id == user.id
        )

        own = Post.query.filter_by(
            user_id=user.id
        ).order_by(
            Post.created_at.desc()
        )

        pagination = followed.union(own).paginate()

        return api_success_response(
            data=[item.as_json() for item in pagination.items],
            meta=pagination.meta
        )
    def get(self, username):
        user = User.get_active(username=username)
        if user is None:
            raise ResourceNotFound('User not found')

        return api_success_response(user.as_json())
    def get(self):
        """Get the conversations a user is participating in"""
        user = get_current_user()

        return api_success_response(
            [conversation.as_json() for conversation in user.conversations])
示例#15
0
def render_welcome_greeting():
    return api_success_response("Welcome to {}".format(APP_NAME))