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

Commitf4818df

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

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),
@@ -8232,41 +8233,51 @@ func (q *FakeQuerier) UpdateUserLoginType(_ context.Context, arg database.Update
82328233
return database.User{},sql.ErrNoRows
82338234
}
82348235

8235-
func (q*FakeQuerier)UpdateUserNotificationPreferences(ctx context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
8236+
func (q*FakeQuerier)UpdateUserNotificationPreferences(_ context.Context,arg database.UpdateUserNotificationPreferencesParams) (int64,error) {
82368237
err:=validateDatabaseType(arg)
82378238
iferr!=nil {
8238-
return0,err
8239+
return-1,err
82398240
}
82408241

82418242
q.mutex.Lock()
82428243
deferq.mutex.Unlock()
82438244

82448245
varupsertedint64
8245-
fori,templateID:=rangearg.NotificationTemplateIds {
8246+
fori:=rangearg.NotificationTemplateIds {
82468247
var (
8247-
found*database.NotificationPreference
8248-
disabled=arg.Disableds[i]
8248+
foundbool
8249+
templateID=arg.NotificationTemplateIds[i]
8250+
disabled=arg.Disableds[i]
82498251
)
82508252

8251-
for_,np:=rangeq.notificationPreferences {
8252-
ifnp.UserID!=arg.UserID&&np.NotificationTemplateID!=templateID {
8253+
forj,np:=rangeq.notificationPreferences {
8254+
ifnp.UserID!=arg.UserID {
8255+
continue
8256+
}
8257+
8258+
ifnp.NotificationTemplateID!=templateID {
82538259
continue
82548260
}
82558261

8256-
found=&np
8262+
np.Disabled=disabled
8263+
np.UpdatedAt=time.Now()
8264+
q.notificationPreferences[j]=np
8265+
8266+
upserted++
8267+
found=true
8268+
break
82578269
}
82588270

8259-
iffound!=nil {
8260-
found.Disabled=disabled
8261-
found.UpdatedAt=time.Now()
8262-
}else {
8263-
q.notificationPreferences=append(q.notificationPreferences, database.NotificationPreference{
8271+
if!found {
8272+
np:= database.NotificationPreference{
82648273
Disabled:disabled,
82658274
UserID:arg.UserID,
82668275
NotificationTemplateID:templateID,
82678276
CreatedAt:time.Now(),
82688277
UpdatedAt:time.Now(),
8269-
})
8278+
}
8279+
q.notificationPreferences=append(q.notificationPreferences,np)
8280+
upserted++
82708281
}
82718282
}
82728283

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp