Spaces:
Sleeping
Sleeping
| from typing import Any, Dict, List, Union | |
| from fastapi import status as http_status | |
| from fastapi.responses import JSONResponse | |
| def create_response( | |
| status_value: bool, | |
| message: str, | |
| data: Union[Dict[str, Any], List[Any], None] = None, | |
| code: int = http_status.HTTP_200_OK, | |
| ) -> JSONResponse: | |
| """Create standardized JSON response. | |
| Args: | |
| status_value: Success/failure boolean. | |
| message: Human-readable message. | |
| data: Response payload (dict, list, or None). | |
| code: HTTP status code (default: 200). | |
| Returns: | |
| JSONResponse with structure {status, message, data}. | |
| """ | |
| return JSONResponse( | |
| status_code=code, | |
| content={ | |
| "status": status_value, | |
| "message": message, | |
| "data": data if data is not None else {}, | |
| }, | |
| ) | |