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):
|
||||
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):
|
||||
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 typing import Optional
|
||||
|
||||
|
||||
class Card(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
title: str
|
||||
description: str
|
||||
score: int
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
class Card(BaseModel):
|
||||
id: Optional[str] = Field(
|
||||
default=None,
|
||||
description="UUID representation of the card",
|
||||
examples=["123e4567-e89b-12d3-a456-426655440000"],
|
||||
)
|
||||
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