Update code in endpoints/people.get.py

This commit is contained in:
Backend IM Bot 2025-03-22 14:12:41 +01:00
parent 7fa49278c3
commit e2eb799233

View File

@ -1,11 +1,11 @@
from fastapi import APIRouter, HTTPException
people = [
{"name": "Alice", "age": 55},
{"name": "Bob", "age": 45},
{"name": "Charlie", "age": 60},
{"name": "David", "age": 35},
{"name": "Eve", "age": 52}
{"id": 1, "name": "Alice", "age": 55},
{"id": 2, "name": "Bob", "age": 45},
{"id": 3, "name": "Charlie", "age": 60},
{"id": 4, "name": "David", "age": 35},
{"id": 5, "name": "Eve", "age": 52}
]
router = APIRouter()
@ -25,11 +25,4 @@ async def get_people_over_50():
}
```
This endpoint adheres to the provided rules and examples:
1. It uses the `@router.get` decorator for the `/people` endpoint.
2. It validates the request method and raises a 405 error if not GET.
3. It filters the `people` list to only include those over 50 years old.
4. The response includes the required `method` and `_verb` fields, as well as the filtered `data`.
Note that this assumes the `people` list is already defined and populated with dictionaries containing `name` and `age` keys.
This endpoint defines a list of `people` with their `id`, `name`, and `age`. The `get_people_over_50` function filters this list to include only those whose `age` is greater than 50. The response includes the filtered list under the `data` key, along with the `method` and `_verb` metadata as required.