Exemplo n.º 1
0
    def get(self):
        brands = Brand.query.all()
        brands = list(map(lambda x: x.serialize(), brands))

        return jsonify(get_paginated_list(brands,
                                          start=request.args.get('start', 1),
                                          limit=request.args.get('limit', 20)
                                          ))
Exemplo n.º 2
0
    def get(self):
        sizes = Sizes_shoes.query.all()
        sizes = list(map(lambda x: x.serialize(), sizes))

        return jsonify(
            get_paginated_list(
                sizes,
                start=request.args.get("start", 1),
                limit=request.args.get("limit", 20),
            ))
Exemplo n.º 3
0
    def get(self):
        categories = Category.query.all()
        categories = list(map(lambda x: x.serialize(), categories))

        return jsonify(
            get_paginated_list(
                categories,
                start=request.args.get("start", 1),
                limit=request.args.get("limit", 20),
            ))
Exemplo n.º 4
0
    def get(self):
        media = Media_storage.query.all()
        media = list(map(lambda x: x.serialize(), media))

        return jsonify(
            get_paginated_list(
                media,
                start=request.args.get("start", 1),
                limit=request.args.get("limit", 20),
            ))
Exemplo n.º 5
0
 def get(self, woman: float):
     sizes = Sizes_shoes.query.filter_by(woman=woman).all()
     if sizes:
         sizes = list(map(lambda x: x.serialize(), sizes))
         return jsonify(
             get_paginated_list(
                 sizes,
                 start=request.args.get("start", 1),
                 limit=request.args.get("limit", 20),
             ))
     abort(404, f"Sizes with woman size {woman} do not exist")
Exemplo n.º 6
0
    def get(self):
        products = Product_detail.query.all()
        products = list(map(lambda x: x.serialize(), products))

        return jsonify(
            get_paginated_list(
                products,
                start=request.args.get("start", 1),
                limit=request.args.get("limit", 20),
            )
        )
Exemplo n.º 7
0
 def get(self, brand_id: int):
     sizes = Sizes_shoes.query.filter_by(brand_id=brand_id).all()
     if sizes:
         sizes = list(map(lambda x: x.serialize(), sizes))
         return jsonify(
             get_paginated_list(
                 sizes,
                 start=request.args.get("start", 1),
                 limit=request.args.get("limit", 20),
             ))
     abort(404, f"Sizes with brand id {brand_id} do not exist")
Exemplo n.º 8
0
 def get(self, uk: str):
     sizes = Sizes_shoes.query.filter_by(uk=uk).all()
     if sizes:
         sizes = list(map(lambda x: x.serialize(), sizes))
         return jsonify(
             get_paginated_list(
                 sizes,
                 start=request.args.get("start", 1),
                 limit=request.args.get("limit", 20),
             ))
     abort(404, f"Sizes with uk {uk} do not exist")
Exemplo n.º 9
0
 def get(self, id: int):
     media = Media_storage.query.filter_by(product_id=id).all()
     if media:
         media = list(map(lambda x: x.serialize(), media))
         return jsonify(
             get_paginated_list(
                 media,
                 start=request.args.get("start", 1),
                 limit=request.args.get("limit", 10),
             ))
     abort(404, f"Media with product id {id} does not exist")
Exemplo n.º 10
0
    def get(self, id: int):
        products = Product_detail.query.filter_by(sizes_shoes_id=id).all()

        if products:
            products = list(map(lambda x: x.serialize(), products))
            return jsonify(
                get_paginated_list(
                    products,
                    start=request.args.get("start", 1),
                    limit=request.args.get("limit", 20),
                )
            )
        abort(400)
Exemplo n.º 11
0
    def get(self, last_sale: float):
        products = Product_detail.query.filter_by(last_sale=last_sale).all()
        # products = Product_detail.query.filter(Product_detail.last_sale<=last_sale) -- for queries less then or more then !!!
        if products:
            products = list(map(lambda x: x.serialize(), products))

            return jsonify(
                get_paginated_list(
                    products,
                    start=request.args.get("start", 1),
                    limit=request.args.get("limit", 20),
                )
            )
        abort(400)
Exemplo n.º 12
0
    def get(self, sales: int):
        products = Product_detail.query.filter_by(sales=sales).all()
        # products = Product_detail.query.filter(Product_detail.sales<=sales) -- for queries less then or more then !!!
        if products:
            products = list(map(lambda x: x.serialize(), products))

            return jsonify(
                get_paginated_list(
                    products,
                    start=request.args.get("start", 1),
                    limit=request.args.get("limit", 20),
                )
            )
        else:
            abort(400)
Exemplo n.º 13
0
def search_university(search_term):
    search_results = []
    for uni in Universities:
        if search_term in uni['name'].lower():
            search_results.append(uni)
        else:
            pass

    return jsonify(
        get_paginated_list(
            search_results,
            f"/api/universities/search/{search_term}",
            request.args.get("start", 1),
            request.args.get("limit", 2),
        ))
Exemplo n.º 14
0
def filter_university(country_code):
    search_results = []
    for uni in Universities:

        if country_code.upper() in uni['alpha_two_code']:
            search_results.append(uni)
        else:
            pass

    return jsonify(
        get_paginated_list(
            search_results,
            f"/api/universities/search/filter/{country_code}",
            request.args.get("start", 1),
            request.args.get("limit", 2),
        ))
Exemplo n.º 15
0
    def get(self, date: str):
        products = Product_detail.query.filter(
            Product_detail.last_sale_date.contains(date)
        )
        # products = Product_detail.query.filter(Product_detail.last_sale_date<=date) -- for queries less then or more then !!!
        if products:
            products = list(map(lambda x: x.serialize(), products))

            return jsonify(
                get_paginated_list(
                    products,
                    start=request.args.get("start", 1),
                    limit=request.args.get("limit", 20),
                )
            )
        abort(400)
Exemplo n.º 16
0
    def post(self):
        """Create a amazingresources

        TITLE:Sample
        <pre>
        CURL:"/amazingresources" -d '{"description": "..."}'
        </pre>
        """

        self.initializeAPI()

        if g.dryrun:
            AmazingresourcesRecord = {
                'id': 'this-is-my-id',
                'description': g.args["description"],
            }
            return AmazingresourcesRecord, 200, {}

        kwargs = copy.deepcopy(g.args)
        kwargs.pop('range', None)
        kwargs.pop('async', None)
        async_result = CONSUMER_APP.send_task('amazingresources.post',
                                              kwargs=kwargs,
                                              queue='amazingresources')

        if g.args['async']:
            headers = {
                'Location':
                url_for('amazingresourcesStatusById',
                        id=async_result.id,
                        _external=True),
                'Content-Location':
                url_for('amazingresourcesById',
                        id=async_result.id,
                        _external=True),
            }

            return {}, 202, headers
        else:
            resp = async_result.get()
            if not isinstance(resp['results'], list):
                resp['results'] = [resp['results']]
            return get_paginated_list(resp['results'], async_result.id,
                                      g.args['range'], 'amazingresourcesById')
Exemplo n.º 17
0
Arquivo: app.py Projeto: imzboy/test
    def get(self):
        args = request.args
        if (id := args.get('id')):
            product = Product.query.filter_by(id=id).first()

            # A little serializer for reviews
            reviews = [{
                'id': r.id,
                'title': r.title,
                'review': r.review
            } for r in Review.query.filter_by(product_id=product.id).all()]

            start = args.get('start', 1)
            limit = args.get('limit', 20)
            url = request.base_url

            result = get_paginated_list(reviews, url, start, limit)
            result['product'] = {'asin': product.asin, 'title': product.title}

            return result, 200
Exemplo n.º 18
0
def get():
    # GET all universities
    if request.method == "GET":
        universities = Universities

        return jsonify(
            get_paginated_list(
                universities,
                "/api/universities",
                request.args.get("start", 1),
                request.args.get("limit", 2),
            ))
    else:
        # CREATE a new university
        id = random.random()
        alpha_two_code = request.json['alpha_two_code']
        country = request.json['country']
        domain = request.json['domain']
        name = request.json['name']
        web_page = request.json['web_page']
        description = request.json['description']
        img_url = request.json['img_url']

    # build university object from the request sent
    created_university = {
        "id": id,
        "alpha_two_code": alpha_two_code,
        "country": country,
        "domain": domain,
        "name": name,
        "web_page": web_page,
        "description": description,
        "img_url": img_url
    }

    # append the newly created university to the existing universities list
    Universities.append(created_university)
    # return the newly created univeersity
    return jsonify(created_university)
Exemplo n.º 19
0
    def get(self, id):
        """Get amazingresources

        Get amazingresources informations

        TITLE:Sample
        <pre>
        CURL:"/amazingresources/<id>"
        </pre>
        """

        # verify request
        self.initializeAPI(data={"id": id})

        if g.dryrun:
            AmazingresourcesRecord = {
                'id': 'this-is-my-id',
                'description': g.args["description"],
            }
            return AmazingresourcesRecord, 200

        kwargs = copy.deepcopy(g.args)
        async_result = AsyncResult(id, app=CONSUMER_APP)

        # Check if we are getting a resource or a task result. (A resource being
        # a task.get result)
        if async_result.state == 'SUCCESS':
            resp = async_result.get()
            if not resp.get('success', False):
                return resp.get('error_msg', 'Task failed'), 200
            if not resp.get('results', False):
                resp['results'] = []
            if not isinstance(resp['results'], list):
                resp['results'] = [resp['results']]
            return get_paginated_list(resp['results'], async_result.id,
                                      g.args['range'], 'amazingresourcesById')

        return {}, 404
Exemplo n.º 20
0
    def post(self):
        """Test check

        Run test task

        TITLE:Sample
        <pre>
        CURL:"/amazingresources/_test" -d '{"description": "..."}'
        </pre>
        """

        self.initializeAPI()

        kwargs = copy.deepcopy(g.args)
        kwargs.pop('async', None)
        kwargs.pop('range', None)
        async_result = CONSUMER_APP.send_task('amazingresources.test',
                                              kwargs=kwargs,
                                              queue='amazingresources')

        if g.args['async']:
            headers = {
                'Location':
                url_for('amazingresourcesStatusById',
                        id=async_result.id,
                        _external=True),
                'Content-Location':
                url_for('amazingresourcesById',
                        id=async_result.id,
                        _external=True),
            }

            return {}, 202, headers
        resp = async_result.get()
        if not isinstance(resp['results'], list):
            resp['results'] = [resp['results']]
        return get_paginated_list(resp['results'], async_result.id,
                                  g.args['range'], 'amazingresourcesById')
 def get(self):
     args = parser.parse_args()
     return get_paginated_list(todos, args=args)