feat: product endpoints changes for products table
This commit is contained in:
@ -40,9 +40,19 @@ class RepDeleteMixin(Generic[EntityType], RepBaseMixin[EntityType]):
|
||||
class RepCreateMixin(Generic[EntityType, CreateSchemaType], RepBaseMixin[EntityType]):
|
||||
entity_class: Type[EntityType]
|
||||
|
||||
async def _prepare_create(self, data: CreateSchemaType) -> dict:
|
||||
return data.model_dump()
|
||||
|
||||
async def _after_create(self, obj: EntityType, data: CreateSchemaType) -> None:
|
||||
pass
|
||||
|
||||
async def create(self, data: CreateSchemaType) -> int:
|
||||
obj = self.entity_class(**data.model_dump())
|
||||
prepared_data = await self._prepare_create(data)
|
||||
obj = self.entity_class(**prepared_data)
|
||||
self.session.add(obj)
|
||||
await self.session.flash()
|
||||
await self.session.refresh(obj)
|
||||
await self._after_create(obj, data)
|
||||
await self.session.commit()
|
||||
await self.session.refresh(obj)
|
||||
return obj.id
|
||||
|
||||
Reference in New Issue
Block a user