Add UUID handling, sorting, filtering, and soft delete functionality to CRUD operations
- Enhanced UUID validation by supporting both string and `UUID` formats. - Added advanced filtering and sorting capabilities to `get_multi_with_total` method. - Introduced soft delete and restore functionality for models with `deleted_at` column. - Updated tests to reflect new endpoints and rate-limiting logic. - Improved schema definitions with `SortParams` and `SortOrder` for consistent API inputs.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
"""
|
||||
Common schemas used across the API for pagination, responses, etc.
|
||||
Common schemas used across the API for pagination, responses, filtering, and sorting.
|
||||
"""
|
||||
from typing import Generic, TypeVar, List, Optional
|
||||
from enum import Enum
|
||||
from pydantic import BaseModel, Field
|
||||
from math import ceil
|
||||
|
||||
@@ -9,6 +10,12 @@ from math import ceil
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
class SortOrder(str, Enum):
|
||||
"""Sort order options."""
|
||||
ASC = "asc"
|
||||
DESC = "desc"
|
||||
|
||||
|
||||
class PaginationParams(BaseModel):
|
||||
"""Parameters for pagination."""
|
||||
|
||||
@@ -44,6 +51,28 @@ class PaginationParams(BaseModel):
|
||||
}
|
||||
|
||||
|
||||
class SortParams(BaseModel):
|
||||
"""Parameters for sorting."""
|
||||
|
||||
sort_by: Optional[str] = Field(
|
||||
default=None,
|
||||
description="Field name to sort by"
|
||||
)
|
||||
sort_order: SortOrder = Field(
|
||||
default=SortOrder.ASC,
|
||||
description="Sort order (asc or desc)"
|
||||
)
|
||||
|
||||
model_config = {
|
||||
"json_schema_extra": {
|
||||
"example": {
|
||||
"sort_by": "created_at",
|
||||
"sort_order": "desc"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PaginationMeta(BaseModel):
|
||||
"""Metadata for paginated responses."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user