async def server_users_get( response: Response, server_id: int, db=Depends(get_db), current_user=Depends(get_current_active_admin), ): """ Get server users by id """ if current_user.is_ops: return paginate(get_server_users_for_ops(db, server_id)) return paginate(get_server_users(db, server_id))
async def get_content( params: PaginationParams = Depends(), type: Optional[str] = Query( None, description="Either ``'Movie'`` or ``'Show'``."), rating: Optional[str] = Query( None, description= "Valid MPAA or TV Parental Guidelines Monitoring Board rating."), order_by: Optional[str] = Query( None, description='Accepts a model attribute. Prefix with `-` for descending.' ), ): content = Content.all() if type is not None and type.upper() in ContentType._member_names_: content = content.filter(type=type.capitalize()) elif type is not None: raise_exception(detail=f'{type} is not a valid option for `type`.') if rating is not None and _snake_case( rating).upper() in Rating._member_names_: content = content.filter(rating=rating.upper()) elif rating is not None: raise_exception(detail=f'{rating} is not a valid option for `rating`.') if order_by in ContentOutGet.schema()['properties'].keys(): content.order_by(order_by) elif order_by is not None: raise_exception( detail=f'{order_by} is not an attribute that can be ordered by.') return paginate(await ContentOutGet.from_queryset(content), params)
async def Read_News_Feed(params: PaginationParams = Depends(), db: AsyncIOMotorClient = Depends(get_database)): try: posts = [] data = await read_db_sort_desc(db) if (data): async for document in data: posts.append(Response_News_Feed(**document)) return { "status_code": 200, "message": "Success", "Extra_message": "Data Coming From DB", "Data": paginate(posts, params) } else: return { "status_code": 400, "message": "Error", "Extra_message": "DB Operation Issues" } except: return { "status_code": 500, "message": "Error", "Extra_message": "Internal API Level Issues" }
async def servers_list( response: Response, db=Depends(get_db), user=Depends(get_current_active_user), ): """ Get all servers """ return paginate(get_servers(db, user))
async def users_list( response: Response, query: str = None, db=Depends(get_db), current_user=Depends(get_current_active_admin), ): """ Search all users """ return paginate(get_users(db, query=query, user=current_user))
async def ports_list( response: Response, server_id: int, db=Depends(get_db), user=Depends(get_current_active_user), ): """ Get all ports on one server """ return paginate(get_ports(db, server_id, user))
async def testing_cache(user_id: str, params: PaginationParams = Depends(), db: AsyncIOMotorClient = Depends(get_database)): try: ########### checking data in cache data_cache = get_cache_data(user_id) if (data_cache): ############# returning from cache return { "status_code": 200, "message": "Success", "Extra_message": "Data Coming From cache", "Data": paginate(pickle.loads(data_cache), params) } else: posts = [] data = await read_db_sort_desc(db) if (data): async for document in data: posts.append(Response_News_Feed(**document)) ################# converting to string c_data = pickle.dumps(posts) ############ adding data to cache set_cache_data(user_id, 1200, c_data) return { "status_code": 200, "message": "Success", "Extra_message": "Data Coming From DB", "Data": paginate(posts, params) } else: return { "status_code": 400, "message": "Error", "Extra_message": "DB Operation Issues" } except: return { "status_code": 500, "message": "Error", "Extra_message": "Internal API Level Issues" }
def test_params(self, client, params, entities, path_type): response = client.get(getattr(self, f"path_{path_type}"), params=asdict(params)) expected = paginate(entities, params) a, b = normalize( Page[self.model], self._normalize_model(expected), self._normalize_model(response.json()), ) assert a == b
def test_pagination(self, client, params, entities, cls, path): response = client.get(path, params=params.dict()) set_page(cls) expected = paginate(entities, params) a, b = normalize( cls[self.model], self._normalize_model(expected), self._normalize_model(response.json()), ) assert a == b
def route(): return paginate([])
def port_list(db: Session = Depends(get_db)): course_all = crud.port_list(db=db) return paginate(course_all)
def faq_list(db: Session = Depends(get_db)): faq_all = crud.faq_list(db=db) return paginate(faq_all)
def live_list(db: Session = Depends(get_db)): live_all = crud.live_list(db=db) return paginate(live_all)
def extensive_list(db: Session = Depends(get_db)): extensive_all = crud.extensive_list(db=db) return paginate(extensive_all)
def award_list(db: Session = Depends(get_db)): award_all = crud.award_list(db=db) return paginate(award_all)
def feeds_list(db: Session = Depends(get_db)): feeds_all = crud.feeds_list(db=db) return paginate(feeds_all)
def notes_list(db: Session = Depends(get_db)): notes_all = crud.notes_list(db=db) return paginate(notes_all)
def route(params: PaginationParams = Depends()): return paginate([], params)
def master_list(db: Session = Depends(get_db)): master_all = crud.master_list(db=db) return paginate(master_all)
def profession_list(db: Session = Depends(get_db)): profession_all = crud.profession_list(db=db) return paginate(profession_all)
def micro_list(db: Session = Depends(get_db)): micro_all = crud.micro_list(db=db) return paginate(micro_all)
def free_list(db: Session = Depends(get_db)): free_all = crud.master_list(db=db) return paginate(free_all)
def subject_list(db: Session = Depends(get_db)): subject_all = crud.subject_list(db=db) return paginate(subject_all)
def tutor_list(db: Session = Depends(get_db)): tutor_all = crud.tutor_list(db=db) return paginate(tutor_all)
def comment_list(db: Session = Depends(get_db)): comment_all = crud.comment_list(db=db) return paginate(comment_all)
async def find_all_user( currentuser : model.UserList = Depends(util.get_current_active_user), ): query = "select * from Users" user_all = await database.fetch_all(query=query, values={}) return paginate(user_all)
def filmo_list(db: Session = Depends(get_db)): filmo_all = crud.filmo_list(db=db) return paginate(filmo_all)
def inquiry_list(db: Session = Depends(get_db)): inquiry_all = crud.inquiry_list(db=db) return paginate(inquiry_all)
async def read_all_fnotes(): feed_all = await crud.get_all() return paginate(feed_all)
def talent_list(db: Session = Depends(get_db)): course_all = crud.status_list(db=db) return paginate(course_all)