From 3193ca6b56f4b457fb551fa5b96b08c266213a50 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Sat, 5 Feb 2022 10:28:59 +0700 Subject: [PATCH] create user database --- driver/database/dbusers.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 driver/database/dbusers.py diff --git a/driver/database/dbusers.py b/driver/database/dbusers.py new file mode 100644 index 0000000..0322bf8 --- /dev/null +++ b/driver/database/dbusers.py @@ -0,0 +1,28 @@ +from typing import Dict, List, Union +from driver.database.dblocal import db + +usersdb = db.users + + +async def is_served_user(user_id: int) -> bool: + user = await usersdb.find_one({"user_id": user_id}) + if not user: + return False + return True + + +async def get_served_users() -> list: + users = usersdb.find({"user_id": {"$gt": 0}}) + if not users: + return [] + users_list = [] + for user in await users.to_list(length=1000000000): + users_list.append(user) + return users_list + + +async def add_served_user(user_id: int): + is_served = await is_served_user(user_id) + if is_served: + return + return await usersdb.insert_one({"user_id": user_id})