Commit 243843b3 authored by ZZH's avatar ZZH

fix news edit 2024-03-8

parent c607b9ea
......@@ -34,9 +34,12 @@ class PubNewsReq(Model):
class ReviseNewsReq(Model):
news_id: str = Str("文章id").eg("12")
title: str = Opt(Str("文章标题").eg("喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"))
news_type: int = Opt(Int("文章类型(1:公司新闻, 2:行业新闻)").eg(1))
keywords: str = Opt(Str("文章关键词").eg("清科优能"))
contents: str = Opt(Str("文章描述").eg("清科优能"))
pub_time: str = Opt(Str("发布时间").eg("2023-12-29 18:06"))
top: int = Opt(Int("置顶/取消置顶").eg(0))
@dataclass
class ReviseNewsSeoReq(Model):
news_id: str = Str("文章id").eg("12")
......
......@@ -63,17 +63,20 @@ async def save_news_info(news_info, news_url, cover_url):
str(news_info["pub_time"]),))
async def update_news_info(news_id, title, news_url, cover_url):
async def update_news_info(news_info, news_url, cover_url):
async with MysqlUtil(db="official_web") as conn:
if cover_url:
sql = "UPDATE official_web.news_info " \
"SET title=%s, news_url=%s, cover_url=%s WHERE id=%s;"
return await conn.execute(sql, (news_id, title, news_url,
cover_url))
sql = "UPDATE official_web.news_info SET cover_url=%s WHERE id=%s;"
await conn.execute(sql, (cover_url, news_info["news_id"],))
sql = "UPDATE official_web.news_info " \
"SET title=%s, news_url=%s WHERE id=%s;"
return await conn.execute(sql, (news_id, title, news_url,))
"SET title=%s, news_type=%s, news_url=%s, keywords=%s, " \
"contents=%s, pub_time=%s WHERE id=%s;"
await conn.execute(sql, (news_info["title"], news_info["news_type"],
news_url, news_info["keywords"],
news_info["contents"],
str(news_info["pub_time"]),
news_info["news_id"]))
async def update_news_seo(news_id, keywords, contents):
......
......@@ -34,12 +34,14 @@ async def post_publish_news(request, *args, **kwargs) -> SuccessRsp:
return SuccessRsp(success=0, message="发布文章失败")
@summary("重新编辑文章(标题/内容/封面)")
@summary("重新编辑文章(标题|内容|封面|文章分类|发布时间|关键词|描述)")
async def post_revise_news(request, body: ReviseNewsReq) -> SuccessRsp:
news_id, title = body.news_id, body.title
is_success, url_article, url_cover = await upload_news_qs(request)
if is_success:
await update_news_info(news_id, title, url_article, url_cover)
d_news_info = dict(title=body.title, pub_time=body.pub_time,
keywords=body.keywords, contents=body.contents,
news_type=int(body.news_type))
await update_news_info(d_news_info, url_article, url_cover)
return SuccessRsp(success=1, message="修改文章成功")
return SuccessRsp(success=0, message="修改文章失败")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment