feat(social): Add threaded comments backend support
Some checks are pending
Deploy Elmeg / deploy (push) Waiting to run
Some checks are pending
Deploy Elmeg / deploy (push) Waiting to run
This commit is contained in:
parent
1fb39ea40a
commit
a75921d633
4 changed files with 29 additions and 2 deletions
15
backend/add_parent_id_column.py
Normal file
15
backend/add_parent_id_column.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
from sqlmodel import Session, create_engine, text
|
||||||
|
from database import DATABASE_URL
|
||||||
|
|
||||||
|
def add_column():
|
||||||
|
engine = create_engine(DATABASE_URL)
|
||||||
|
with Session(engine) as session:
|
||||||
|
try:
|
||||||
|
session.exec(text("ALTER TABLE comment ADD COLUMN parent_id INTEGER REFERENCES comment(id)"))
|
||||||
|
session.commit()
|
||||||
|
print("Successfully added parent_id column to comment table")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error adding column (might already exist): {e}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
add_column()
|
||||||
|
|
@ -138,6 +138,7 @@ class Comment(SQLModel, table=True):
|
||||||
show_id: Optional[int] = Field(default=None, foreign_key="show.id")
|
show_id: Optional[int] = Field(default=None, foreign_key="show.id")
|
||||||
venue_id: Optional[int] = Field(default=None, foreign_key="venue.id")
|
venue_id: Optional[int] = Field(default=None, foreign_key="venue.id")
|
||||||
song_id: Optional[int] = Field(default=None, foreign_key="song.id")
|
song_id: Optional[int] = Field(default=None, foreign_key="song.id")
|
||||||
|
parent_id: Optional[int] = Field(default=None, foreign_key="comment.id")
|
||||||
|
|
||||||
user: "User" = Relationship(back_populates="comments")
|
user: "User" = Relationship(back_populates="comments")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,18 @@ def create_comment(
|
||||||
session.commit()
|
session.commit()
|
||||||
session.refresh(db_comment)
|
session.refresh(db_comment)
|
||||||
|
|
||||||
# Notify parent author if reply (TODO: Add parent_id to Comment model)
|
# Notify parent author if reply
|
||||||
# For now, let's just log it or skip.
|
if db_comment.parent_id:
|
||||||
|
parent_comment = session.get(Comment, db_comment.parent_id)
|
||||||
|
if parent_comment and parent_comment.user_id != current_user.id:
|
||||||
|
create_notification(
|
||||||
|
session,
|
||||||
|
user_id=parent_comment.user_id,
|
||||||
|
title="New Reply",
|
||||||
|
message=f"Someone replied to your comment.",
|
||||||
|
type="reply",
|
||||||
|
link=f"/activity"
|
||||||
|
)
|
||||||
|
|
||||||
# Handle Mentions
|
# Handle Mentions
|
||||||
mention_pattern = r"@(\w+)"
|
mention_pattern = r"@(\w+)"
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,7 @@ class CommentBase(SQLModel):
|
||||||
show_id: Optional[int] = None
|
show_id: Optional[int] = None
|
||||||
venue_id: Optional[int] = None
|
venue_id: Optional[int] = None
|
||||||
song_id: Optional[int] = None
|
song_id: Optional[int] = None
|
||||||
|
parent_id: Optional[int] = None
|
||||||
|
|
||||||
class CommentCreate(CommentBase):
|
class CommentCreate(CommentBase):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue