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):
|
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]
|
||||||
|
@ -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)
|
||||||
|
@ -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.
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user