def find_post_by_author_pagination(cls, author_id, page=1, per_page=10): """ Find all post publish by specific author :param author_id: id of author to find post by :param page: page index begin at 1 :param per_page: :return: """ # valid user if if not is_id_valid(author_id): raise InvalidFieldError("author id does not valid.", ["author_id"]) # confirm user existent author = DBUser.get_by_id(author_id) if not author: raise UserNotFoundError("User with id = %d does not exist") args = {"user_id": author_id} # validate pagination info if not is_id_valid(page): page = 1 if int(per_page) <= 0 or int(per_page) >= 50: per_page = 10 pagination = DBPost.pagination_get(filter_dict=args, page=page, per_page=per_page, order_by="time desc") return pagination, author
def get_posts_pagination(cls, page=1, per_page=10): """ Get many post at a time, order by post time :param page: page index begin at 1 :param per_page: :return: """ if not is_id_valid(page): page = 1 if int(per_page) <= 0 or int(per_page) >= 50: per_page = 10 pagination = DBPost.pagination_get(page=page, per_page=per_page, order_by="time desc") return pagination