Skip to content

Commit 0b2ca3d

Browse files
committed
WIP: dirac autorun for reminders-bell-badge (error)
1 parent 6bb871c commit 0b2ca3d

3 files changed

Lines changed: 82 additions & 17 deletions

File tree

backend/app/api/routes/reminders.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
ReminderPublic,
1515
RemindersPublic,
1616
ReminderUpdate,
17+
ReminderWithContactPublic,
18+
RemindersWithContactPublic,
1719
)
1820

1921
router = APIRouter(prefix="/reminders", tags=["reminders"])
@@ -58,7 +60,7 @@ def list_reminders(
5860
)
5961

6062

61-
@router.get("/due", response_model=RemindersPublic)
63+
@router.get("/due", response_model=RemindersWithContactPublic)
6264
def list_due_reminders(
6365
session: SessionDep,
6466
current_user: CurrentUser,
@@ -72,30 +74,62 @@ def list_due_reminders(
7274
- snoozed_until is NULL or snoozed_until <= now (not snoozed)
7375
- is_active is True
7476
- owned by current user or tied to visible contacts
77+
78+
Also joins with Contact to include contact_name.
7579
"""
7680
now = datetime.now(timezone.utc)
7781

78-
statement = select(Reminder).where(
79-
Reminder.remind_at <= now,
80-
or_(
81-
Reminder.snoozed_until.is_(None),
82-
Reminder.snoozed_until <= now,
83-
),
84-
Reminder.is_active == True,
85-
or_(
86-
Reminder.owner_id == current_user.id,
87-
Reminder.contact_id.in_(visible_contact_ids(current_user)),
88-
),
82+
statement = (
83+
select(Reminder, Contact.first_name, Contact.last_name)
84+
.outerjoin(Contact, Reminder.contact_id == Contact.id)
85+
.where(
86+
Reminder.remind_at <= now,
87+
or_(
88+
Reminder.snoozed_until.is_(None),
89+
Reminder.snoozed_until <= now,
90+
),
91+
Reminder.is_active == True,
92+
or_(
93+
Reminder.owner_id == current_user.id,
94+
Reminder.contact_id.in_(visible_contact_ids(current_user)),
95+
),
96+
)
8997
)
9098

91-
count_statement = select(func.count()).select_from(statement.subquery())
99+
count_statement = select(func.count()).select_from(
100+
select(Reminder.id)
101+
.outerjoin(Contact, Reminder.contact_id == Contact.id)
102+
.where(
103+
Reminder.remind_at <= now,
104+
or_(
105+
Reminder.snoozed_until.is_(None),
106+
Reminder.snoozed_until <= now,
107+
),
108+
Reminder.is_active == True,
109+
or_(
110+
Reminder.owner_id == current_user.id,
111+
Reminder.contact_id.in_(visible_contact_ids(current_user)),
112+
),
113+
)
114+
.subquery()
115+
)
92116
count = session.exec(count_statement).one()
93117

94118
statement = statement.order_by(Reminder.remind_at.asc()).offset(skip).limit(limit)
95-
reminders = session.exec(statement).all()
96-
97-
return RemindersPublic(
98-
data=[ReminderPublic.model_validate(r) for r in reminders],
119+
results = session.exec(statement).all()
120+
121+
reminders_with_contact = []
122+
for row in results:
123+
reminder = row[0]
124+
first_name = row[1]
125+
last_name = row[2]
126+
reminder_data = ReminderWithContactPublic.model_validate(reminder)
127+
if first_name:
128+
reminder_data.contact_name = f"{first_name} {last_name or ''}".strip()
129+
reminders_with_contact.append(reminder_data)
130+
131+
return RemindersWithContactPublic(
132+
data=reminders_with_contact,
99133
count=count,
100134
)
101135

backend/app/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,8 +1252,18 @@ class ReminderPublic(ReminderBase):
12521252
created_at: datetime
12531253

12541254

1255+
class ReminderWithContactPublic(ReminderPublic):
1256+
"""Reminder with optional contact name for list views."""
1257+
contact_name: str | None = None
1258+
1259+
12551260
class RemindersPublic(SQLModel):
12561261
data: list[ReminderPublic]
1262+
1263+
1264+
class RemindersWithContactPublic(SQLModel):
1265+
"""Response wrapper for reminders that include contact name."""
1266+
data: list[ReminderWithContactPublic]
12571267
count: int
12581268

12591269

front

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Types for reminders with contact information
2+
// These extend the auto-generated types with contact_name field
3+
4+
export interface ReminderWithContactPublic {
5+
title: string;
6+
description: string | null;
7+
remind_at: string;
8+
frequency: string;
9+
is_active: boolean;
10+
id: string;
11+
contact_id: string | null;
12+
last_sent_at: string | null;
13+
snoozed_until: string | null;
14+
created_at: string;
15+
contact_name: string | null;
16+
}
17+
18+
export interface RemindersWithContactPublic {
19+
data: ReminderWithContactPublic[];
20+
count: number;
21+
}

0 commit comments

Comments
 (0)