示例#1
0
 def get_story(cls, limit: Optional[int] = None,
               offset: Optional[int] = None,
               sort: Optional[str] = None,
               category_id: Optional[int] = None) -> list:
     story_qs = Story.sa.query(
         Story.sa.id,
         Story.sa.name,
         Story.sa.slug,
         Story.sa.description,
         Story.sa.content,
         Category.sa.name.label('category_name')
     ).join(
         Category.sa
     )
     if category_id:
         total_count = Story.sa.query(func.count(Story.sa.id)).filter(Category.sa.id == category_id).scalar()
         story_qs = story_qs.filter(
             Category.sa.id == category_id
         )
     else:
         total_count = Story.sa.query(func.count(Story.sa.id)).scalar()
     story_qs = BaseRespository.filter_limit(story_qs, limit)
     story_qs = BaseRespository.filter_offset(story_qs, offset)
     story_qs = BaseRespository.sort_all(story_qs, sort, Story)
     try:
         result = story_qs.all()
     except NoResultFound:
         result = None
     return result, total_count
示例#2
0
 def get_category(cls, limit: Optional[int] = None,
                  offset: Optional[int] = None,
                  sort: Optional[str] = None) -> list:
     category_qs = Category.sa.query(
         Category.sa.id,
         Category.sa.name,
         Category.sa.slug
     )
     total_count = Category.sa.query(func.count(Category.sa.id)).scalar()
     category_qs = BaseRespository.filter_limit(category_qs, limit)
     category_qs = BaseRespository.filter_offset(category_qs, offset)
     category_qs = BaseRespository.sort_all(category_qs, sort, Category)
     try:
         result = category_qs.all()
     except NoResultFound:
         result = None
     return result, total_count