Ejemplo n.º 1
0
    def get(self, username, page, per_page, visibility):
        user = User.get_by_username(username=username)
        if not user:
            return {'message': 'User not found'}, HTTPStatus.NOT_FOUND
        current_user = get_jwt_identity()

        if current_user != user.id and visibility != 'public':
            visibility = 'public'
        if visibility not in ['public', 'all', 'private']:
            return {'message': 'Nothing matches the given URI'}, HTTPStatus.NOT_FOUND
        paginated_recipes = Recipe.get_all_by_user(user_id=user.id, page=page, per_page=per_page,
                                                   visibility=visibility)
        return recipe_pagination_schema.dump(paginated_recipes), HTTPStatus.OK
Ejemplo n.º 2
0
 def get(self, username, page, per_page, visibility):
     user = User.get_by_username(username=username)
     if user is None:
         return {'message': 'User not found'}, HTTPStatus.NOT_FOUND
     current_user = get_jwt_identity()
     if current_user == user.id and visibility in ['all', 'private']:
         pass
     else:
         visibility = 'public'
     paginated_recipes = Recipe.get_all_by_user(user_id=user.id,
                                                page=page,
                                                per_page=per_page,
                                                visibility=visibility)
     return recipe_pagination_schema.dump(paginated_recipes), HTTPStatus.OK
Ejemplo n.º 3
0
 def get(self, username):
     page = int(request.args.get("page", 1))
     per_page = int(request.args.get("per_page", 10))
     visibility = request.args.get("visibility", "public")
     user = User.get_by_username(username=username)
     if user is None:
         return {"message": "user not found"}, HTTPStatus.NOT_FOUND
     current_user = get_jwt_identity()
     if current_user == user.id and visibility in ["all", "private"]:
         pass
     else:
         visibility = "public"
     paginated_recipes = Recipe.get_all_by_user(
         user_id=user.id, page=page, per_page=per_page, visibility=visibility
     )
     return recipe_pagination_schema.dump(paginated_recipes), HTTPStatus.OK
Ejemplo n.º 4
0
    def get(self, username, page, per_page, visibility):
        """This method has the logic to retrieve all recipes published by a user."""
        user = User.get_by_username(username=username)

        if user is None:
            return {'message': 'User not found'}, HTTPStatus.NOT_FOUND

        current_user = get_jwt_identity()

        # If the username is the currently authenticated user, then they can
        # see all the recipes
        if current_user == user.id and visibility in ['all', 'private']:
            pass
        else:
            visibility = 'public'

        # Gets the paginated recipes by a particular author
        paginated_recipes = Recipe.get_all_by_user(user_id=user.id, page=page, per_page=per_page, visibility=visibility)

        # Serialize the paginated object and return HTTP Status Code
        return recipe_pagination_schema.dump(paginated_recipes).data, HTTPStatus.OK
Ejemplo n.º 5
0
    def get(self, username, page, per_page, visibility):
        user = User.get_by_username(username=username)

        user = User.get_by_username(username=username)

        if user is None:
            return {'message': 'User not found'}, HTTPStatus.NOT_FOUND

        current_user = get_jwt_identity()
        if current_user == user.id and visibility in ['all', 'private']:
            pass
        else:
            visibility = 'public'

        # gets the paginated recipes by a particular author
        # lets recipe_pagination_schema serialize the paginated object.
        paginated_recipes = Recipe.get_all_by_user(user_id=user.id,
                                                   page=page,
                                                   per_page=per_page,
                                                   visibility=visibility)

        return recipe_pagination_schema.dump(
            paginated_recipes).data, HTTPStatus.OK