crappy
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user