def update(item_id: str, db: Session = Depends(get_db)): item = crud.get_item(db, item_id=item_id) if item.is_active: item.is_active = False else: item.is_active = True db.commit() return
def create_stock(stock: schemas.StockCreate, db: Session = Depends(get_db)): db_item = crud.get_item(db, name=stock.item_name) if db_item is None: raise HTTPException(status_code=404, detail="Item not found") db_shop = crud.get_shop(db, name=stock.shop_name) if db_shop is None: raise HTTPException(status_code=404, detail="Shop not found") new_stock = schemas.StockDBIn(item_id=db_item.id, shop_id=db_shop.id, quantity=stock.quantity) return crud.create_stock(db=db, stock=new_stock)
def get_stock(stock: schemas.StockRead, db: Session = Depends(get_db)): db_item = crud.get_item(db, name=stock.item_name) if db_item is None: raise HTTPException(status_code=404, detail="Item not found") db_shop = crud.get_shop(db, name=stock.shop_name) if db_shop is None: raise HTTPException(status_code=404, detail="Shop not found") db_stock = crud.get_stock(db, item_id=db_item.id, shop_id=db_shop.id) stock = schemas.StockOutput(item=db_item, shop=db_shop, quantity=db_stock.quantity) return stock
def item_detail(item_id): item = crud.get_item(item_id) if item: comments = crud.get_comments(item_id) commentForm = NewCommentForm() commentForm.item_id.data = item_id deleteItemForm = DeleteItemForm() return render_template("item.html", item=item, comments=comments, commentForm=commentForm, deleteItemForm=deleteItemForm) return redirect(url_for("home"))
def make_invalid(item_id: str, db: Session = Depends(get_db)): item = crud.get_item(db, item_id=item_id) data = item.inc_type + ' ' + item.inc_detail + ' ' + str( item.lat) + ' ' + str( item.lon) + ' ' + item.url + ' ' + item.pic + ' ' + str( item.is_active) Popen( 'curl -d \'{"id":"' + item_id + '" , "data":"' + data + '"}\' -H "Content-Type: application/json" -X POST http://127.0.0.1:8000/invalid_input/' + item.owner_id + '/', stdin=None, stderr=None, shell=True).communicate() db.delete(item) db.commit() return
def read_item(item_id: int, db: Session = Depends(get_db)): db_item = crud.get_item(db, item_id=item_id) if db_item is None: raise HTTPException(status_code=404, detail="Item to read not found") return db_item
def create_item(item: schemas.ItemCreate, db: Session = Depends(get_db)): db_item = crud.get_item(db, name=item.name) if db_item is not None: raise HTTPException(status_code=404, detail="Item already exist") return crud.create_item(db, item)
def get_item(item: schemas.ItemRead, db: Session = Depends(get_db)): db_item = crud.get_item(db, name=item.name) if db_item is None: raise HTTPException(status_code=404, detail="Item not found") return db_item