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
|
from fastapi import APIRouter, HTTPException
|
||||||
|
|
||||||
laptops = [
|
laptops = [
|
||||||
{"name": "Dell XPS 15"},
|
{"name": "MacBook Pro"},
|
||||||
{"name": "MacBook Pro 16"},
|
{"name": "Dell XPS"},
|
||||||
{"name": "Lenovo ThinkPad X1 Carbon"},
|
{"name": "Lenovo ThinkPad"},
|
||||||
{"name": "HP Spectre x360"},
|
{"name": "HP Spectre"}
|
||||||
{"name": "Asus ZenBook Pro Duo"}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/logout")
|
@router.post("/logout")
|
||||||
async def logout():
|
async def logout():
|
||||||
"""Endpoint that returns list of laptop names"""
|
"""Returns list of laptop names"""
|
||||||
if request.method != "POST":
|
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 {
|
return {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"_verb": "post",
|
|
||||||
"laptops": [laptop["name"] for laptop in laptops]
|
"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