feat:增加查询博客相邻记录功能
This commit is contained in:
@@ -8,11 +8,15 @@ from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from config.elastic import es, BLOG_INDEX
|
||||
from config.setting import settings
|
||||
from models.blog import Blog, BlogCategory, BlogContent
|
||||
from schemas.blog_elastic import BlogElastic, BlogSearch
|
||||
|
||||
|
||||
def sync_all_blog(db: Session) -> bool:
|
||||
if settings.ENVIRONMENT == 'dev':
|
||||
return True
|
||||
|
||||
query = select(
|
||||
Blog.id,
|
||||
Blog.title,
|
||||
@@ -54,6 +58,9 @@ def sync_all_blog(db: Session) -> bool:
|
||||
|
||||
|
||||
def add_blog_elastic(blog: BlogElastic) -> bool:
|
||||
if settings.ENVIRONMENT == 'dev':
|
||||
return True
|
||||
|
||||
now = datetime.now()
|
||||
blog.createTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
blog.updateTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
@@ -64,10 +71,14 @@ def add_blog_elastic(blog: BlogElastic) -> bool:
|
||||
body=blog.model_dump()
|
||||
)
|
||||
|
||||
logger.info(f"成功新增博客 {blog.id} 到 Elasticsearch")
|
||||
return True
|
||||
|
||||
|
||||
def update_blog_elastic(blog: BlogElastic) -> bool:
|
||||
if settings.ENVIRONMENT == 'dev':
|
||||
return True
|
||||
|
||||
now = datetime.now()
|
||||
blog.updateTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
@@ -77,12 +88,17 @@ def update_blog_elastic(blog: BlogElastic) -> bool:
|
||||
body=blog.model_dump()
|
||||
)
|
||||
|
||||
logger.info(f"成功修改博客 {blog.id} 到 Elasticsearch")
|
||||
return True
|
||||
|
||||
|
||||
def delete_blog(blog_id: int) -> bool:
|
||||
if settings.ENVIRONMENT == 'dev':
|
||||
return True
|
||||
|
||||
es.delete(index=BLOG_INDEX, id=blog_id)
|
||||
|
||||
logger.info(f"成功删除博客 {blog_id} 到 Elasticsearch")
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user