Add card endpoint

This commit is contained in:
Esa Kataja
2024-11-09 22:17:30 +02:00
parent c8884ebeec
commit 6c961db275
2 changed files with 29 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
from models.card import Card
from lib.database.database import get_db
def get_all_cards() -> list[Card]:
sql = "SELECT * FROM cards"
with get_db() as conn:
result = conn.execute(sql).fetchall()
cards: list[Card] = []
for row in result:
card = Card(
id=str(row[0]),
title=row[1],
description=row[2],
point_value=row[3],
created_at=row[4],
updated_at=row[5],
)
cards.append(card)
return cards
+9
View File
@@ -1,7 +1,16 @@
from fastapi import APIRouter
from models.card import Card
from lib.database.card import get_all_cards
router = APIRouter(
prefix="/card",
tags=["card"],
responses={404: {"description": "Not found"}},
)
@router.get("/", response_model=list[Card])
async def get_cards() -> list[Card]:
"""Get all cards"""
return get_all_cards()