feat: add create request

This commit is contained in:
2026-06-10 18:54:30 +03:00
parent dc05528405
commit 5e085ae67e
7 changed files with 114 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
from typing import Any
from ulid import ULID
from sqlalchemy import func, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.exc import SQLAlchemyError
@@ -45,6 +46,16 @@ class PurchaseRequestRepository(IPurchaseRequestRepository):
stmt = stmt.where(PurchaseRequestModel.organization_id == organization_id)
return stmt
async def create(self, values: dict[str, Any]) -> PurchaseRequestEntity:
model = PurchaseRequestModel(id=str(ULID()), **values)
self._session.add(model)
try:
await self._session.flush()
return self._to_entity(model)
except SQLAlchemyError as exc:
self._logger.exception(str(exc))
raise ApplicationException(status_code=500, message='Database error')
async def get_by_id(self, request_id: str) -> PurchaseRequestEntity:
res = await self._session.execute(select(PurchaseRequestModel).where(PurchaseRequestModel.id == request_id))
m = res.scalar_one_or_none()