sql_app: Access log for user (access history)
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
52a7cffce2
commit
36123b1090
@ -36,6 +36,8 @@ def get_users(db: Session, skip: int = 0, limit: int = 100):
|
||||
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_user_by_id(db: Session, id : str):
|
||||
return db.query(models.DoorAccessLog).filter(models.DoorAccessLog.user_id == id).all()
|
||||
|
||||
def create_user(db: Session, user: schemas.UserCreate):
|
||||
key = crypto.gen_new_key(user.password)
|
||||
|
@ -16,7 +16,6 @@ oauth = OAuth2PasswordBearer(tokenUrl="tkn")
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
# Dependency
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
@ -171,6 +170,20 @@ def get_access_log_for_door(request : schemas.AccessLogRequest,
|
||||
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.post("/admin/user/accesslog/email/", tags=['Admin'])
|
||||
def get_access_log_history_for_user(request : schemas.UserAccessLogRequestEmail,
|
||||
db : Session = Depends(get_db)):
|
||||
user = crud.get_user_by_email(db, request.email)
|
||||
if not user: raise HTTPException(status_code=404, detail="User not found")
|
||||
return crud.get_access_log_for_user_by_id(db, user.id)
|
||||
|
||||
@app.post("/admin/user/accesslog/username/", tags=['Admin'])
|
||||
def get_access_log_history_for_user(request : schemas.UserAccessLogRequestUsername,
|
||||
db : Session = Depends(get_db)):
|
||||
user = crud.get_user_by_username(db, request.username)
|
||||
if not user: raise HTTPException(status_code=404, detail="User not found")
|
||||
return crud.get_access_log_for_user_by_id(db, user.id)
|
||||
|
||||
@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)
|
||||
|
@ -100,3 +100,12 @@ class DoorAccessLog(BaseModel):
|
||||
|
||||
class AccessLogRequest(BaseModel):
|
||||
bluetooth_mac : str
|
||||
|
||||
class UserAccessLogRequestUsername(BaseModel):
|
||||
username : str
|
||||
|
||||
class UserAccessLogRequestEmail(BaseModel):
|
||||
email : str
|
||||
|
||||
class UserAccessLogRequestID(BaseModel):
|
||||
id : int
|
||||
|
Loading…
Reference in New Issue
Block a user