async def delete_products(ref: int, db: Session = Depends(get_db)): products = crud.get_product_id(db, ref) if products is None: raise HTTPException(status_code=404, detail="El producto no existe") db.delete(products) db.commit() return {"Delete successfull": True}
async def update_qty(ref: int, product: schemas.ProductsQTY, db: Session = Depends(get_db)): product_in = crud.get_product_id(db, ref) product_in.qty = product.qty db.commit() return product_in
def show_product(product_id): """Show details on a particular product.""" product = crud.get_product_id(product_id) product_ingredients = crud.get_ingredients_for_product(product) return render_template('product_details.html', product=product, product_ingredients=product_ingredients)
async def update_product(ref: int, product: schemas.ProductsUpdate, db: Session = Depends(get_db)): product_in = crud.get_product_id(db, ref) product_in.name = product.name product_in.date = product.date product_in.price = product.price product_in.qty = product.qty product_in.category = product.category db.commit() return product_in
def add_product(): '''adds new product to db''' # GET BASIC INFO FROM DATA data = request.get_json() user_id = data['user_id'] bcorp = data['selectedBCorp'] productName = data['productName'] company = data['company'] productUrl = data['productUrl'] description = data['description'] # ****************************** # # INFO THAT NEEDS MORE PROCESSING selectedSubCategory = data['selectedSubCategory'] #! IP category_from_data = data['category'] selectedCerts = data['selectedCerts'] img_url = data['img'] # ****************************** # # GET DEPARTMENT/CATEGORY ID FROM DB BASED ON DATA category_id = crud.get_category_id(category_from_data) # GET SUBCATEGORY ID FROM DB BASED ON DATA subcategory_id = crud.get_subcategory_id(selectedSubCategory) #! IP # GET ALL CERT IDS FOR CERTS GIVEN IF THEY AREN'T A BCORP cert_id_list = [] for cert in selectedCerts: if cert != 'Bcorp': cert_id = crud.get_cert_id_by_title(cert) cert_id_list.append(cert_id) # IF THERE IS A BCORP IGNORE THE COMPANY PROVIDED (we can do this on the front end later maybe?) if bcorp: company = bcorp new_product = crud.post_product(productName,productUrl,company,description,category_id,subcategory_id,user_id) product_id = crud.get_product_id(productName,user_id) if img_url: image_id = crud.post_image(img_url,product_id) product = crud.put_product_image(image_id,product_id) print('new_product',product) # ADD PRODUCT CERTIFICATIONS TO RELATIONAL TABLE (which we don't need to do for bcorps) for cert_id in cert_id_list: new_certification = crud.post_product_certifications(product_id,cert_id) return jsonify('Product added')
async def read_qty_by_ref(ref: int, db: Session = Depends(get_db)): products = crud.get_product_id(db, ref=ref) if products is None: raise HTTPException(status_code=404, detail="Producto no encontrado.") products.qty return products.qty