added accepted order status

parent 58915028
from uuid import UUID
from tortoise.exceptions import ValidationError
from ..base import BaseController
......@@ -17,3 +19,10 @@ class OrderController(BaseController):
except ValidationError as e:
raise http_exc.HTTPBadRequestException(detail=f"Validation error: {str(e)}")
async def accepted_order(self, id: UUID):
try:
return await self.order_service.accepted_order(id)
except common_exc.UpdateException as e:
raise http_exc.HTTPBadRequestException(detail=str(e))
import fastapi as fa
from .ctrl import OrderController
from .schemas import OrderPostSchema
from .schemas import OrderPostSchema, OrderIdSchema, OrderStatusSchema
router = fa.APIRouter(prefix='/orders', tags=['Order'])
......@@ -11,3 +11,9 @@ ctrl = OrderController()
@router.post('')
async def create_order(body: OrderPostSchema):
return await ctrl.create(**body.model_dump(exclude_none=True))
@router.put('/accepted')
async def accepted_order(body: OrderIdSchema):
order = await ctrl.accepted_order(**body.model_dump(exclude_none=True))
return OrderStatusSchema.model_validate(order)
......@@ -24,3 +24,8 @@ class OrderGetSchema(OrderIdSchema):
status: str
total: float
products: List[ProductOrderGetSchema]
class OrderStatusSchema(BaseModel):
id: UUID
status: str
from uuid import UUID
from db.repositories.order import OrderRepository
from db.repositories.product import ProductRepository
from .schemas import OrderGetSchema
from exceptions import common as common_exc, http as http_exc
from db.models import ProductOrder
from db.models import ProductOrder, Order
class OrderService:
......@@ -40,3 +42,14 @@ class OrderService:
}
return OrderGetSchema.model_validate(order_data)
async def accepted_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))
order.status = Order.StatusEnum.CONFIRMED
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