This commit is contained in:
2024-03-04 04:15:01 +03:00
parent d870f1cffe
commit bf24c791fc
12 changed files with 116 additions and 13 deletions

View File

@@ -13,13 +13,25 @@ class DealService(BaseService):
async def _get_deal_by_id(self, deal_id) -> Deal:
return await self.session.get(Deal, deal_id)
async def create(self, request: DealCreateRequest) -> DealCreateResponse:
async def create(self, request: DealCreateRequest, user: User) -> DealCreateResponse:
deal = Deal(
name=request.name,
created_at=datetime.datetime.now(),
current_status=DealStatus.AWAITING_ACCEPTANCE
current_status=DealStatus.CREATED
)
self.session.add(deal)
await self.session.flush()
# Append status history
status_change = DealStatusHistory(
deal_id=request.deal_id,
user_id=user.id,
changed_at=datetime.datetime.now(),
from_status=deal.current_status,
to_status=DealStatus.CREATED.AWAITING_ACCEPTANCE
)
self.session.add(status_change)
await self.session.commit()
return DealCreateResponse(ok=True)