initializer service deployed and tested
This commit is contained in:
70
api_services/api_validations/response/pagination.py
Normal file
70
api_services/api_validations/response/pagination.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from typing import Any, Dict, Optional, Union, TypeVar, Type
|
||||
from sqlalchemy import desc, asc
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .base import PostgresResponse
|
||||
|
||||
# Type variable for class methods returning self
|
||||
T = TypeVar("T", bound="BaseModel")
|
||||
|
||||
|
||||
class PaginateConfig:
|
||||
"""
|
||||
Configuration for pagination settings.
|
||||
|
||||
Attributes:
|
||||
DEFAULT_SIZE: Default number of items per page (10)
|
||||
MIN_SIZE: Minimum allowed page size (10)
|
||||
MAX_SIZE: Maximum allowed page size (40)
|
||||
"""
|
||||
|
||||
DEFAULT_SIZE = 10
|
||||
MIN_SIZE = 5
|
||||
MAX_SIZE = 100
|
||||
|
||||
|
||||
class ListOptions(BaseModel):
|
||||
"""
|
||||
Query for list option abilities
|
||||
"""
|
||||
|
||||
page: Optional[int] = 1
|
||||
size: Optional[int] = 10
|
||||
orderField: Optional[Union[tuple[str], list[str]]] = ["uu_id"]
|
||||
orderType: Optional[Union[tuple[str], list[str]]] = ["asc"]
|
||||
# include_joins: Optional[list] = None
|
||||
|
||||
|
||||
class PaginateOnly(ListOptions):
|
||||
"""
|
||||
Query for list option abilities
|
||||
"""
|
||||
|
||||
query: Optional[dict] = None
|
||||
|
||||
|
||||
class PaginationConfig(BaseModel):
|
||||
"""
|
||||
Configuration for pagination settings.
|
||||
|
||||
Attributes:
|
||||
page: Current page number (default: 1)
|
||||
size: Items per page (default: 10)
|
||||
orderField: Field to order by (default: "created_at")
|
||||
orderType: Order direction (default: "desc")
|
||||
"""
|
||||
|
||||
page: int = 1
|
||||
size: int = 10
|
||||
orderField: Optional[Union[tuple[str], list[str]]] = ["created_at"]
|
||||
orderType: Optional[Union[tuple[str], list[str]]] = ["desc"]
|
||||
|
||||
def __init__(self, **data):
|
||||
super().__init__(**data)
|
||||
if self.orderField is None:
|
||||
self.orderField = ["created_at"]
|
||||
if self.orderType is None:
|
||||
self.orderType = ["desc"]
|
||||
|
||||
|
||||
default_paginate_config = PaginateConfig()
|
||||
Reference in New Issue
Block a user