def get_user(req: Request, active: int = 0, page: int = 1, session: Session = Depends(get_session), credentials: credentials = Depends(security)): verify_admin(req.state.authenticated, session) user = crud_user.get_user(session=session, skip=(10 * (page - 1)), active=active) if not user: raise HTTPException(status_code=404, detail="Not found") total = crud_user.count(session=session, active=active) user = [i.serialize for i in user] if not active: auth0_data = get_auth0_user() auth0_data = pd.DataFrame(auth0_data) auth0_data = auth0_data.drop_duplicates(subset='email') user = pd.DataFrame(user) user = user.merge(auth0_data, on='email', how='left') for col in list(user): user[col] = user[col].apply(lambda x: None if x != x else x) user = user.to_dict('records') total_page = ceil(total / 10) if total > 0 else 0 if total_page < page: raise HTTPException(status_code=404, detail="Not found") if active: [u.update({'email_verified': True}) for u in user] return { 'current': page, 'data': user, 'total': total, 'total_page': total_page }
def add_crop(req: Request, name: str, session: Session = Depends(get_session), credentials: credentials = Depends(security)): verify_admin(req.state.authenticated, session) crop = crud_crop.add_crop(session=session, name=name) return crop
def get_user_by_id(req: Request, id: int, session: Session = Depends(get_session), credentials: credentials = Depends(security)): verify_admin(req.state.authenticated, session) user = crud_user.get_user_by_id(session=session, id=id) if user is None: raise HTTPException(status_code=404, detail="Not Found") return user.serialize
def update_user_by_id(req: Request, id: int, active: bool, role: UserRole, access: List[AccessBase] = [], session: Session = Depends(get_session), credentials: credentials = Depends(security)): verify_admin(req.state.authenticated, session) access = crud_user.add_access(session=session, user=id, access=access) user = crud_user.update_user_by_id(session=session, id=id, active=active, role=role) if user is None: raise HTTPException(status_code=404, detail="Not Found") if user.role == UserRole.admin: crud_user.delete_all_access(session=session, user=user.id) return user.serialize
def add_driver_income(req: Request, country: int, crop: int, status: DriverIncomeStatus, area: float = None, price: float = None, cop_pha: int = None, cop_pkg: float = None, efficiency: int = None, yields: int = None, diversification: int = None, revenue: int = None, total_revenue: int = None, net_income: int = None, living_income: int = None, source: str = None, session: Session = Depends(get_session), credentials: credentials = Depends(security)): verify_admin(req.state.authenticated, session) driver_income = crud_driver_income.add_driver_income( session=session, data=DriverIncome(country=country, crop=crop, status=status, area=area, price=price, cop_pha=cop_pha, cop_pkg=cop_pkg, efficiency=efficiency, yields=yields, diversification=diversification, revenue=revenue, total_revenue=total_revenue, net_income=net_income, living_income=living_income, source=source)) return driver_income.serialize