added completed order status

parent 4170c57c
......@@ -36,3 +36,10 @@ class OrderController(BaseController):
async def get_list(self, **kwargs):
return await self.order_service.get_order_list(**kwargs)
async def completed_order(self, id: UUID):
try:
return await self.order_service.completed_order(id)
except common_exc.UpdateException as e:
raise http_exc.HTTPBadRequestException(detail=str(e))
......@@ -30,3 +30,9 @@ async def get_order_status(id: UUID):
@router.get('')
async def get_orders(page: int = 1, size: int = 10):
return await ctrl.get_list(page=page, size=size)
@router.put('/completed')
async def accepted_order(body: OrderIdSchema):
order = await ctrl.completed_order(**body.model_dump(exclude_none=True))
return OrderStatusSchema.model_validate(order)
......@@ -74,3 +74,19 @@ class OrderService:
) for order in orders['result']
]
}
async def completed_order(self, id: UUID):
try:
order = await self.order_repository.get(id=id)
except common_exc.NotFoundException as e:
raise http_exc.HTTPBadRequestException(detail=str(e))
if order.status != Order.StatusEnum.CONFIRMED:
raise http_exc.HTTPBadRequestException(detail='Order must be in CONFIRMED status to be completed')
order.status = Order.StatusEnum.COMPLETED
await order.save()
return {'id': order.id, 'status': order.status}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment