Beispiel #1
0
    def get(self):
        recipes = Recipe.get_all_published()
        data = []

        for recipe in recipes:
            data.append(recipe.data())

        return {'data': data}, HTTPStatus.OK
Beispiel #2
0
 def get(self, q, page, per_page, sort, order):
     # get all recipes (that published)
     print('Quering the database..')
     if sort not in ['created_at', 'cook_time', 'num_of_servings']:
         sort = 'created_at'
     if order not in ['asc', 'desc']:
         order = 'desc'
     paginated_recipes = Recipe.get_all_published(q, page, per_page, sort, order)
     return recipe_pagination_schema.dump(paginated_recipes), HTTPStatus.OK
Beispiel #3
0
 def get(self, q, page, per_page, sort, order):
     if sort not in ['created_at', 'cook_time', 'num_of_servings']:
         sort = 'created_at'
     if order not in ['asc', 'desc']:
         order = 'desc'
     paginated_recipes = Recipe.get_all_published(page=page,
                                                  per_page=per_page,
                                                  sort=sort,
                                                  order=order,
                                                  q=q)
     return recipe_pagination_schema.dump(
         paginated_recipes).data, HTTPStatus.OK
Beispiel #4
0
    def get(self, q, page, per_page, sort, order):
        """This method have the logic to retrieve
         all recipes, paginate, sort results and search for recipes"""

        # Accept only the created_at, cook_time, and num_of_servings values
        if sort not in ['created_at', 'cook_time', 'num_of_servings']:
            sort = 'created_at'

        # Accept only the asc and desc values
        if order not in ['asc', 'desc']:
            order = 'desc'

        paginated_recipes = Recipe.get_all_published(q, page, per_page, sort, order)

        return recipe_pagination_schema.dump(paginated_recipes).data, HTTPStatus.OK
Beispiel #5
0
    def get(self):
        sort = request.args.get("sort", "created_at")
        order = request.args.get("order", "desc")
        q = request.args.get("q", "")
        per_page = int(request.args.get("per_page", 10))
        page = int(request.args.get("page", 1))

        if sort not in ["created_at", "cook_time", "num_of_servings"]:
            sort = "created_at"
        if order not in ["asc", "desc"]:
            order = "desc"

        paginated_recipes = Recipe.get_all_published(q, page, per_page, order,
                                                     sort)
        return recipe_pagination_schema.dump(paginated_recipes), HTTPStatus.OK
Beispiel #6
0
    def get(self, q, page, per_page, sort, order):
        """
        Passes three arguments in the get_all_published method
        and gets the pagination object back. returns the
        paginated recipes as serialized and back to front
        end client. The q parameter passed the search string into the API
        """
        print('Querying database')
        if sort not in ['created_at', 'cook_time', 'num_of_servings']:
            sort = 'created_at'
        if order not in ['asc', 'desc']:
            order = 'desc'

        paginated_recipes = Recipe.get_all_published(q, page, per_page, sort,
                                                     order)
        return recipe_pagination_schema.dump(
            paginated_recipes).data, HTTPStatus.OK
Beispiel #7
0
    def get(self, q, page, per_page):

        paginated_recipes = Recipe.get_all_published(q, page, per_page)

        return recipe_pagination_schema.dump(
            paginated_recipes).data, HTTPStatus.OK
Beispiel #8
0
    def get(self):

        recipes = Recipe.get_all_published()

        return recipe_list_schema.dump(recipes).data, HTTPStatus.OK