feat: modules, products, services, services kits
This commit is contained in:
33
modules/fulfillment_base/repositories/product.py
Normal file
33
modules/fulfillment_base/repositories/product.py
Normal file
@ -0,0 +1,33 @@
|
||||
from modules.fulfillment_base.models import Product
|
||||
from modules.fulfillment_base.schemas.product import (
|
||||
CreateProductSchema,
|
||||
UpdateProductSchema,
|
||||
)
|
||||
from repositories.mixins import *
|
||||
from schemas.base import PaginationSchema
|
||||
|
||||
|
||||
class ProductRepository(
|
||||
BaseRepository,
|
||||
RepGetAllMixin[Product],
|
||||
RepDeleteMixin[Product],
|
||||
RepCreateMixin[Product, CreateProductSchema],
|
||||
RepUpdateMixin[Product, UpdateProductSchema],
|
||||
RepGetByIdMixin[Product],
|
||||
):
|
||||
entity_class = Product
|
||||
|
||||
def _process_get_all_stmt_with_args(self, stmt: Select, *args) -> Select:
|
||||
search_input = args[0]
|
||||
pagination: PaginationSchema = args[1]
|
||||
if search_input:
|
||||
stmt = stmt.where(Product.name.ilike(f"%{search_input}%"))
|
||||
if pagination.items_per_page and pagination.page:
|
||||
stmt = self._apply_pagination(
|
||||
stmt, pagination.page, pagination.items_per_page
|
||||
)
|
||||
|
||||
return stmt
|
||||
|
||||
async def update(self, product: Product, data: UpdateProductSchema) -> Product:
|
||||
return await self._apply_update_data_to_model(product, data, True)
|
||||
Reference in New Issue
Block a user