feat: admin product deletion

This commit is contained in:
2026-08-13 12:03:56 +07:00
parent 1b78f2ba36
commit 406356c240
5 changed files with 239 additions and 6 deletions

View File

@@ -7,6 +7,35 @@ from db.models import Product
class ProductRepository:
async def delete_product(self, session: AsyncSession, product_id: int) -> Product | None:
product = await self.get_product_by_id(session, product_id)
if not product:
return None
await session.delete(product)
await session.commit()
return product
async def add_product(
self,
session: AsyncSession,
*,
category_id: int | None,
name: str,
description: str,
price: int,
) -> Product:
product = Product(
category_id=category_id,
name=name,
description=description,
price=price,
)
session.add(product)
await session.commit()
await session.refresh(product)
return product
async def get_product_by_id(
self, session: AsyncSession, product_id: int, *, include_hidden: bool = True
) -> Product | None: