Skip to content

Commit fddf156

Browse files
committed
change queries to match targets
1 parent a7a88e0 commit fddf156

File tree

10 files changed

+123
-100
lines changed

10 files changed

+123
-100
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,8 +1421,8 @@ func (q *querier) FetchInboxNotificationsByUserID(ctx context.Context, userID uu
14211421
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchInboxNotificationsByUserID)(ctx, userID)
14221422
}
14231423

1424-
func (q *querier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
1425-
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID)(ctx, arg)
1424+
func (q *querier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargets(ctx context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetsParams) ([]database.NotificationsInbox, error) {
1425+
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchInboxNotificationsByUserIDAndTemplateIDAndTargets)(ctx, arg)
14261426
}
14271427

14281428
func (q *querier) FetchMemoryResourceMonitorsByAgentID(ctx context.Context, agentID uuid.UUID) (database.WorkspaceAgentMemoryResourceMonitor, error) {
@@ -1450,8 +1450,8 @@ func (q *querier) FetchUnreadInboxNotificationsByUserID(ctx context.Context, use
14501450
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchUnreadInboxNotificationsByUserID)(ctx, userID)
14511451
}
14521452

1453-
func (q *querier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
1454-
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID)(ctx, arg)
1453+
func (q *querier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargets(ctx context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetsParams) ([]database.NotificationsInbox, error) {
1454+
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargets)(ctx, arg)
14551455
}
14561456

14571457
func (q *querier) FetchVolumesResourceMonitorsByAgentID(ctx context.Context, agentID uuid.UUID) ([]database.WorkspaceAgentVolumeResourceMonitor, error) {
@@ -3588,17 +3588,12 @@ func (q *querier) RevokeDBCryptKey(ctx context.Context, activeKeyDigest string)
35883588
return q.db.RevokeDBCryptKey(ctx, activeKeyDigest)
35893589
}
35903590

3591-
func (*querier) SetInboxNotificationAsRead(_ context.Context, _ database.SetInboxNotificationAsReadParams) error {
3592-
panic("implement me")
3593-
// fetchFunc := func(ctx context.Context, id uuid.UUID) (database.NotificationsInbox, error) {
3594-
// return q.db.GetInboxNotificationByID(ctx, id)
3595-
// }
3596-
3597-
// updateFunc := func(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
3598-
// return q.db.SetInboxNotificationAsRead(ctx, arg)
3599-
// }
3591+
func (q *querier) SetInboxNotificationAsRead(ctx context.Context, args database.SetInboxNotificationAsReadParams) error {
3592+
fetchFunc := func(ctx context.Context, args database.SetInboxNotificationAsReadParams) (database.NotificationsInbox, error) {
3593+
return q.db.GetInboxNotificationByID(ctx, args.ID)
3594+
}
36003595

3601-
// return update(q.log, q.auth, fetchFunc, updateFunc)(ctx, arg)
3596+
return update(q.log, q.auth, fetchFunc, q.db.SetInboxNotificationAsRead)(ctx, args)
36023597
}
36033598

36043599
func (q *querier) TryAcquireLock(ctx context.Context, id int64) (bool, error) {

coderd/database/dbmem/dbmem.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,14 +2379,28 @@ func (q *FakeQuerier) FetchInboxNotificationsByUserID(_ context.Context, userID
23792379
return notifications, nil
23802380
}
23812381

2382-
func (q *FakeQuerier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID(_ context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
2382+
func (q *FakeQuerier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargets(_ context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetsParams) ([]database.NotificationsInbox, error) {
23832383
q.mutex.RLock()
23842384
defer q.mutex.RUnlock()
23852385

23862386
notifications := make([]database.NotificationsInbox, 0)
23872387
for _, notification := range q.notificationsInbox {
2388-
if notification.UserID == arg.UserID && notification.TemplateID == arg.TemplateID && notification.TargetID == arg.TargetID {
2389-
notifications = append(notifications, notification)
2388+
if notification.UserID == arg.UserID && notification.TemplateID == arg.TemplateID {
2389+
for _, target := range arg.Targets {
2390+
isFound := false
2391+
for _, insertedTarget := range notification.Targets {
2392+
if insertedTarget == target {
2393+
isFound = true
2394+
break
2395+
}
2396+
}
2397+
2398+
if !isFound {
2399+
continue
2400+
}
2401+
2402+
notifications = append(notifications, notification)
2403+
}
23902404
}
23912405
}
23922406

@@ -2449,14 +2463,28 @@ func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserID(_ context.Context, u
24492463
return notifications, nil
24502464
}
24512465

2452-
func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID(_ context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
2466+
func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargets(_ context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetsParams) ([]database.NotificationsInbox, error) {
24532467
q.mutex.RLock()
24542468
defer q.mutex.RUnlock()
24552469

24562470
notifications := make([]database.NotificationsInbox, 0)
24572471
for _, notification := range q.notificationsInbox {
2458-
if notification.UserID == arg.UserID && notification.TemplateID == arg.TemplateID && notification.TargetID == arg.TargetID && !notification.ReadAt.Valid {
2459-
notifications = append(notifications, notification)
2472+
if notification.UserID == arg.UserID && notification.TemplateID == arg.TemplateID && !notification.ReadAt.Valid {
2473+
for _, target := range arg.Targets {
2474+
isFound := false
2475+
for _, insertedTarget := range notification.Targets {
2476+
if insertedTarget == target {
2477+
isFound = true
2478+
break
2479+
}
2480+
}
2481+
2482+
if !isFound {
2483+
continue
2484+
}
2485+
2486+
notifications = append(notifications, notification)
2487+
}
24602488
}
24612489
}
24622490

@@ -8042,7 +8070,7 @@ func (q *FakeQuerier) InsertInboxNotification(_ context.Context, arg database.In
80428070
ID: arg.ID,
80438071
UserID: arg.UserID,
80448072
TemplateID: arg.TemplateID,
8045-
TargetID: arg.TargetID,
8073+
Targets: arg.Targets,
80468074
Title: arg.Title,
80478075
Content: arg.Content,
80488076
Icon: arg.Icon,

coderd/database/dbmetrics/querymetrics.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dump.sql

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000295_notifications_inbox.up.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CREATE TABLE notifications_inbox (
22
id UUID PRIMARY KEY,
33
user_id UUID NOT NULL,
44
template_id UUID NOT NULL,
5-
target_id UUID,
5+
targets UUID[],
66
title TEXT NOT NULL,
77
content TEXT NOT NULL,
88
icon TEXT NOT NULL,
@@ -12,4 +12,4 @@ CREATE TABLE notifications_inbox (
1212
);
1313

1414
CREATE INDEX idx_notifications_inbox_user_id_read_at ON notifications_inbox(user_id, read_at);
15-
CREATE INDEX idx_notifications_inbox_user_id_template_id_target_id ON notifications_inbox(user_id, template_id, target_id);
15+
CREATE INDEX idx_notifications_inbox_user_id_template_id_targets ON notifications_inbox(user_id, template_id, targets);

coderd/database/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy