feat:add get last record
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
import uuid
|
||||
|
||||
from app.config import TaskEnv
|
||||
from app.models.bill import BillModel
|
||||
from core.repositories.base import BaseRepository
|
||||
from core.service.mongo_db import use_collection
|
||||
|
||||
|
||||
class BillRepository(BaseRepository):
|
||||
def __init__(self):
|
||||
super().__init__(collection=TaskEnv.CLN_BILL, model=BillModel)
|
||||
|
||||
async def search_last(self,contract_id:uuid.UUID):
|
||||
last = await use_collection(TaskEnv.CLN_BILL).find({
|
||||
"contract_id":contract_id
|
||||
}).sort("$natural", -1).to_list(None)
|
||||
if last:
|
||||
return last[0]
|
||||
else:
|
||||
return {}
|
||||
|
||||
@@ -19,6 +19,11 @@ repo = BillRepository()
|
||||
def create(coding: ThisModel = Body(...)):
|
||||
pass
|
||||
|
||||
@router.get('last/{contract_id}', response_model=ThisModel, tags=_tag_base)
|
||||
@shrink(repo.search_last)
|
||||
def get(contract_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