sql_app: Added access log request
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
575ba9452a
commit
52a7cffce2
@ -33,6 +33,10 @@ def get_user_by_username(db: Session, username: str):
|
||||
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 create_user(db: Session, user: schemas.UserCreate):
|
||||
key = crypto.gen_new_key(user.password)
|
||||
salt = key[1]
|
||||
|
@ -164,6 +164,13 @@ 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_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'])
|
||||
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)
|
||||
|
@ -51,3 +51,5 @@ class RoomSensorData(Base):
|
||||
temperature = Column(Integer)
|
||||
smoke_sensor_reading = Column(Integer)
|
||||
timestamp = Column(DateTime)
|
||||
|
||||
# TODO: Add table to store active sessions. May periodically clear.
|
@ -97,3 +97,6 @@ class DoorAccessLog(BaseModel):
|
||||
time: datetime
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
class AccessLogRequest(BaseModel):
|
||||
bluetooth_mac : str
|
||||
|
Loading…
Reference in New Issue
Block a user