sql_app: fixed errors in room access log endpoints
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
fdb5be583b
commit
0a4a560ac5
@ -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):
|
def get_users(db: Session, skip: int = 0, limit: int = 100):
|
||||||
return db.query(models.User).offset(skip).limit(limit).all()
|
return db.query(models.User).offset(skip).limit(limit).all()
|
||||||
|
|
||||||
def get_access_log_for_door_by_door_mac(db: Session, bluetooth_mac : str):
|
def get_access_log_for_door_by_door_mac(db: Session, iot_id: str):
|
||||||
return db.query(models.DoorAccessLog).filter(models.DoorAccessLog.iot_dev_bluetooth_mac == bluetooth_mac).all()
|
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):
|
def get_access_log_for_user_by_id(db: Session, id : str):
|
||||||
return db.query(models.DoorAccessLog).filter(models.DoorAccessLog.user_id == id).all()
|
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.commit()
|
||||||
db.refresh(entry)
|
db.refresh(entry)
|
||||||
|
|
||||||
def get_all_sensor_data_for_room(db: Session, room_id: int):
|
def get_sensor_data_for_room(db: Session, skip: int = 0, limit: int = 100):
|
||||||
data = db.query(models.RoomSensorData).offset(0).limit(50).all()
|
data = db.query(models.RoomSensorData).offset(skip).limit(limit).all()
|
||||||
return data
|
return data
|
@ -279,13 +279,6 @@ def generate_token_for_iot_device(bluetooth_mac : schemas.IotBluetoothMac,
|
|||||||
tkn = auth_helper.create_iot_dev_token(data)
|
tkn = auth_helper.create_iot_dev_token(data)
|
||||||
return {"access_token": tkn, "token_type": "bearer"}
|
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'])
|
@app.post("/admin/user/accesslog/email/", tags=['Admin'])
|
||||||
def get_access_log_history_for_user(request : schemas.UserAccessLogRequestEmail,
|
def get_access_log_history_for_user(request : schemas.UserAccessLogRequestEmail,
|
||||||
db : Session = Depends(get_db)):
|
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)):
|
def get_room_data(db: Session = Depends(get_db)):
|
||||||
return crud.get_room_data_now(db)
|
return crud.get_room_data_now(db)
|
||||||
|
|
||||||
@app.get("/admin/roominfo/history/sensors/{room_id}", tags=['Admin'])
|
@app.get("/admin/roominfo/history/sensors", tags=['Admin'])
|
||||||
def get_all_sensor_history(room_id: int,
|
def get_all_sensor_history(skip: int = 0, limit: int = 100,
|
||||||
api_key: APIKey = Depends(auth_helper.valid_api_key),
|
api_key: APIKey = Depends(auth_helper.valid_api_key),
|
||||||
db: Session = Depends(get_db)):
|
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'])
|
@app.post("/iotdevice/door/status", response_model=schemas.IotDoorPollingResponse, tags=['Iot'])
|
||||||
def polling_method_for_iot_entity(request: schemas.IotDoorPollingRequest,
|
def polling_method_for_iot_entity(request: schemas.IotDoorPollingRequest,
|
||||||
|
@ -107,7 +107,7 @@ class DoorAccessLog(BaseModel):
|
|||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
|
||||||
class AccessLogRequest(BaseModel):
|
class AccessLogRequest(BaseModel):
|
||||||
bluetooth_mac : str
|
iot_id : int
|
||||||
|
|
||||||
class UserAccessLogRequestUsername(BaseModel):
|
class UserAccessLogRequestUsername(BaseModel):
|
||||||
username : str
|
username : str
|
||||||
|
Loading…
Reference in New Issue
Block a user