feat: personal notes on bill detail pages
- bill_notes table (migration 0014): user_id, bill_id, content, pinned,
created_at, updated_at; unique constraint (user_id, bill_id)
- BillNote SQLAlchemy model with back-refs on User and Bill
- GET/PUT/DELETE /api/notes/{bill_id} — auth-required, one note per (user, bill)
- NotesPanel component: collapsible, auto-resize textarea, pin toggle,
save + delete; shows last-saved date and pin indicator in collapsed header
- Pinned notes render above BriefPanel; unpinned render below DraftLetterPanel
- Guests see nothing (token guard in component + query disabled)
Co-Authored-By: Jack Levy
This commit is contained in:
@@ -4,6 +4,7 @@ from app.models.follow import Follow
|
||||
from app.models.member import Member
|
||||
from app.models.member_interest import MemberTrendScore, MemberNewsArticle
|
||||
from app.models.news import NewsArticle
|
||||
from app.models.note import BillNote
|
||||
from app.models.notification import NotificationEvent
|
||||
from app.models.setting import AppSetting
|
||||
from app.models.trend import TrendScore
|
||||
@@ -15,6 +16,7 @@ __all__ = [
|
||||
"BillAction",
|
||||
"BillDocument",
|
||||
"BillBrief",
|
||||
"BillNote",
|
||||
"Follow",
|
||||
"Member",
|
||||
"MemberTrendScore",
|
||||
|
||||
@@ -39,6 +39,7 @@ class Bill(Base):
|
||||
news_articles = relationship("NewsArticle", back_populates="bill", order_by="desc(NewsArticle.published_at)")
|
||||
trend_scores = relationship("TrendScore", back_populates="bill", order_by="desc(TrendScore.score_date)")
|
||||
committee_bills = relationship("CommitteeBill", back_populates="bill")
|
||||
notes = relationship("BillNote", back_populates="bill", cascade="all, delete-orphan")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_bills_congress_number", "congress_number"),
|
||||
|
||||
26
backend/app/models/note.py
Normal file
26
backend/app/models/note.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Index, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class BillNote(Base):
|
||||
__tablename__ = "bill_notes"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
pinned = Column(Boolean, nullable=False, default=False)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
user = relationship("User", back_populates="bill_notes")
|
||||
bill = relationship("Bill", back_populates="notes")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("user_id", "bill_id", name="uq_bill_notes_user_bill"),
|
||||
Index("ix_bill_notes_user_id", "user_id"),
|
||||
Index("ix_bill_notes_bill_id", "bill_id"),
|
||||
)
|
||||
@@ -19,3 +19,4 @@ class User(Base):
|
||||
|
||||
follows = relationship("Follow", back_populates="user", cascade="all, delete-orphan")
|
||||
notification_events = relationship("NotificationEvent", back_populates="user", cascade="all, delete-orphan")
|
||||
bill_notes = relationship("BillNote", back_populates="user", cascade="all, delete-orphan")
|
||||
|
||||
Reference in New Issue
Block a user