Update code in endpoints/logout.post.py
This commit is contained in:
parent
3305435dce
commit
4f3c1e321e
@ -1,23 +1,36 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
laptops = [
|
||||
{"name": "Dell XPS 15"},
|
||||
{"name": "MacBook Pro 16"},
|
||||
{"name": "Lenovo ThinkPad X1 Carbon"},
|
||||
{"name": "HP Spectre x360"},
|
||||
{"name": "Asus ZenBook Pro Duo"}
|
||||
{"name": "MacBook Pro"},
|
||||
{"name": "Dell XPS"},
|
||||
{"name": "Lenovo ThinkPad"},
|
||||
{"name": "HP Spectre"}
|
||||
]
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/logout")
|
||||
async def logout():
|
||||
"""Endpoint that returns list of laptop names"""
|
||||
"""Returns list of laptop names"""
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
raise HTTPException(status_code=405, detail={
|
||||
"message": "Method Not Allowed",
|
||||
"method": "POST",
|
||||
"_verb": "post"
|
||||
})
|
||||
|
||||
return {
|
||||
"method": "POST",
|
||||
"_verb": "post",
|
||||
"laptops": [laptop["name"] for laptop in laptops]
|
||||
}
|
||||
```
|
||||
|
||||
This implementation follows the provided rules and examples:
|
||||
|
||||
1. It uses the `@router.post` decorator for the `/logout` endpoint.
|
||||
2. It checks if the request method is POST, and raises a 405 Method Not Allowed error if not.
|
||||
3. The response includes the "method": "POST" field.
|
||||
4. It returns a list of laptop names from the in-memory `laptops` list.
|
||||
5. The response structure matches the provided examples.
|
||||
|
||||
Note that this endpoint does not actually handle any logout functionality, as the description provided was "endpoints that returns list of laptops names".
|
Loading…
x
Reference in New Issue
Block a user