Skip to content

Commit 72e6de4

Browse files
committed
fmt and lint
1 parent ef91969 commit 72e6de4

File tree

2 files changed

+96
-30
lines changed

2 files changed

+96
-30
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,16 +3588,17 @@ func (q *querier) RevokeDBCryptKey(ctx context.Context, activeKeyDigest string)
35883588
return q.db.RevokeDBCryptKey(ctx, activeKeyDigest)
35893589
}
35903590

3591-
func (q *querier) SetInboxNotificationAsRead(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
3592-
fetchFunc := func(ctx context.Context, id uuid.UUID) (database.NotificationsInbox, error) {
3593-
return q.db.GetInboxNotificationByID(ctx, id)
3594-
}
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+
// }
35953596

3596-
updateFunc := func(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
3597-
return q.db.SetInboxNotificationAsRead(ctx, arg)
3598-
}
3597+
// updateFunc := func(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
3598+
// return q.db.SetInboxNotificationAsRead(ctx, arg)
3599+
// }
35993600

3600-
return update(q.log, q.auth, fetchFunc, updateFunc)(ctx, arg)
3601+
// return update(q.log, q.auth, fetchFunc, updateFunc)(ctx, arg)
36013602
}
36023603

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

coderd/database/dbmem/dbmem.go

Lines changed: 87 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func New() database.Store {
6767
gitSSHKey: make([]database.GitSSHKey, 0),
6868
notificationMessages: make([]database.NotificationMessage, 0),
6969
notificationPreferences: make([]database.NotificationPreference, 0),
70+
notificationsInbox: make([]database.NotificationsInbox, 0),
7071
parameterSchemas: make([]database.ParameterSchema, 0),
7172
provisionerDaemons: make([]database.ProvisionerDaemon, 0),
7273
provisionerKeys: make([]database.ProvisionerKey, 0),
@@ -206,6 +207,7 @@ type data struct {
206207
notificationMessages []database.NotificationMessage
207208
notificationPreferences []database.NotificationPreference
208209
notificationReportGeneratorLogs []database.NotificationReportGeneratorLog
210+
notificationsInbox []database.NotificationsInbox
209211
oauth2ProviderApps []database.OAuth2ProviderApp
210212
oauth2ProviderAppSecrets []database.OAuth2ProviderAppSecret
211213
oauth2ProviderAppCodes []database.OAuth2ProviderAppCode
@@ -2363,17 +2365,32 @@ func (q *FakeQuerier) FavoriteWorkspace(_ context.Context, arg uuid.UUID) error
23632365
return nil
23642366
}
23652367

2366-
func (q *FakeQuerier) FetchInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
2367-
panic("not implemented")
2368+
func (q *FakeQuerier) FetchInboxNotificationsByUserID(_ context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
2369+
q.mutex.RLock()
2370+
defer q.mutex.RUnlock()
2371+
2372+
notifications := make([]database.NotificationsInbox, 0)
2373+
for _, notification := range q.notificationsInbox {
2374+
if notification.UserID == userID {
2375+
notifications = append(notifications, notification)
2376+
}
2377+
}
2378+
2379+
return notifications, nil
23682380
}
23692381

2370-
func (q *FakeQuerier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
2371-
err := validateDatabaseType(arg)
2372-
if err != nil {
2373-
return nil, err
2382+
func (q *FakeQuerier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID(_ context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
2383+
q.mutex.RLock()
2384+
defer q.mutex.RUnlock()
2385+
2386+
notifications := make([]database.NotificationsInbox, 0)
2387+
for _, notification := range q.notificationsInbox {
2388+
if notification.UserID == arg.UserID && notification.TemplateID == arg.TemplateID && notification.TargetID == arg.TargetID {
2389+
notifications = append(notifications, notification)
2390+
}
23742391
}
23752392

2376-
panic("not implemented")
2393+
return notifications, nil
23772394
}
23782395

23792396
func (q *FakeQuerier) FetchMemoryResourceMonitorsByAgentID(_ context.Context, agentID uuid.UUID) (database.WorkspaceAgentMemoryResourceMonitor, error) {
@@ -2418,17 +2435,32 @@ func (q *FakeQuerier) FetchNewMessageMetadata(_ context.Context, arg database.Fe
24182435
}, nil
24192436
}
24202437

2421-
func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
2422-
panic("not implemented")
2438+
func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserID(_ context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
2439+
q.mutex.RLock()
2440+
defer q.mutex.RUnlock()
2441+
2442+
notifications := make([]database.NotificationsInbox, 0)
2443+
for _, notification := range q.notificationsInbox {
2444+
if notification.UserID == userID && !notification.ReadAt.Valid {
2445+
notifications = append(notifications, notification)
2446+
}
2447+
}
2448+
2449+
return notifications, nil
24232450
}
24242451

2425-
func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
2426-
err := validateDatabaseType(arg)
2427-
if err != nil {
2428-
return nil, err
2452+
func (q *FakeQuerier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID(_ context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
2453+
q.mutex.RLock()
2454+
defer q.mutex.RUnlock()
2455+
2456+
notifications := make([]database.NotificationsInbox, 0)
2457+
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)
2460+
}
24292461
}
24302462

2431-
panic("not implemented")
2463+
return notifications, nil
24322464
}
24332465

24342466
func (q *FakeQuerier) FetchVolumesResourceMonitorsByAgentID(_ context.Context, agentID uuid.UUID) ([]database.WorkspaceAgentVolumeResourceMonitor, error) {
@@ -3358,8 +3390,17 @@ func (q *FakeQuerier) GetHungProvisionerJobs(_ context.Context, hungSince time.T
33583390
return hungJobs, nil
33593391
}
33603392

3361-
func (q *FakeQuerier) GetInboxNotificationByID(ctx context.Context, id uuid.UUID) (database.NotificationsInbox, error) {
3362-
panic("not implemented")
3393+
func (q *FakeQuerier) GetInboxNotificationByID(_ context.Context, id uuid.UUID) (database.NotificationsInbox, error) {
3394+
q.mutex.RLock()
3395+
defer q.mutex.RUnlock()
3396+
3397+
for _, notification := range q.notificationsInbox {
3398+
if notification.ID == id {
3399+
return notification, nil
3400+
}
3401+
}
3402+
3403+
return database.NotificationsInbox{}, sql.ErrNoRows
33633404
}
33643405

33653406
func (q *FakeQuerier) GetJFrogXrayScanByWorkspaceAndAgentID(_ context.Context, arg database.GetJFrogXrayScanByWorkspaceAndAgentIDParams) (database.JfrogXrayScan, error) {
@@ -7989,13 +8030,28 @@ func (q *FakeQuerier) InsertGroupMember(_ context.Context, arg database.InsertGr
79898030
return nil
79908031
}
79918032

7992-
func (q *FakeQuerier) InsertInboxNotification(ctx context.Context, arg database.InsertInboxNotificationParams) (database.NotificationsInbox, error) {
7993-
err := validateDatabaseType(arg)
7994-
if err != nil {
8033+
func (q *FakeQuerier) InsertInboxNotification(_ context.Context, arg database.InsertInboxNotificationParams) (database.NotificationsInbox, error) {
8034+
if err := validateDatabaseType(arg); err != nil {
79958035
return database.NotificationsInbox{}, err
79968036
}
79978037

7998-
panic("not implemented")
8038+
q.mutex.Lock()
8039+
defer q.mutex.Unlock()
8040+
8041+
notification := database.NotificationsInbox{
8042+
ID: arg.ID,
8043+
UserID: arg.UserID,
8044+
TemplateID: arg.TemplateID,
8045+
TargetID: arg.TargetID,
8046+
Title: arg.Title,
8047+
Content: arg.Content,
8048+
Icon: arg.Icon,
8049+
Actions: arg.Actions,
8050+
CreatedAt: time.Now(),
8051+
}
8052+
8053+
q.notificationsInbox = append(q.notificationsInbox, notification)
8054+
return notification, nil
79998055
}
80008056

80018057
func (q *FakeQuerier) InsertLicense(
@@ -9482,13 +9538,22 @@ func (q *FakeQuerier) RevokeDBCryptKey(_ context.Context, activeKeyDigest string
94829538
return sql.ErrNoRows
94839539
}
94849540

9485-
func (q *FakeQuerier) SetInboxNotificationAsRead(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
9541+
func (q *FakeQuerier) SetInboxNotificationAsRead(_ context.Context, arg database.SetInboxNotificationAsReadParams) error {
94869542
err := validateDatabaseType(arg)
94879543
if err != nil {
94889544
return err
94899545
}
94909546

9491-
panic("not implemented")
9547+
q.mutex.Lock()
9548+
defer q.mutex.Unlock()
9549+
9550+
for i := range q.notificationsInbox {
9551+
if q.notificationsInbox[i].ID == arg.ID {
9552+
q.notificationsInbox[i].ReadAt = arg.ReadAt
9553+
}
9554+
}
9555+
9556+
return nil
94929557
}
94939558

94949559
func (*FakeQuerier) TryAcquireLock(_ context.Context, _ int64) (bool, error) {

0 commit comments

Comments
 (0)