Ejemplo n.º 1
0
def update_user_by_id(user_id: int, user: Dict,
                      users_repository: UsersRepository) -> User:
    try:
        return users_repository.update_by_id(user_id, user)
    except ResourceNotFoundError:
        raise_user_not_found()
    except ResourceAlreadyExistsError:
        raise_conflict("User with data already exists")
Ejemplo n.º 2
0
def send_access_code(
        body: AccessCodeCreate,
        access_code_service: AccessCodeService = Depends(access_code_service),
        producer: SendCodeProducer = Depends(send_code_producer),
        users_repository: UsersRepository = Depends(users_repository),
):
    try:
        user = find_user_by_email(body.email, users_repository)
    except HTTPException as error:
        if not body.create_user:
            raise error
        user = users_repository.create(UserCreate(email=body.email).dict())
    code = access_code_service.generate_code(user.id)
    producer.send_code(code, user.email)
Ejemplo n.º 3
0
def delete_user_by_id(user_id: int, users_repository: UsersRepository):
    try:
        return users_repository.delete_by_id(user_id)
    except ResourceNotFoundError:
        raise_user_not_found()
Ejemplo n.º 4
0
def find_user_by_email(email: str, users_repository: UsersRepository) -> User:
    try:
        return users_repository.find_by_email(email)
    except ResourceNotFoundError:
        raise_user_not_found()
Ejemplo n.º 5
0
def find_user_by_id(user_id: int, users_repository: UsersRepository) -> User:
    try:
        return users_repository.find_by_id(user_id)
    except ResourceNotFoundError:
        raise_user_not_found()
Ejemplo n.º 6
0
def users_repository(db: Session = Depends(db_session)) -> UsersRepository:
    return UsersRepository(db)
Ejemplo n.º 7
0
def users_repository(db_session):
    return UsersRepository(db_session)
Ejemplo n.º 8
0
def list_users(users_repository: UsersRepository = Depends(users_repository)):
    return users_repository.find_all()
Ejemplo n.º 9
0
def create_user(user: UserCreate,
                users_repository: UsersRepository = Depends(users_repository)):
    try:
        return users_repository.create(user.dict())
    except ResourceAlreadyExistsError:
        raise_conflict("User already exists")