Update code in endpoints/users.get.py

This commit is contained in:
Backend IM Bot 2025-03-22 14:05:52 +01:00
parent 8da36f2b56
commit 2e12c7c759

View File

@ -3,17 +3,13 @@ from fastapi import APIRouter, HTTPException
users = [
{
"id": "1",
"username": "user1",
"email": "user1@example.com",
"country": "USA",
"state": "California"
"name": "John Doe",
"country": "Nigeria"
},
{
"id": "2",
"username": "user2",
"email": "user2@example.com",
"country": "Canada",
"state": "Ontario"
"name": "Jane Smith",
"country": "South Africa"
}
]
@ -21,15 +17,14 @@ router = APIRouter()
@router.get("/users")
async def get_users():
"""Fetch list of users"""
if request.method != "GET":
raise HTTPException(status_code=405, detail="Method Not Allowed")
return {
"""Fetches list of users"""
response = {
"method": "GET",
"_verb": "get",
"users": users
}
```
This endpoint fetches a list of users from the in-memory `users` list. It checks if the request method is GET, and if not, raises a 405 Method Not Allowed error. The response includes the method, a "_verb" metadata field, and the list of user objects containing id, username, email, country, and state.
if request.method != "GET":
raise HTTPException(status_code=405, detail="Method Not Allowed")
return response