Пример #1
0
async def post(book: BookItem):
    book_obj = session.query(Books).filter_by(id=book.id).first()
    if not book:
        return return_data(msg='没有找到该书籍', code=404)
    book_obj.title = book.title
    book_obj.new_percent = book.new_percent
    book_obj.author = book.author
    book_obj.pub_com = book.pub_com
    session.commit()
    session.close()
    return return_data(data={"title": book.title})
Пример #2
0
def get_article_list(status: ArticleStatusEnum,
                     article_type: str = 'public',
                     free: bool = True,
                     user_id: int = Query(default=0)):
    article_obj_list = session.query(Article).filter_by(type=article_type,
                                                        free=free)
    if user_id:
        article_obj_list = article_obj_list.filter(Article.user_id == user_id)
    return return_data(data_list=article_obj_list.all())
Пример #3
0
async def pulish_book(title: str,
                      new_percent: float,
                      author: str = Query('', max_length=50),
                      pub_com: str = None,
                      can_email: bool = True):
    """
    发布书籍
    :param title: 书籍名称
    :param new_percent: 新旧程度
    :param author: 作者
    :param pub_com: 出版社
    :return:
    """
    book = Books(title=title,
                 new_percent=new_percent,
                 author=author,
                 pub_com=pub_com)
    session.add(book)
    session.commit()
    return return_data()
Пример #4
0
async def user_profile(user_id: int):
    user_obj = session.query(User).get(user_id)
    return return_data(data=user_obj)
Пример #5
0
async def path_test(file_path):
    return return_data(data={'file_path': file_path})
Пример #6
0
async def login_by_third_paty(name: LoginNameEnum):
    return return_data(data={'name': name})
Пример #7
0
async def book_list(user_id: int = Form(None)):
    books = session.query(Books).all()
    return return_data(data_list=books)
Пример #8
0
async def article_detail(article_id: int):
    article_obj = session.query(Article).get(article_id)
    return return_data(data=article_obj)
Пример #9
0
async def newst_comment_list(user_id: int):
    comments_list = session.query(Comment).filter()
    return return_data(data_list=comments_list)
Пример #10
0
async def updata_article_status(status: ArticleStatusEnum, article_ids: List[int] = Query(...)):
    print(status.value)
    session.query(Article).filter(Article.id.in_(article_ids)).update({'status': status.value})
    session.commit()
    return return_data(data_list=article_ids)
Пример #11
0
async def comment_operate_detail(id: int):
    comment_operate = session.query(CommentOperate).filter(CommentOperate.id == id).first()
    return return_data(data=comment_operate)
Пример #12
0
async def comment_detail(comment_id: int):
    comment = session.query(Comment).filter(Comment.id == comment_id).first()
    return return_data(data=comment)
Пример #13
0
async def add_comment(article_id: int, comment: AddCommentItem):
    comment_obj = Comment(detail=comment.detail, img_url=comment.img_url, article_id=article_id)
    session.add(comment_obj)
    session.commit()
    return return_data()
Пример #14
0
async def like_article(article_id: int):
    article_obj = session.query(Article).get(article_id)
    article_obj.like_num += 1
    session.commit()
    # todo 生成一条谁点赞谁的文章记录
    return return_data()
Пример #15
0
async def user_articles(user_id: int):
    articles = session.query(Article).filter(Article.user_id == user_id).all()
    return return_data(data_list=articles)
Пример #16
0
async def test(cookie: str = Cookie(None)):
    print(cookie)
    return return_data(data=cookie)
Пример #17
0
async def public_article(article: ArticleItem):
    article_obj = Article(**article.dict())
    session.add(article_obj)
    session.commit()
    return return_data()