Browse Source

add new

master
panda 8 months ago
parent
commit
e52c3c4ec9
  1. 27
      routers/blogmanage.py

27
routers/blogmanage.py

@ -32,6 +32,18 @@ async def blog_list():
blog_list = fetch_all(select_query)
return response_success(blog_list, "blog get list success")
@router.get("/list/{id}")
async def blog_one(id: int):
# 列表参数:博客名称、博客内容、创建时间、博客图片、博客查看时间、博客阅读次数、博客字数、类型名称、标签名列表
select_query = """
SELECT id, blogtitle, blogcontent FROM blogs
WHERE id = %s
ORDER BY create_at DESC;
"""
blog_one = fetch_one(select_query,(id,))
return response_success(blog_one, "blog get blog_one success")
# 博客新增
@router.post("/add")
@ -62,21 +74,6 @@ async def blog_delete(id: str = Path(description="博客id")):
execute_query(insert_query, (id,))
return response_success(message="blog delete success")
# 博客修改
# @router.put("/update/{id}")
# async def blog_put(blog: Blog, id: str = Path(description="博客id")):
# select_query = "SELECT * FROM blogs WHERE id=%s"
# existing_blog = fetch_one(select_query, (id,))
# raise_if_not_found(existing_blog, "blog not found")
# update_query = (
# "UPDATE blogs SET blogtitle=%s,blogcontent=%s,typeid=%s,descr=%s WHERE id=%s;"
# )
# update_data = (blog.blogtitle, blog.blogcontent,
# blog.typeid, blog.descr, id)
# execute_query(update_query, update_data)
# return response_success("blog update sucess")
@router.put("/update/{id}")
async def blog_update(id: int, blog: Blog, labels: list[Label], _: User = Depends(get_current_active_user)):
# 检查要编辑的博客是否存在

Loading…
Cancel
Save