Update code in endpoints/people.get.py
This commit is contained in:
parent
7fa49278c3
commit
e2eb799233
@ -1,11 +1,11 @@
|
|||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
|
|
||||||
people = [
|
people = [
|
||||||
{"name": "Alice", "age": 55},
|
{"id": 1, "name": "Alice", "age": 55},
|
||||||
{"name": "Bob", "age": 45},
|
{"id": 2, "name": "Bob", "age": 45},
|
||||||
{"name": "Charlie", "age": 60},
|
{"id": 3, "name": "Charlie", "age": 60},
|
||||||
{"name": "David", "age": 35},
|
{"id": 4, "name": "David", "age": 35},
|
||||||
{"name": "Eve", "age": 52}
|
{"id": 5, "name": "Eve", "age": 52}
|
||||||
]
|
]
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@ -25,11 +25,4 @@ async def get_people_over_50():
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This endpoint adheres to the provided rules and examples:
|
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.
|
||||||
|
|
||||||
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.
|
|
Loading…
x
Reference in New Issue
Block a user