30 lines
908 B
Python
30 lines
908 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, obj_in: DashboardCreate, user_id: str):
|
|
db_obj = DashboardDB(
|
|
**obj_in.dict(), user_id=user_id,
|
|
_id=uuid.uuid1().hex
|
|
|
|
)
|
|
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)
|
|
|
|
|
|
dashboard = CRUDDashboard('dashboard')
|