feat:更新elastic模块
This commit is contained in:
@@ -4,10 +4,10 @@ from config.elastic import es, BLOG_INDEX
|
||||
from schemas.blog_elastic import BlogElastic
|
||||
|
||||
|
||||
def create_blog(blog: BlogElastic) -> bool:
|
||||
def add_blog_elastic(blog: BlogElastic) -> bool:
|
||||
now = datetime.now()
|
||||
blog.createTime = now
|
||||
blog.updateTime = now
|
||||
blog.createTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
blog.updateTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
es.index(
|
||||
index=BLOG_INDEX,
|
||||
@@ -18,8 +18,9 @@ def create_blog(blog: BlogElastic) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def update_blog(blog: BlogElastic) -> bool:
|
||||
blog.updateTime = datetime.now()
|
||||
def update_blog_elastic(blog: BlogElastic) -> bool:
|
||||
now = datetime.now()
|
||||
blog.updateTime = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
es.index(
|
||||
index=BLOG_INDEX,
|
||||
|
||||
@@ -7,9 +7,11 @@ from sqlalchemy.orm import Session
|
||||
from models.blog import Blog, BlogCategory, BlogVisit, BlogContent, BlogComment
|
||||
from schemas.blog import BlogResponse, BlogQuery, BlogCategoryResponse, BlogStatsResponse, \
|
||||
BlogLatestResponse, BlogCommentCreate, BlogCommentResponse, BlogVisitResponse, BlogCreate, BlogUpdate
|
||||
from schemas.blog_elastic import BlogElastic
|
||||
from schemas.pagination import PageResult
|
||||
from schemas.paginate_query import paginate_query
|
||||
from middleware.exceptions import AppException
|
||||
from service.blog_elastic_service import add_blog_elastic
|
||||
from utils.blog_utils import get_blog_summary, get_word_count, get_read_duration
|
||||
|
||||
|
||||
@@ -126,6 +128,14 @@ def add_blog(db: Session, blog: BlogCreate) -> bool:
|
||||
db.commit()
|
||||
db.refresh(db_blog)
|
||||
|
||||
blog_elastic = BlogElastic(
|
||||
id=db_blog.id,
|
||||
title=db_blog.title,
|
||||
content=blog.content,
|
||||
category=blog.category
|
||||
)
|
||||
add_blog_elastic(blog_elastic)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user