xbackend/crud/user_label.py
2021-10-25 17:08:33 +08:00

34 lines
1.1 KiB
Python

from motor.motor_asyncio import AsyncIOMotorDatabase
import schemas
from crud.base import CRUDBase
__all__ = 'user_label',
from utils import get_uid
class CRUDUserLabel(CRUDBase):
async def save(self, db: AsyncIOMotorDatabase, data_in: schemas.UserLabelSave, act_name, game):
where = {'cluster_name': data_in.cluster_name, 'game': game}
is_exists = await self.find_one(db, where)
data = data_in.dict(skip_defaults=True)
data['act_name'] = act_name
if not is_exists:
data = {'$set': {**data, '_id': get_uid()}}
return await self.update_one(db, where, data, upsert=True)
return await self.update_one(db, where, {'$set': data}, upsert=True)
async def read(self, db: AsyncIOMotorDatabase, data_in: schemas.UserLabelRead):
where = data_in.dict(skip_defaults=True)
res = await self.find_many(db, where)
return res
async def get_list(self, db: AsyncIOMotorDatabase, game: str):
where = {'game': game}
res = await self.find_many(db, where, {'qp': 0})
return res
user_label = CRUDUserLabel('user_label')