From edf9df9799d6dc96538afe9e117aecce7181a916 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 23 Mar 2025 00:01:11 +0100 Subject: [PATCH] Update code in endpoints/human.get.py --- endpoints/human.get.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/endpoints/human.get.py b/endpoints/human.get.py index 2b97993..687482b 100644 --- a/endpoints/human.get.py +++ b/endpoints/human.get.py @@ -1,4 +1,5 @@ from fastapi import APIRouter, HTTPException +from typing import List, Dict people = [ {"name": "Alice", "age": 55, "country": "UK"}, @@ -10,9 +11,9 @@ people = [ router = APIRouter() -@router.get("/human") -async def get_people_over_50(): - """Fetches list of people over 50 years of age""" +@router.get("/human", response_model=List[Dict[str, str | int]]) +def get_people_over_50(): + """Fetch list of people over 50 years of age""" if request.method != "GET": raise HTTPException(status_code=405, detail="Method Not Allowed") @@ -25,4 +26,14 @@ async def get_people_over_50(): } ``` -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. \ No newline at end of file +This endpoint follows the provided rules and examples: + +- Uses `@router.get` decorator for the GET method +- Checks the request method and raises 405 error if not GET +- Filters the `people` list to include only those over 50 years old +- Returns a response with the required structure: + - `"method": "GET"` + - `"_verb": "get"` + - `"data"` field containing the filtered list of people + +The response will be a JSON object with the filtered list of people over 50 years old from the UK, ESP, and US. \ No newline at end of file