Files
blog-service/service/blog_elastic_service.py

37 lines
656 B
Python

from datetime import datetime
from config.elastic import es, BLOG_INDEX
from schemas.blog_elastic import BlogElastic
def create_blog(blog: BlogElastic) -> bool:
now = datetime.now()
blog.createTime = now
blog.updateTime = now
es.index(
index=BLOG_INDEX,
id=blog.id,
body=blog.model_dump()
)
return True
def update_blog(blog: BlogElastic) -> bool:
blog.updateTime = datetime.now()
es.index(
index=BLOG_INDEX,
id=blog.id,
body=blog.model_dump()
)
return True
def delete_blog(blog_id: int) -> bool:
es.delete(index=BLOG_INDEX, id=blog_id)
return True