This commit is contained in:
@ -16,12 +16,15 @@ async def login(
|
||||
session: AsyncSessionDep,
|
||||
credentials: Annotated[HTTPAuthorizationCredentials, Depends(BEARER)],
|
||||
):
|
||||
user = cache.get(credentials.credentials)
|
||||
user = await cache.get(credentials.credentials)
|
||||
|
||||
if user is None:
|
||||
raise e.UnauthorizedException
|
||||
|
||||
_, user_id = user.decode().split(':')
|
||||
try:
|
||||
_, user_id = user.decode().split(':')
|
||||
except ValueError:
|
||||
raise e.UnauthorizedException from None
|
||||
|
||||
user_model_stmt = select(User).where(User.id == int(user_id))
|
||||
user_model = (await session.execute(user_model_stmt)).scalar_one_or_none()
|
||||
|
||||
@ -31,7 +31,12 @@ async def get_profile(user: Annotated[User, Depends(login)]):
|
||||
return await c.vitacore_api.getProfile(user.vita_id)
|
||||
|
||||
|
||||
@router.get('/getDepartments', response_model=list[vs.OrganizationsModel])
|
||||
@router.get(
|
||||
'/getDepartments',
|
||||
responses={
|
||||
status.HTTP_200_OK: {'model': vs.OrganizationsModel},
|
||||
},
|
||||
)
|
||||
async def get_departments():
|
||||
"""
|
||||
Get list of departments.
|
||||
@ -346,7 +351,7 @@ async def measurement(
|
||||
'status': status,
|
||||
}
|
||||
cache_key = f'tdn:measurement:{user.id}:{created}'
|
||||
cache.set(cache_key, dumps(data))
|
||||
await cache.set(cache_key, dumps(data))
|
||||
|
||||
|
||||
@router.get('/measurements')
|
||||
@ -354,6 +359,7 @@ async def measurements(
|
||||
user: Annotated[User, Depends(login)],
|
||||
):
|
||||
data = [
|
||||
cache.get(key) for key in cache.keys(f'tdn:measurement:{user.id}:*')
|
||||
cache.get(key)
|
||||
for key in await cache.keys(f'tdn:measurement:{user.id}:*')
|
||||
]
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user