feat: add GET /api/v2/users (#1028)

This commit is contained in:
Bruno Quaresma
2022-04-18 12:19:47 -05:00
committed by GitHub
parent af672803a2
commit 1df750bf1a
8 changed files with 102 additions and 0 deletions

View File

@ -23,6 +23,25 @@ import (
"github.com/coder/coder/cryptorand"
)
// Lists all the users
func (api *api) users(rw http.ResponseWriter, r *http.Request) {
users, err := api.Database.GetUsers(r.Context())
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("get users: %s", err.Error()),
})
return
}
var res []codersdk.User
for _, user := range users {
res = append(res, convertUser(user))
}
httpapi.Write(rw, http.StatusOK, res)
}
// Returns whether the initial user has been created or not.
func (api *api) firstUser(rw http.ResponseWriter, r *http.Request) {
userCount, err := api.Database.GetUserCount(r.Context())