Skip to content

Commit

Permalink
Adicionado rota para exclusão de order
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsonferovante committed Oct 15, 2024
1 parent abac4a1 commit 21855f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/apps/order/order_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nest.core import Controller, Get, Post
from nest.core import Controller, Get, Post, Delete
from .order_service import OrderService
from .order_model import OrderCreateDTO, Order, OrderFindDTO
from .exceptions.handlers_order_expections import handlers_order_expections
Expand All @@ -25,4 +25,12 @@ async def add_order(self, order: OrderCreateDTO) -> Order:
except Exception as exception:
print ("Exception - add_order", exception)
handlers_order_expections(exception)


@Delete("/delete")
async def delete_order(self, order: OrderFindDTO) -> Order:
try:
return await self.order_service.delete_order(order)
except Exception as exception:
print ("Exception - delete_order", exception)
handlers_order_expections(exception)

12 changes: 12 additions & 0 deletions src/apps/order/order_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ async def get_order_by_identifier(self, identifier: str) -> Order:

await order.save()
return transform_Document_to_Order(order)


@db_request_handler
async def delete_order(self, order: OrderFindDTO) -> Order:
order_find = OrderFindDTO(identifier=identifier)

order = await OrderEntity.find_one(OrderEntity.identifier == order_find.identifier)
if not order:
raise OrderNotFoundException(order_find.identifier)

await order.delete()
return transform_Document_to_Order(order)

0 comments on commit 21855f7

Please sign in to comment.