Add Card add remove endpoints
This commit is contained in:
@@ -62,8 +62,29 @@ def set_movie_watched(movie_id: str):
|
|||||||
|
|
||||||
|
|
||||||
def add_card(card: Card):
|
def add_card(card: Card):
|
||||||
pass
|
sql = """
|
||||||
|
INSERT INTO cards (title, description, point_value)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
"""
|
||||||
|
values = (
|
||||||
|
card.title,
|
||||||
|
card.description,
|
||||||
|
card.point_value,
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
db_run(sql, values)
|
||||||
|
return {"message": "Card added successfully"}
|
||||||
|
except Exception as e:
|
||||||
|
return {"message": f"Error adding card: {e}"}
|
||||||
|
|
||||||
|
|
||||||
def remove_card(card_id: str):
|
def remove_card(card_id: str):
|
||||||
pass
|
sql = f"""
|
||||||
|
DELETE FROM cards WHERE id = '{card_id}'
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
db_run(sql)
|
||||||
|
return {"message": "Card removed successfully"}
|
||||||
|
except Exception as e:
|
||||||
|
return {"message": f"Error removing card: {e}"}
|
||||||
|
|||||||
+25
-8
@@ -1,12 +1,29 @@
|
|||||||
from sqlmodel import Field, SQLModel
|
from pydantic import BaseModel, Field
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class Card(SQLModel, table=True):
|
class Card(BaseModel):
|
||||||
id: Optional[int] = Field(default=None, primary_key=True)
|
id: Optional[str] = Field(
|
||||||
title: str
|
default=None,
|
||||||
description: str
|
description="UUID representation of the card",
|
||||||
score: int
|
examples=["123e4567-e89b-12d3-a456-426655440000"],
|
||||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
)
|
||||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
title: str = Field(
|
||||||
|
description="Title of the card", examples=["The Interupted Kiss"]
|
||||||
|
)
|
||||||
|
description: str = Field(
|
||||||
|
description="Description of the card",
|
||||||
|
examples=["The couples first kiss is interrupted"],
|
||||||
|
)
|
||||||
|
point_value: int = Field(description="Score of the card", examples=[2])
|
||||||
|
created_at: datetime = Field(
|
||||||
|
default_factory=datetime.utcnow,
|
||||||
|
description="Creation date of the card",
|
||||||
|
examples=[datetime.utcnow()],
|
||||||
|
)
|
||||||
|
modified_at: datetime = Field(
|
||||||
|
default_factory=datetime.utcnow,
|
||||||
|
description="Modification date of the card",
|
||||||
|
examples=[datetime.utcnow()],
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user