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 = [ users = [
{ {
"id": "1", "id": "1",
"username": "user1", "name": "John Doe",
"email": "user1@example.com", "country": "Nigeria"
"country": "USA",
"state": "California"
}, },
{ {
"id": "2", "id": "2",
"username": "user2", "name": "Jane Smith",
"email": "user2@example.com", "country": "South Africa"
"country": "Canada",
"state": "Ontario"
} }
] ]
@ -21,15 +17,14 @@ router = APIRouter()
@router.get("/users") @router.get("/users")
async def get_users(): async def get_users():
"""Fetch list of users""" """Fetches list of users"""
if request.method != "GET": response = {
raise HTTPException(status_code=405, detail="Method Not Allowed")
return {
"method": "GET", "method": "GET",
"_verb": "get", "_verb": "get",
"users": users "users": users
} }
```
if request.method != "GET":
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. raise HTTPException(status_code=405, detail="Method Not Allowed")
return response