ADD: api get list post save

This commit is contained in:
2022-08-15 11:24:51 +07:00
parent a027c72910
commit 5f25bd290f

View File

@@ -792,9 +792,15 @@ async def find_list_post(status: str = None, specialist: str = None, key_find: s
@post.post( @post.post(
"/find_post_save", response_description="search list posts" "/find_post_save", response_description="search list posts save"
) )
async def find_list_post(token: str, page: int = 0, limit: int = 10, key_find: str = None, history: HistoryFindModel = None): async def find_post_save(
token: str,
page: int = 0,
limit: int = 10,
# key_find: str = None,
history: HistoryFindModel = None
):
# point_data = ["point.less10", # point_data = ["point.less10",
# "point.form10to20", # "point.form10to20",
# "point.form20to30", # "point.form20to30",
@@ -812,19 +818,19 @@ async def find_list_post(token: str, page: int = 0, limit: int = 10, key_find: s
# posts = await db["posts"].find("$or": [ # posts = await db["posts"].find("$or": [
# {"translation_post": {"$regex": key_find}}, # {"translation_post": {"$regex": key_find}},
# {"translation_post": {"$regex": key_find}}, # {"translation_post": {"$regex": key_find}},
print(key_find) # print(key_find)
# ]).sort(age_sort, -1).to_list(100) # # ]).sort(age_sort, -1).to_list(100)
if key_find != None: # if key_find != None:
posts = await db["posts"].find({ # posts = await db["posts"].find({
"$or": [ # "$or": [
{"translation_post": {"$regex": key_find, "$options": 'i'}}, # {"translation_post": {"$regex": key_find, "$options": 'i'}},
{"data.content": {"$regex": key_find, "$options": 'i'}}, # {"data.content": {"$regex": key_find, "$options": 'i'}},
{"original_post": {"$regex": key_find, "$options": 'i'}}, # {"original_post": {"$regex": key_find, "$options": 'i'}},
{"summary": {"$regex": key_find, "$options": 'i'}}, # {"summary": {"$regex": key_find, "$options": 'i'}},
{"tag": {"$regex": key_find, "$options": 'xi'}}, # {"tag": {"$regex": key_find, "$options": 'xi'}},
] # ]
}).sort("point.total", -1).skip(page*limit).to_list(limit) # }).sort("point.total", -1).skip(page*limit).to_list(limit)
else: # else:
posts = await db["posts"].find().sort("point.total", -1).skip(page*limit).to_list(limit) posts = await db["posts"].find().sort("point.total", -1).skip(page*limit).to_list(limit)
count_total = 0 count_total = 0
output = [] output = []
@@ -836,10 +842,10 @@ async def find_list_post(token: str, page: int = 0, limit: int = 10, key_find: s
history = jsonable_encoder(history) history = jsonable_encoder(history)
history_user = history history_user = history
history_user["user_name"] = data history_user["user_name"] = data
history_user["status"] = "Tìm kiếm bài viết đã lưu theo từ khóa" history_user["status"] = "Xem danh sách bài viết đã lưu"
history_user["note"] = "" history_user["note"] = ""
history_user["data"] = key_find history_user["data"] = ""
check_data = await db["history"].find({"data": key_find, "status": "Tìm kiếm bài viết đã lưu theo từ khóa"}).sort("created_at", -1).to_list(1) check_data = await db["history"].find({"user_name": data, "status": "Xem danh sách bài viết đã lưu"}).sort("created_at", -1).to_list(1)
if check_data != []: if check_data != []:
history_user["count"] = int(check_data[0]["count"]) + 1 history_user["count"] = int(check_data[0]["count"]) + 1
else: else: