From 6520f8979501d8483243a2129c84318f9eb6cddf Mon Sep 17 00:00:00 2001 From: wuaho Date: Thu, 9 Sep 2021 15:30:27 +0800 Subject: [PATCH] 1 --- crud/crud_api_list.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crud/crud_api_list.py b/crud/crud_api_list.py index 1445fe3..9275edd 100644 --- a/crud/crud_api_list.py +++ b/crud/crud_api_list.py @@ -5,6 +5,8 @@ from crud.base import CRUDBase __all__ = 'api_list', +from utils import get_uid + class CRUDApiList(CRUDBase): async def add_api(self, db: AsyncIOMotorDatabase, data_in: schemas.AddApi): @@ -16,7 +18,9 @@ class CRUDApiList(CRUDBase): async def update_api(self, db: AsyncIOMotorDatabase, data_in: schemas.UpdateApi): where = {'path': data_in.path} data = {'$set': data_in.dict()} - + is_exists = await self.find_one(db, {'path': data_in.path}) + if not is_exists: + data['$set']['_id'] = get_uid() return await self.update_one(db, where, data, upsert=True) async def edit_api(self, db: AsyncIOMotorDatabase, data_in: schemas.EditApi): @@ -24,14 +28,9 @@ class CRUDApiList(CRUDBase): data = {'$set': data_in.dict(exclude={'id'})} return await self.update_one(db, where, data) - async def all_api(self, db: AsyncIOMotorDatabase): return await self.find_many(db) - - - - async def del_api(self, db: AsyncIOMotorDatabase, data_in: schemas.DelApi): return await self.delete_id(db, *data_in.ids)