Notifications API: respond with updated notifications (#17064)
* notifications api: return updated notifications in response * make generate-swagger * openapi fix Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
ba2e600d17
commit
0ffad31b92
7 changed files with 37 additions and 23 deletions
|
@ -772,20 +772,20 @@ func setRepoNotificationStatusReadIfUnread(e Engine, userID, repoID int64) error
|
|||
}
|
||||
|
||||
// SetNotificationStatus change the notification status
|
||||
func SetNotificationStatus(notificationID int64, user *User, status NotificationStatus) error {
|
||||
func SetNotificationStatus(notificationID int64, user *User, status NotificationStatus) (*Notification, error) {
|
||||
notification, err := getNotificationByID(x, notificationID)
|
||||
if err != nil {
|
||||
return err
|
||||
return notification, err
|
||||
}
|
||||
|
||||
if notification.UserID != user.ID {
|
||||
return fmt.Errorf("Can't change notification of another user: %d, %d", notification.UserID, user.ID)
|
||||
return nil, fmt.Errorf("Can't change notification of another user: %d, %d", notification.UserID, user.ID)
|
||||
}
|
||||
|
||||
notification.Status = status
|
||||
|
||||
_, err = x.ID(notificationID).Update(notification)
|
||||
return err
|
||||
return notification, err
|
||||
}
|
||||
|
||||
// GetNotificationByID return notification by ID
|
||||
|
|
|
@ -76,12 +76,15 @@ func TestSetNotificationStatus(t *testing.T) {
|
|||
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
notf := AssertExistsAndLoadBean(t,
|
||||
&Notification{UserID: user.ID, Status: NotificationStatusRead}).(*Notification)
|
||||
assert.NoError(t, SetNotificationStatus(notf.ID, user, NotificationStatusPinned))
|
||||
_, err := SetNotificationStatus(notf.ID, user, NotificationStatusPinned)
|
||||
assert.NoError(t, err)
|
||||
AssertExistsAndLoadBean(t,
|
||||
&Notification{ID: notf.ID, Status: NotificationStatusPinned})
|
||||
|
||||
assert.Error(t, SetNotificationStatus(1, user, NotificationStatusRead))
|
||||
assert.Error(t, SetNotificationStatus(NonexistentID, user, NotificationStatusRead))
|
||||
_, err = SetNotificationStatus(1, user, NotificationStatusRead)
|
||||
assert.Error(t, err)
|
||||
_, err = SetNotificationStatus(NonexistentID, user, NotificationStatusRead)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestUpdateNotificationStatuses(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue