app/modules/products/services.py
def fetch_all_with_pagination(self, db: Session, page: int, per_page: int = 20, name: str = '') -> ProductsResponse:
        """
        Retrieve all products records listed by page argument and pagination metadata.

        Args:
            db (Session): The database session.
            page (int): Page to fetch.
            per_page (int): Amount of products per page.
            name (str): Product name to filter.

        Raises:
            InvalidPage: If the page informed is invalid.
            ItensNotFound: If no item was found.
            InvalidPageItemsNumber: Numbers of items per page must be greater than 0.

        Returns:
            ProductsResponse: A dict with products records and pagination metadata.
        """
        if page <= 0:
            raise InvalidPage(f"Page number should be positive and greater than zero: {page}")
        if per_page <= 0:
            raise InvalidPageItemsNumber(f"Numbers of items per page must be greater than zero")

        query = db.query(Product).filter(
            Product.is_deleted == False,
            func.lower(Product.name).contains(name.lower(), autoescape=True)
        ).order_by(Product.id)

        query, pagination = apply_pagination(query, page_number=page, page_size=per_page)
        products = parse_obj_as(List[ProductResponse], query.all())

        if page > pagination.num_pages and pagination.num_pages > 0:
            raise InvalidPage(f"Page number invalid, the total of pages is {pagination.num_pages}: {page}")
        if len(products) == 0:
            raise ItensNotFound("No products found")

        pagination_metadata = make_pagination_metadata(
            current_page=page,
            total_pages=pagination.num_pages,
            per_page=per_page,
            total_items=pagination.total_results,
            url_args={'name': name}
        )
        response = ProductsResponse(
            pagination_metadata = pagination_metadata,
            records = products
        )
        return response

        Retrieve all products records listed by page argument and pagination metadata.

        Args:
            db (Session): The database session.
            page (int): Page to fetch.
            per_page (int): Amount of products per page.
            name (str): Product name to filter.

        Raises:
            InvalidPage: If the page informed is invalid.
            ItensNotFound: If no item was found.
            InvalidPageItemsNumber: Numbers of items per page must be greater than 0.

        Returns:
            ProductsResponse: A dict with products records and pagination metadata.
        
Retrieve all products records listed by page argument and pagination metadata.
Retrieve all products records listed by page argument and pagination metadata .
def fetch_all_with_pagination(self, db: Session, page: int, per_page: int = 20, name: str = '') -> ProductsResponse:
        if page <= 0:
            raise InvalidPage(f"Page number should be positive and greater than zero: {page}")
        if per_page <= 0:
            raise InvalidPageItemsNumber(f"Numbers of items per page must be greater than zero")
        query = db.query(Product).filter(
            Product.is_deleted == False,
            func.lower(Product.name).contains(name.lower(), autoescape=True)
        ).order_by(Product.id)
        query, pagination = apply_pagination(query, page_number=page, page_size=per_page)
        products = parse_obj_as(List[ProductResponse], query.all())
        if page > pagination.num_pages and pagination.num_pages > 0:
            raise InvalidPage(f"Page number invalid, the total of pages is {pagination.num_pages}: {page}")
        if len(products) == 0:
            raise ItensNotFound("No products found")
        pagination_metadata = make_pagination_metadata(
            current_page=page,
            total_pages=pagination.num_pages,
            per_page=per_page,
            total_items=pagination.total_results,
            url_args={'name': name}
        )
        response = ProductsResponse(
            pagination_metadata = pagination_metadata,
            records = products
        )
        return response
def fetch_all_with_pagination ( self , db : Session , page : int , per_page : int = 20 , name : str = '' ) -> ProductsResponse : if page <= 0 : raise InvalidPage ( f"Page number should be positive and greater than zero: {page}" ) if per_page <= 0 : raise InvalidPageItemsNumber ( f"Numbers of items per page must be greater than zero" ) query = db . query ( Product ) . filter ( Product . is_deleted == False , func . lower ( Product . name ) . contains ( name . lower ( ) , autoescape = True ) ) . order_by ( Product . id ) query , pagination = apply_pagination ( query , page_number = page , page_size = per_page ) products = parse_obj_as ( List [ ProductResponse ] , query . all ( ) ) if page > pagination . num_pages and pagination . num_pages > 0 : raise InvalidPage ( f"Page number invalid, the total of pages is {pagination.num_pages}: {page}" ) if len ( products ) == 0 : raise ItensNotFound ( "No products found" ) pagination_metadata = make_pagination_metadata ( current_page = page , total_pages = pagination . num_pages , per_page = per_page , total_items = pagination . total_results , url_args = { 'name' : name } ) response = ProductsResponse ( pagination_metadata = pagination_metadata , records = products ) return response
Retrieve all products records listed by page argument and pagination metadata.
Retrieve all products records listed by page argument and pagination metadata .
"""
        Retrieve all products records listed by page argument and pagination metadata.

        Args:
            db (Session): The database session.
            page (int): Page to fetch.
            per_page (int): Amount of products per page.
            name (str): Product name to filter.

        Raises:
            InvalidPage: If the page informed is invalid.
            ItensNotFound: If no item was found.
            InvalidPageItemsNumber: Numbers of items per page must be greater than 0.

        Returns:
            ProductsResponse: A dict with products records and pagination metadata.
        """
A dict with products records and pagination metadata.
A dict with products records and pagination metadata .
ProductsResponse
If the page informed is invalid.
If the page informed is invalid .
InvalidPage
If no item was found.
If no item was found .
ItensNotFound
Numbers of items per page must be greater than 0.
Numbers of items per page must be greater than 0 .
InvalidPageItemsNumber
self
db
Session
The database session.
The database session .
page
int
Page to fetch.
Page to fetch .
per_page
int
Amount of products per page.
Amount of products per page .
name
str
Product name to filter.
Product name to filter .