Beispiel #1
0
def test_set_to_cache(rdc: RedisCache) -> None:
    key = "teste:1"
    value = 10
    rdc.set_to_cache(key, value)
    cache = pickle.loads(rdc.get(key))
    assert cache
    assert cache == 10

    rdc.delete(key)
Beispiel #2
0
def list_providers(
    user: UserModel = Depends(deps.get_user), 
    db: Session = Depends(deps.get_db),
    rdc: RedisCache = Depends(deps.get_redis)
) -> Any:
    """
    Endpoint for list providers
    """
    cache_key = f"providers-list:{str(user.id)}"
    providers = rdc.get_from_cache(cache_key)
    if not providers:
        providers = crud_user.get_all_providers(db, user)
        rdc.set_to_cache(cache_key, providers)

    return providers
Beispiel #3
0
def list_self_provider_appointments(
    query: ProviderAppointmentsQuery = Depends(),
    user: UserModel = Depends(deps.get_user), 
    db: Session = Depends(deps.get_db),
    rdc: RedisCache = Depends(deps.get_redis),
) -> Any:
    """
    Endpoint for list self provider appointments
    """
    cache_key = f"providers-appointments:{str(user.id)}:{query.year}:{query.month}:{query.day}"
    appointments = rdc.get_from_cache(cache_key)
    if not appointments:
        appointments = crud_appointment.get_appointments_by_DMY(db, query, user)
        rdc.set_to_cache(cache_key, parse_obj_as(List[ProviderAppointments], appointments))

    return appointments
Beispiel #4
0
def list_self_provider_appointments(
        user: UserModel = Depends(deps.get_user),
        db: Session = Depends(deps.get_db),
        rdc: RedisCache = Depends(deps.get_redis),
) -> Any:
    """
    Endpoint for list self user appointments
    """
    cache_key = f"user-appointments:{str(user.id)}"
    appointments = rdc.get_from_cache(cache_key)
    if not appointments:
        appointments = crud_appointment.get_appointments_by_user(db, user)
        rdc.set_to_cache(cache_key,
                         parse_obj_as(List[UserAppointments], appointments))

    return appointments