prs_server/crud/crud_dashboard.py
2022-07-25 14:49:05 +08:00

29 lines
1015 B
Python

import pymongo
from motor.motor_asyncio import AsyncIOMotorDatabase
from crud.base import CRUDBase
from schemas import *
__all__ = 'dashboard',
class CRUDDashboard(CRUDBase):
# 创建一个空看板
async def create(self, db: AsyncIOMotorDatabase,name, user_id: str):
db_obj = DashboardDB( user_id=user_id,
_id=uuid.uuid1().hex,name=name
)
await db[self.coll_name].insert_one(db_obj.dict(by_alias=True))
async def set_sort(self, db: AsyncIOMotorDatabase, index: str, sort: int):
await self.update_one(db, {'_id': index}, {'$set': {'sort': sort}})
async def create_index(self, db: AsyncIOMotorDatabase):
await db[self.coll_name].create_index(
[('project_id', pymongo.DESCENDING), ('name', pymongo.DESCENDING), ('user_id', pymongo.DESCENDING)],
unique=True)
async def find_report(self, db: AsyncIOMotorDatabase,user_id):
await self.find(db, {'user_id': user_id}, {})
dashboard = CRUDDashboard('dashboard')