def read_users( db: Session = Depends(deps.get_db), skip: int = 0, limit: int = 100, user_id: Optional[List[UUID]] = Query(None)) -> Any: """ Retrieve users. """ users = crud.user.get_multi_filter(db, skip=skip, limit=limit, user_id=user_id) total_count = crud.user.count(db) info = schemas.Info(count=len(users), totalCount=total_count) return schemas.UsersWebInfo(users=users, info=info)
def read_movies( db: Session = Depends(deps.get_db), skip: int = 0, limit: int = 100, sort_settings: schemas.SortingMovies = Depends(deps.check_movies_sorting) ) -> Any: """ Retrieve movies. """ movies = crud.movie.get_multi_sort(db, skip=skip, limit=limit, sort=sort_settings.sort, sort_dir=sort_settings.sort_dir) total_count = crud.movie.count(db) info = schemas.Info(count=len(movies), totalCount=total_count) return schemas.MoviesInfo(movies=movies, info=info)
def read_movie_reviews( movie_id: UUID, db: Session = Depends(deps.get_db), skip: int = 0, limit: int = 100, sort_settings: schemas.ReviewsSortingModel = Depends( deps.check_reviews_sorting) ) -> Any: """ Retrieve reviews by movie. """ reviews = crud.review.get_by_movie(db, movie_id=movie_id, skip=skip, limit=limit, sort=sort_settings.sort, sort_dir=sort_settings.sort_dir) total_count = crud.review.get_count_by_movie(db=db, movie_id=movie_id)[0] info = schemas.Info(count=len(reviews), totalCount=total_count) return schemas.ReviewsInfo(reviews=reviews, info=info)
def read_all_reviews( db: Session = Depends(deps.get_db), *, skip: int = 0, limit: int = 100, sort_settings: schemas.SortingReviews = Depends( deps.check_reviews_sorting), created_gte: Optional[datetime] = None, user_id: Optional[List[UUID]] = Query(None) ) -> Any: reviews = crud.review.get_multi_sort(db=db, skip=skip, limit=limit, sort=sort_settings.sort, sort_dir=sort_settings.sort_dir, created_gte=created_gte, user_id=user_id) total_count = crud.review.count_all(db=db, created_gte=created_gte, user_id=user_id) info = schemas.Info(count=len(reviews), totalCount=total_count) return schemas.ReviewsInfo(reviews=reviews, info=info)
def read_following_by_user( user_id: UUID, db: Session = Depends(deps.get_db), skip: int = 0, limit: int = 100, sort_settings: schemas.SortingRelationships = Depends( deps.check_relationships_sorting) ) -> Any: """ Retrieve following by user_id. """ relationships = crud.relationship.get_following_by_user( db=db, user_id=user_id, skip=skip, limit=limit, sort=sort_settings.sort, sort_dir=sort_settings.sort_dir) total_count = crud.relationship.count_following_by_user(db=db, user_id=user_id) info = schemas.Info(count=len(relationships), totalCount=total_count) return schemas.RelationshipsInfo(relationships=relationships, info=info)