diff --git a/app/src/routers/post.py b/app/src/routers/post.py index e3d08df..06ed9bb 100644 --- a/app/src/routers/post.py +++ b/app/src/routers/post.py @@ -792,9 +792,15 @@ async def find_list_post(status: str = None, specialist: str = None, key_find: s @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.form10to20", # "point.form20to30", @@ -812,20 +818,20 @@ async def find_list_post(token: str, page: int = 0, limit: int = 10, key_find: s # posts = await db["posts"].find("$or": [ # {"translation_post": {"$regex": key_find}}, # {"translation_post": {"$regex": key_find}}, - print(key_find) - # ]).sort(age_sort, -1).to_list(100) - if key_find != None: - posts = await db["posts"].find({ - "$or": [ - {"translation_post": {"$regex": key_find, "$options": 'i'}}, - {"data.content": {"$regex": key_find, "$options": 'i'}}, - {"original_post": {"$regex": key_find, "$options": 'i'}}, - {"summary": {"$regex": key_find, "$options": 'i'}}, - {"tag": {"$regex": key_find, "$options": 'xi'}}, - ] - }).sort("point.total", -1).skip(page*limit).to_list(limit) - else: - posts = await db["posts"].find().sort("point.total", -1).skip(page*limit).to_list(limit) + # print(key_find) + # # ]).sort(age_sort, -1).to_list(100) + # if key_find != None: + # posts = await db["posts"].find({ + # "$or": [ + # {"translation_post": {"$regex": key_find, "$options": 'i'}}, + # {"data.content": {"$regex": key_find, "$options": 'i'}}, + # {"original_post": {"$regex": key_find, "$options": 'i'}}, + # {"summary": {"$regex": key_find, "$options": 'i'}}, + # {"tag": {"$regex": key_find, "$options": 'xi'}}, + # ] + # }).sort("point.total", -1).skip(page*limit).to_list(limit) + # else: + posts = await db["posts"].find().sort("point.total", -1).skip(page*limit).to_list(limit) count_total = 0 output = [] # history.created_at = datetime.datetime.now(tz=tz) @@ -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_user = history 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["data"] = key_find - 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) + history_user["data"] = "" + 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 != []: history_user["count"] = int(check_data[0]["count"]) + 1 else: