Skip to content

feat(coderd): add mark-all-as-read endpoint for inbox notifications #16976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix 204
  • Loading branch information
defelmnq committed Mar 19, 2025
commit deff124bf1a926a24af221ac6fb1b4d6d17e32a9
3 changes: 1 addition & 2 deletions coderd/inboxnotifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,8 @@ func TestInboxNotifications_MarkAllAsRead(t *testing.T) {
require.Equal(t, 20, notifs.UnreadCount)
require.Len(t, notifs.Notifications, 20)

resp, err := client.MarkAllInboxNotificationsAsRead(ctx)
err = client.MarkAllInboxNotificationsAsRead(ctx)
require.NoError(t, err)
require.Zero(t, resp.UnreadCount)

notifs, err = client.ListInboxNotifications(ctx, codersdk.ListInboxNotificationsRequest{})
require.NoError(t, err)
Expand Down
11 changes: 5 additions & 6 deletions codersdk/inboxnotification.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,20 @@ type MarkAllInboxNotificationsAsReadResponse struct {
UnreadCount int `json:"unread_count"`
}

func (c *Client) MarkAllInboxNotificationsAsRead(ctx context.Context) (MarkAllInboxNotificationsAsReadResponse, error) {
func (c *Client) MarkAllInboxNotificationsAsRead(ctx context.Context) error {
res, err := c.Request(
ctx, http.MethodPut,
"/api/v2/notifications/inbox/mark-all-as-read",
nil,
)
if err != nil {
return MarkAllInboxNotificationsAsReadResponse{}, err
return err
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return MarkAllInboxNotificationsAsReadResponse{}, ReadBodyAsError(res)
if res.StatusCode != http.StatusNoContent {
return ReadBodyAsError(res)
}

var resp MarkAllInboxNotificationsAsReadResponse
return resp, json.NewDecoder(res.Body).Decode(&resp)
return nil
}
Loading