Beispiel #1
0
def add_one_product():
    name = request.get_json().get('name')
    products = Product(id=3, name=name, description=name)
    print(products)
    products = db.session.add(products) # SQLAlchemy request => 'SELECT * FROM products'
    db.session.commit()
    return one_product_schema.jsonify(products), 200
Beispiel #2
0
def read_one_product(id):
    content = request.get_json()
    if content is None:
        abort(400)

    product = db.session.query(Product).get(id)
    if product is None:
        abort(404)
    return one_product_schema.jsonify(product), 200
Beispiel #3
0
def post_one_product():
    content = request.get_json()
    if content is None:
        abort(400)

    product = Product()
    product.name = content['name']
    db.session.add(product)
    db.session.commit()
    return one_product_schema.jsonify(product), 201
Beispiel #4
0
def create_one_product():
    content = request.json
    name = content.get('name', None)
    description = content.get('description', '')
    if name is None:
        return {}, 404
    new_product = Product(name=name, description=description)
    db.session.add(new_product)
    db.session.commit()
    return one_product_schema.jsonify(new_product), 201
Beispiel #5
0
def update_one_product(id):
    product = db.session.query(Product).get(id)
    if product is None:
        return {}, 404
    content = request.json
    name = content.get('name', None)
    description = content.get('description', None)
    if name is not None and name != '':
        product.name = name
    if description is not None and description != '':
        product.description = description
    db.session.add(product)
    db.session.commit()
    return one_product_schema.jsonify(product), 201
Beispiel #6
0
def get_one_product(id):
    products = db.session.query(Product).get(id) # SQLAlchemy request => 'SELECT * FROM products'
    return one_product_schema.jsonify(products), 200
Beispiel #7
0
def get_one_product(id):
    product = db.session.query(Product).get(id)
    return one_product_schema.jsonify(product), 200
Beispiel #8
0
def get_one_product(product_id):
    product = db.session.query(Product).get(
        product_id
    )  # SQLAlchemy request => 'SELECT * FROM products where id = {product_id}'
    return one_product_schema.jsonify(product), 200