add grand project model, repository
This commit is contained in:
@@ -1,7 +1,26 @@
|
||||
import uuid
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.models.grand_project import GrandProjectModel
|
||||
from core.repositories.base import BaseRepository
|
||||
from core.utils.crudify import mongo_inserter, mongo_updater
|
||||
|
||||
COLLECTION = "grand_project"
|
||||
class GrandProjectRepository(BaseRepository[GrandProjectModel]):
|
||||
def __init__(self):
|
||||
super().__init__(collection=COLLECTION, model=GrandProjectModel)
|
||||
super().__init__(collection=COLLECTION, model=GrandProjectModel)
|
||||
|
||||
def check_weight(self,_inp:GrandProjectModel):
|
||||
sum = 0
|
||||
for project in _inp.assign_project:
|
||||
sum = project.weight
|
||||
if sum != 100:
|
||||
raise HTTPException(422, 'مجموعه وزن ها باید صد درصد باشد')
|
||||
async def create(self, create: GrandProjectModel):
|
||||
self.check_weight(create)
|
||||
return await mongo_inserter(create, self.COLLECTION, getter=self.get)
|
||||
|
||||
async def update(self,_id:uuid.UUID, update:GrandProjectModel):
|
||||
self.check_weight(update)
|
||||
return await mongo_updater(update,_id,COLLECTION)
|
||||
Reference in New Issue
Block a user