feat: add search to crud paginate function (#17)

* feat: add search to crud paginate function

* fixes: comments + tests import
This commit is contained in:
d3vyce
2026-01-29 00:08:02 +01:00
committed by GitHub
parent 577e087321
commit d14551781c
7 changed files with 644 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ from .exceptions import (
ApiException,
ConflictError,
ForbiddenError,
NoSearchableFieldsError,
NotFoundError,
UnauthorizedError,
generate_error_responses,
@@ -14,6 +15,7 @@ __all__ = [
"ApiException",
"ConflictError",
"ForbiddenError",
"NoSearchableFieldsError",
"NotFoundError",
"UnauthorizedError",
]

View File

@@ -119,6 +119,25 @@ class RoleNotFoundError(NotFoundError):
)
class NoSearchableFieldsError(ApiException):
"""Raised when search is requested but no searchable fields are available."""
api_error = ApiError(
code=400,
msg="No Searchable Fields",
desc="No searchable fields configured for this resource.",
err_code="SEARCH-400",
)
def __init__(self, model: type) -> None:
self.model = model
detail = (
f"No searchable fields found for model '{model.__name__}'. "
"Provide 'search_fields' parameter or set 'searchable_fields' on the CRUD class."
)
super().__init__(detail)
def generate_error_responses(
*errors: type[ApiException],
) -> dict[int | str, dict[str, Any]]: