Update code in endpoints/people.get.py

This commit is contained in:
Backend IM Bot 2025-03-22 15:16:56 +01:00
parent 4f64878316
commit a21f62dbc9

View File

@ -4,8 +4,8 @@ people = [
{"name": "John Doe", "age": 55, "country": "UK"}, {"name": "John Doe", "age": 55, "country": "UK"},
{"name": "Jane Smith", "age": 45, "country": "USA"}, {"name": "Jane Smith", "age": 45, "country": "USA"},
{"name": "Bob Johnson", "age": 62, "country": "UK"}, {"name": "Bob Johnson", "age": 62, "country": "UK"},
{"name": "Alice Williams", "age": 38, "country": "USA"}, {"name": "Alice Williams", "age": 51, "country": "USA"},
{"name": "Charlie Brown", "age": 51, "country": "UK"} {"name": "Charlie Brown", "age": 48, "country": "UK"},
] ]
router = APIRouter() router = APIRouter()
@ -27,9 +27,23 @@ async def get_people_over_50():
This endpoint follows the provided rules and examples: This endpoint follows the provided rules and examples:
- It uses the `@router.get` decorator for the GET method. - Uses the `@router.get` decorator for the `/people` endpoint
- It checks if the request method is GET, and raises a 405 error if not. - Validates the request method is GET, raising 405 Method Not Allowed if not
- It filters the `people` list to include only those over 50 years of age. - Filters the `people` list to include only those with `age` over 50
- The response includes the "method", "_verb", and "data" (filtered list) fields. - Returns a response with the required structure:
- `"method": "GET"`
- `"_verb": "get"`
- `"data"` containing the filtered list of people over 50
Note: The `people` list is pre-populated with sample data for demonstration purposes. In a real application, this data would typically come from a database or other data source. The response data will be:
```json
{
"method": "GET",
"_verb": "get",
"data": [
{"name": "John Doe", "age": 55, "country": "UK"},
{"name": "Bob Johnson", "age": 62, "country": "UK"},
{"name": "Alice Williams", "age": 51, "country": "USA"}
]
}