Update code in endpoints/logout.post.py

This commit is contained in:
Backend IM Bot 2025-03-23 17:44:26 +01:00
parent f53b347b95
commit 08ef540a92

View File

@ -1,26 +1,25 @@
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
laptops = [ laptops = [
{"name": "MacBook Pro"}, {"name": "Dell XPS 13"},
{"name": "Dell XPS"}, {"name": "MacBook Pro 16"},
{"name": "Lenovo ThinkPad"}, {"name": "Lenovo ThinkPad X1 Carbon"},
{"name": "HP Spectre"} {"name": "HP Spectre x360"},
{"name": "Asus ZenBook Pro Duo"}
] ]
router = APIRouter() router = APIRouter()
@router.post("/logout") @router.post("/logout", response_model=list)
async def logout(): async def logout():
"""endpoints that returns list of laptops names""" """Returns list of laptop names"""
if request.method != "POST": if request.method != "POST":
raise HTTPException(status_code=405, detail={ raise HTTPException(status_code=405, detail="Method Not Allowed")
"message": "Method Not Allowed",
"method": "POST", laptop_names = [laptop["name"] for laptop in laptops]
"_verb": "post"
})
return { return {
"method": "POST", "method": "POST",
"_verb": "post", "_verb": "post",
"laptops": [laptop["name"] for laptop in laptops] "data": laptop_names
} }