Update code in endpoints/basket.post.py
This commit is contained in:
parent
dca2be4296
commit
5dea9c0ab6
43
endpoints/basket.post.py
Normal file
43
endpoints/basket.post.py
Normal file
@ -0,0 +1,43 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import uuid
|
||||
|
||||
games = [] # In-memory storage
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/basket")
|
||||
async def save_game(
|
||||
name: str,
|
||||
description: str,
|
||||
price: float
|
||||
):
|
||||
"""Save a new game to the database"""
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
game_id = str(uuid.uuid4())
|
||||
games.append({
|
||||
"id": game_id,
|
||||
"name": name,
|
||||
"description": description,
|
||||
"price": price
|
||||
})
|
||||
|
||||
return {
|
||||
"message": "Game saved successfully",
|
||||
"game_id": game_id,
|
||||
"method": "POST",
|
||||
"_verb": "post"
|
||||
}
|
||||
|
||||
@router.get("/basket")
|
||||
async def get_games():
|
||||
"""Fetch all saved games from the database"""
|
||||
if request.method != "GET":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
return {
|
||||
"games": games,
|
||||
"method": "GET",
|
||||
"_verb": "get"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user