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

        Args:
            db (Session): The database session.
            page (int): Page to fetch.
            per_page (int): Amount of providers per page.
            name (str): Provider 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:
            ProvidersResponse: A dict with providers 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(Provider).filter(
            Provider.is_deleted == False,
            func.lower(Provider.name).contains(name.lower(), autoescape=True)
        ).order_by(Provider.id)

        query, pagination = apply_pagination(query, page_number=page, page_size=per_page)
        providers = parse_obj_as(List[ProviderResponse], 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(providers) == 0:
            raise ItensNotFound("No providers 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 = ProvidersResponse(
            pagination_metadata = pagination_metadata,
            records = providers
        )
        return response

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

        Args:
            db (Session): The database session.
            page (int): Page to fetch.
            per_page (int): Amount of providers per page.
            name (str): Provider 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:
            ProvidersResponse: A dict with providers records and pagination metadata.
        
Retrieve all providers records listed by page argument and pagination metadata.
Retrieve all providers records listed by page argument and pagination metadata .
def fetch_all_with_pagination(self, db: Session, page: int, per_page: int = 20, name: str = '') -> ProvidersResponse:
        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(Provider).filter(
            Provider.is_deleted == False,
            func.lower(Provider.name).contains(name.lower(), autoescape=True)
        ).order_by(Provider.id)
        query, pagination = apply_pagination(query, page_number=page, page_size=per_page)
        providers = parse_obj_as(List[ProviderResponse], 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(providers) == 0:
            raise ItensNotFound("No providers 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 = ProvidersResponse(
            pagination_metadata = pagination_metadata,
            records = providers
        )
        return response
def fetch_all_with_pagination ( self , db : Session , page : int , per_page : int = 20 , name : str = '' ) -> ProvidersResponse : 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 ( Provider ) . filter ( Provider . is_deleted == False , func . lower ( Provider . name ) . contains ( name . lower ( ) , autoescape = True ) ) . order_by ( Provider . id ) query , pagination = apply_pagination ( query , page_number = page , page_size = per_page ) providers = parse_obj_as ( List [ ProviderResponse ] , 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 ( providers ) == 0 : raise ItensNotFound ( "No providers 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 = ProvidersResponse ( pagination_metadata = pagination_metadata , records = providers ) return response
Retrieve all providers records listed by page argument and pagination metadata.
Retrieve all providers records listed by page argument and pagination metadata .
"""
        Retrieve all providers records listed by page argument and pagination metadata.

        Args:
            db (Session): The database session.
            page (int): Page to fetch.
            per_page (int): Amount of providers per page.
            name (str): Provider 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:
            ProvidersResponse: A dict with providers records and pagination metadata.
        """
A dict with providers records and pagination metadata.
A dict with providers records and pagination metadata .
ProvidersResponse
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 providers per page.
Amount of providers per page .
name
str
Provider name to filter.
Provider name to filter .