Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf75c74

Browse files
committed
UpdateUserNotificationPreferences
Signed-off-by: Danny Kopping <danny@coder.com>
1 parenteff74a2 commitaf75c74

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

‎coderd/database/dbmem/dbmem.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func New() database.Store {
6565
files:make([]database.File,0),
6666
gitSSHKey:make([]database.GitSSHKey,0),
6767
notificationMessages:make([]database.NotificationMessage,0),
68+
notificationPreferences:make([]database.NotificationPreference,0),
6869
parameterSchemas:make([]database.ParameterSchema,0),
6970
provisionerDaemons:make([]database.ProvisionerDaemon,0),
7071
workspaceAgents:make([]database.WorkspaceAgent,0),
@@ -8123,41 +8124,51 @@ func (q *FakeQuerier) UpdateUserLoginType(_ context.Context, arg database.Update
81238124
return database.User{},sql.ErrNoRows
81248125
}
81258126

8126-
func (q*FakeQuerier)UpdateUserNotificationPreferences(ctx context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
8127+
func (q*FakeQuerier)UpdateUserNotificationPreferences(_ context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
81278128
err:=validateDatabaseType(arg)
81288129
iferr!=nil {
8129-
return0,err
8130+
return-1,err
81308131
}
81318132

81328133
q.mutex.Lock()
81338134
deferq.mutex.Unlock()
81348135

81358136
varupsertedint64
8136-
fori,templateID:=rangearg.NotificationTemplateIds {
8137+
fori:=rangearg.NotificationTemplateIds {
81378138
var (
8138-
found*database.NotificationPreference
8139-
disabled=arg.Disableds[i]
8139+
foundbool
8140+
templateID=arg.NotificationTemplateIds[i]
8141+
disabled=arg.Disableds[i]
81408142
)
81418143

8142-
for_,np:=rangeq.notificationPreferences {
8143-
ifnp.UserID!=arg.UserID&&np.NotificationTemplateID!=templateID {
8144+
forj,np:=rangeq.notificationPreferences {
8145+
ifnp.UserID!=arg.UserID {
8146+
continue
8147+
}
8148+
8149+
ifnp.NotificationTemplateID!=templateID {
81448150
continue
81458151
}
81468152

8147-
found=&np
8153+
np.Disabled=disabled
8154+
np.UpdatedAt=time.Now()
8155+
q.notificationPreferences[j]=np
8156+
8157+
upserted++
8158+
found=true
8159+
break
81488160
}
81498161

8150-
iffound!=nil {
8151-
found.Disabled=disabled
8152-
found.UpdatedAt=time.Now()
8153-
}else {
8154-
q.notificationPreferences=append(q.notificationPreferences, database.NotificationPreference{
8162+
if!found {
8163+
np:= database.NotificationPreference{
81558164
Disabled:disabled,
81568165
UserID:arg.UserID,
81578166
NotificationTemplateID:templateID,
81588167
CreatedAt:time.Now(),
81598168
UpdatedAt:time.Now(),
8160-
})
8169+
}
8170+
q.notificationPreferences=append(q.notificationPreferences,np)
8171+
upserted++
81618172
}
81628173
}
81638174

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp