-
Notifications
You must be signed in to change notification settings - Fork 574
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
feat: add count to get users endpoint #5016
Conversation
@coadler would this work? I will go further with this if there aren't any immediate concern. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coadler pls review. I'm pretty packed today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments but it looks good and it's working for me!
// GetUsers does not return ErrNoRows because it uses a window function to get the count. | ||
// So we need to check if the userRows is empty and return an empty array if so. | ||
if len(userRows) == 0 { | ||
httpapi.Write(ctx, rw, http.StatusOK, codersdk.GetUsersResponse{ | ||
Users: []codersdk.User{}, | ||
Count: 0, | ||
}) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it ever could return that error anyways since it returns an array, and only :one
queries will error. I think this simplifies the code below though, which is nice.
What this changes:
GET /api/v2/users/count
endpoint and removes usage from the dashboardcount
field to theGET /api/v2/users
responseThis will ideally be the template for paginated queries moving forward.