Skip to content

feat: sort users by username #7838

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 4 commits into from
Jun 6, 2023
Merged

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Jun 5, 2023

This PR modifies the default behavior of the /users API to return users sorted by username. Currently, they are sorted by creation date (not sure why?).

Currently (not sorted):

Screenshot 2023-06-02 at 12 13 29

@mtojek mtojek self-assigned this Jun 5, 2023
@mtojek mtojek requested a review from mafredri June 5, 2023 14:10
@mtojek mtojek marked this pull request as ready for review June 5, 2023 14:10
return a.ID.String() < b.ID.String()
}
return a.CreatedAt.Before(b.CreatedAt)
return sort.StringsAreSorted([]string{a.Username, b.Username})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This is essentially just a a.Username < b.Username comparison, could be simplified.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return users[i].ID.String() < users[j].ID.String()
}
return users[i].CreatedAt.Before(users[j].CreatedAt)
return sort.StringsAreSorted([]string{users[i].Username, users[j].Username})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, users[i].Username < users[j].Username or sort.Strings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@mtojek mtojek merged commit 93378da into coder:main Jun 6, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants