Update code in endpoints/human.get.py
This commit is contained in:
parent
29ea054568
commit
5a4a9d9ebe
@ -2,10 +2,10 @@ from fastapi import APIRouter, HTTPException
|
|||||||
|
|
||||||
people = [
|
people = [
|
||||||
{"name": "Alice", "age": 55, "country": "UK"},
|
{"name": "Alice", "age": 55, "country": "UK"},
|
||||||
{"name": "Bob", "age": 45, "country": "USA"},
|
{"name": "Bob", "age": 45, "country": "US"},
|
||||||
{"name": "Charlie", "age": 60, "country": "ESP"},
|
{"name": "Charlie", "age": 60, "country": "ESP"},
|
||||||
{"name": "David", "age": 35, "country": "UK"},
|
{"name": "David", "age": 35, "country": "UK"},
|
||||||
{"name": "Eve", "age": 52, "country": "USA"}
|
{"name": "Eve", "age": 52, "country": "US"}
|
||||||
]
|
]
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@ -16,7 +16,7 @@ async def get_people_over_50():
|
|||||||
if request.method != "GET":
|
if request.method != "GET":
|
||||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||||
|
|
||||||
over_50 = [p for p in people if p["age"] > 50]
|
over_50 = [person for person in people if person["age"] > 50]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
@ -25,12 +25,4 @@ async def get_people_over_50():
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This endpoint follows the provided rules and examples:
|
This endpoint filters the `people` list to only include those whose age is over 50, and returns that filtered list in the response data. It also includes the required method metadata fields.
|
||||||
|
|
||||||
- It uses the `@router.get` decorator for the `GET` method.
|
|
||||||
- It validates the request method and raises a 405 error if not `GET`.
|
|
||||||
- It filters the `people` list to include only those over 50 years old.
|
|
||||||
- The response includes the required `method`, `_verb`, and `data` fields.
|
|
||||||
- The `data` field contains the list of people over 50.
|
|
||||||
|
|
||||||
Note that this endpoint assumes the `people` list is already defined and populated with data. In a real application, this data would likely come from a database or other data source.
|
|
Loading…
x
Reference in New Issue
Block a user