sql_app: fixed errors in room access log endpoints

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-06-08 13:26:41 +03:00
parent fdb5be583b
commit 0a4a560ac5
3 changed files with 17 additions and 15 deletions

View File

@ -34,8 +34,9 @@ def get_user_by_username(db: Session, username: str) -> models.User:
def get_users(db: Session, skip: int = 0, limit: int = 100):
return db.query(models.User).offset(skip).limit(limit).all()
def get_access_log_for_door_by_door_mac(db: Session, bluetooth_mac : str):
return db.query(models.DoorAccessLog).filter(models.DoorAccessLog.iot_dev_bluetooth_mac == bluetooth_mac).all()
def get_access_log_for_door_by_door_mac(db: Session, iot_id: str):
return db.query(models.DoorAccessLog)\
.filter(models.DoorAccessLog.iot_id == iot_id).all()
def get_access_log_for_user_by_id(db: Session, id : str):
return db.query(models.DoorAccessLog).filter(models.DoorAccessLog.user_id == id).all()
@ -186,6 +187,6 @@ def record_user_connection(db: Session, user: models.User, time: datetime):
db.commit()
db.refresh(entry)
def get_all_sensor_data_for_room(db: Session, room_id: int):
data = db.query(models.RoomSensorData).offset(0).limit(50).all()
def get_sensor_data_for_room(db: Session, skip: int = 0, limit: int = 100):
data = db.query(models.RoomSensorData).offset(skip).limit(limit).all()
return data

View File

@ -279,13 +279,6 @@ def generate_token_for_iot_device(bluetooth_mac : schemas.IotBluetoothMac,
tkn = auth_helper.create_iot_dev_token(data)
return {"access_token": tkn, "token_type": "bearer"}
@app.post("/admin/iotdevice/accesslog/", tags=['Admin'])
def get_access_log_for_door(request : schemas.AccessLogRequest,
db : Session = Depends(get_db)):
device = crud.get_iot_entity_by_bluetooth_mac(db, request.bluetooth_mac)
if not device: raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Iot Entity not found")
return crud.get_access_log_for_door_by_door_mac(db, request.bluetooth_mac)
@app.post("/admin/user/accesslog/email/", tags=['Admin'])
def get_access_log_history_for_user(request : schemas.UserAccessLogRequestEmail,
db : Session = Depends(get_db)):
@ -304,11 +297,19 @@ def get_access_log_history_for_user(request : schemas.UserAccessLogRequestUserna
def get_room_data(db: Session = Depends(get_db)):
return crud.get_room_data_now(db)
@app.get("/admin/roominfo/history/sensors/{room_id}", tags=['Admin'])
def get_all_sensor_history(room_id: int,
@app.get("/admin/roominfo/history/sensors", tags=['Admin'])
def get_all_sensor_history(skip: int = 0, limit: int = 100,
api_key: APIKey = Depends(auth_helper.valid_api_key),
db: Session = Depends(get_db)):
return crud.get_all_sensor_data_for_room(db, room_id)
return crud.get_sensor_data_for_room(db, skip, limit)
@app.post("/admin/roominfo/accesslog", tags=['Admin'])
def get_access_log_for_door(request : schemas.AccessLogRequest,
api_key: APIKey = Depends(auth_helper.valid_api_key),
db : Session = Depends(get_db)):
device = crud.get_iot_entity(db, request.iot_id)
if not device: raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Iot Entity not found")
return crud.get_access_log_for_door_by_door_mac(db, request.iot_id)
@app.post("/iotdevice/door/status", response_model=schemas.IotDoorPollingResponse, tags=['Iot'])
def polling_method_for_iot_entity(request: schemas.IotDoorPollingRequest,

View File

@ -107,7 +107,7 @@ class DoorAccessLog(BaseModel):
orm_mode = True
class AccessLogRequest(BaseModel):
bluetooth_mac : str
iot_id : int
class UserAccessLogRequestUsername(BaseModel):
username : str