fix:add sum
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.config import TaskEnv
|
||||
@@ -16,3 +18,10 @@ class ProgramRepository(BaseRepository):
|
||||
return True
|
||||
else:
|
||||
raise HTTPException(status_code=422,detail='it is not last record')
|
||||
|
||||
async def cal_sum(self, project_id: uuid.UUID):
|
||||
sum = await use_collection(TaskEnv.CLN_AUDIT_PROGRAM).aggregate([
|
||||
{"$match": {"project_id": project_id}},
|
||||
{"$group": {"_id": None, "sum_add": {"$sum": "$add_price"},"sum_sub": {"$sum": "$sub_price"},"sum_diff": {"$sum": "$diff_price"}}}
|
||||
]).to_list(None)
|
||||
return sum
|
||||
|
||||
@@ -24,6 +24,10 @@ def create(coding: ThisModel = Body(...)):
|
||||
def is_last(coding: CheckLast = Body(...)):
|
||||
pass
|
||||
|
||||
@router.get('/sum/{_id}', tags=_tag_base)
|
||||
@shrink(repo.cal_sum)
|
||||
def cal_sum(_id: UUID):
|
||||
pass
|
||||
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base)
|
||||
@shrink(repo.update)
|
||||
def update(_id: UUID, coding: ThisModel = Body(...)):
|
||||
|
||||
Reference in New Issue
Block a user