Exemple #1
0
async def update_supplier(supplier_id: PositiveInt, supplier: dict, db: Session = Depends(get_db)):
    db_supplier = crud.get_supplier(db, supplier_id)
    if db_supplier is None:
        raise HTTPException(status_code=404, detail="Supplier not found")
    else:
        if supplier != {}:
            crud.update_supplier(db, supplier, supplier_id)
            db.commit()
        db_supplier = crud.get_supplier(db, supplier_id)
        return db_supplier
Exemple #2
0
async def get_suppliers_product(id: int, db: Session = Depends(get_db)):
    check_id = crud.get_supplier(db, id)
    if check_id is None:
        raise HTTPException(status_code=404)
    else:

        return crud.get_product(db, id)
Exemple #3
0
async def modify_supplier(id: int, db: Session = Depends(get_db)):
    deleted_supplier = crud.get_supplier(db, id)

    if deleted_supplier is None:
        raise HTTPException(status_code=404)

    crud.delete_supplier(db, id)
Exemple #4
0
async def get_products_for_supplier(supplier_id: PositiveInt,
                                    db: Session = Depends(get_db)):
    db_supplier = crud.get_supplier(db, supplier_id)
    if not db_supplier:
        raise HTTPException(status_code=404, detail="Supplier not found")

    return crud.get_products_for_supplier(db, supplier_id)
Exemple #5
0
async def update_supplier(supplier_id,
                          new_props: schemas.SupplierUpdate,
                          db: Session = Depends(get_db)):
    db_supplier = crud.get_supplier(db, supplier_id)
    if db_supplier is None:
        raise HTTPException(status_code=404, detail="Supplier not found")
    return crud.update_supplier(db, supplier_id, new_props)
Exemple #6
0
async def delete_supplier(supplier_id: PositiveInt, db: Session = Depends(get_db)):
    db_supplier = crud.get_supplier(db, supplier_id)
    if db_supplier is None:
        raise HTTPException(status_code=404, detail="Supplier not found")
    else:
        crud.delete_supplier(db,supplier_id)
        db.commit()
Exemple #7
0
async def add_supplier(supplier: schemas.Supplier, db: Session = Depends(get_db)):
    print(supplier)
    crud.add_supplier(db, supplier)
    db.commit()
    supplier_id = crud.get_last_Supplier(db).SupplierID
    db_supplier = crud.get_supplier(db, supplier_id)
    return db_supplier
Exemple #8
0
async def get_products(supplier_id: PositiveInt, db: Session = Depends(get_db)):
    db_supplier = crud.get_supplier(db, supplier_id)
    if db_supplier is None:
        raise HTTPException(status_code=404, detail="Supplier not found")
    else:
        products = crud.get_products(db, supplier_id)
        products = [{"ProductID": product.ProductID, "ProductName": product.ProductName,
                     "Category":{"CategoryID": product.CategoryID,
                                 "CategoryName": crud.get_product_category(db,product.CategoryID).CategoryName},
                     "Discontinued": product.Discontinued} for product in products]
    return products
Exemple #9
0
async def put_supplier(update_supplier: schemas.UpdateSupplier, supplier_id: PositiveInt, db: Session = Depends(get_db)):
    updates = {}
    for k, v in dict(update_supplier).items():
        if v:
            updates[k] = v
    db.query(models.Supplier).filter(models.Supplier.SupplierID == supplier_id).\
        update(updates)
    db_supplier = crud.get_supplier(db, supplier_id)
    if db_supplier is None:
        raise HTTPException(status_code=404, detail="Supplier not found")
    return db_supplier
Exemple #10
0
async def delete_supplier(supplier_id: int, db: Session = Depends(get_db)):
    check_id = crud.get_supplier(db, supplier_id)
    if check_id is None:
        raise HTTPException(status_code=404)
    return crud.delete_supplier(db, supplier_id)
Exemple #11
0
async def put_supplier(supplier: schemas.SupplierPut, supplier_id: int, db: Session = Depends(get_db)):
    check_id = crud.get_supplier(db, supplier_id)
    if check_id is None:
        raise HTTPException(status_code=404)
    return crud.put_supplier(db, supplier, supplier_id)
Exemple #12
0
async def get_supplier(id: PositiveInt, db: Session = Depends(get_db)):
    db_supplier = crud.get_supplier(db, id)
    if db_supplier is None:
        raise HTTPException(status_code=404)
    return db_supplier
Exemple #13
0
async def delete_supplier(supplier_id, db: Session = Depends(get_db)):
    db_supplier = crud.get_supplier(db, supplier_id)
    if db_supplier is None:
        raise HTTPException(status_code=404, detail="Supplier not found")
    crud.delete_supplier(db, supplier_id)
Exemple #14
0
async def update_supplier(sup_id: int,
                          supp: schemas.Supplier,
                          db: Session = Depends(get_db)):
    db_supplier = check_for_supplier(db, sup_id)
    crud.upd_supp(db, supp, sup_id)
    return crud.get_supplier(db, sup_id)
Exemple #15
0
def check_for_supplier(db, supp_id):
    is_supp = crud.get_supplier(db, supp_id)
    if is_supp is None:
        raise HTTPException(status_code=404, detail="Not Okie Dokie ID")
    return is_supp
Exemple #16
0
async def get_shipper(supplier_id: PositiveInt, db: Session = Depends(get_db)):
    db_supplier = crud.get_supplier(db, supplier_id)
    if db_supplier is None:
        raise HTTPException(status_code=404, detail="Supplier not found")
    return db_supplier