crud: get iot by BT

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-04-17 21:34:50 +03:00
parent 59417427c3
commit 48e4f0ab48
2 changed files with 6 additions and 2 deletions

View File

@ -14,6 +14,9 @@ def get_iot_entity(db: Session, id: int):
def get_iot_entity_by_description(db: Session, description: str): def get_iot_entity_by_description(db: Session, description: str):
return db.query(models.IotEntity).filter(models.IotEntity.description == description).first() return db.query(models.IotEntity).filter(models.IotEntity.description == description).first()
def get_iot_entity_by_bluetooth_mac(db: Session, bluetooth_mac: str):
return db.query(models.IotEntity).filter(models.IotEntity.bluetooth_mac == bluetooth_mac).first()
def get_user_by_email(db: Session, email: str): def get_user_by_email(db: Session, email: str):
return db.query(models.User).filter(models.User.email == email).first() return db.query(models.User).filter(models.User.email == email).first()

View File

@ -59,8 +59,9 @@ def get_current_iot_device(current_device: schemas.IotBluetoothMac = Depends(),
) )
payload = jwt.decode(token, auth_helper.JWT_SECRET, algorithms=[auth_helper.JWT_ALGO]) payload = jwt.decode(token, auth_helper.JWT_SECRET, algorithms=[auth_helper.JWT_ALGO])
mac_signed = payload.get("bluetooth_mac") mac_signed = payload.get("bluetooth_mac")
if (mac_signed == current_device): return mac_signed if (mac_signed != current_device): raise credentials_exception
else: raise credentials_exception device = crud.get_iot_entity_by_bluetooth_mac(db, mac_signed)
return device
@app.post("/users/reg", response_model=schemas.User, tags=['Users']) @app.post("/users/reg", response_model=schemas.User, tags=['Users'])
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)): def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)):