sql_app: Added access log request

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-05-23 19:02:54 +03:00
parent 575ba9452a
commit 52a7cffce2
4 changed files with 18 additions and 2 deletions

View File

@ -33,6 +33,10 @@ def get_user_by_username(db: Session, username: str):
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):
return db.query(models.DoorAccessLog).filter(models.DoorAccessLog.iot_dev_bluetooth_mac == bluetooth_mac).all()
def create_user(db: Session, user: schemas.UserCreate): def create_user(db: Session, user: schemas.UserCreate):
key = crypto.gen_new_key(user.password) key = crypto.gen_new_key(user.password)
salt = key[1] salt = key[1]

View File

@ -164,6 +164,13 @@ 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_code=404, detail="Iot Entity not found")
return crud.get_access_log_for_door_by_door_mac(db, request.bluetooth_mac)
@app.get("/users/acesslist/", response_model=List[schemas.IotEntity], tags=['Users']) @app.get("/users/acesslist/", response_model=List[schemas.IotEntity], tags=['Users'])
def get_iot_access_list_for_user(db: Session = Depends(get_db), current_user: schemas.User = Depends(get_current_active_user)): def get_iot_access_list_for_user(db: Session = Depends(get_db), current_user: schemas.User = Depends(get_current_active_user)):
user = crud.get_user_by_username(db, current_user.username) user = crud.get_user_by_username(db, current_user.username)

View File

@ -50,4 +50,6 @@ class RoomSensorData(Base):
people = Column(Integer) people = Column(Integer)
temperature = Column(Integer) temperature = Column(Integer)
smoke_sensor_reading = Column(Integer) smoke_sensor_reading = Column(Integer)
timestamp = Column(DateTime) timestamp = Column(DateTime)
# TODO: Add table to store active sessions. May periodically clear.

View File

@ -96,4 +96,7 @@ class DoorAccessLog(BaseModel):
door_bluetooth_mac: str door_bluetooth_mac: str
time: datetime time: datetime
class Config: class Config:
orm_mode = True orm_mode = True
class AccessLogRequest(BaseModel):
bluetooth_mac : str