Library/routes/api/v1/users_list.go

29 lines
509 B
Go
Raw Normal View History

2018-01-23 11:37:13 +00:00
package v1
import (
"net/http"
2018-03-05 11:53:12 +00:00
"git.kolaente.de/konrad/Library/models"
2018-01-23 11:59:48 +00:00
"github.com/labstack/echo"
2018-01-23 11:37:13 +00:00
)
2018-01-23 12:00:32 +00:00
// UsersList lists all users
2018-01-23 11:37:13 +00:00
func UsersList(c echo.Context) error {
// Check if the user is admin
if !models.IsAdmin(c) {
return echo.ErrUnauthorized
}
// Prepare the searchterm
search := c.QueryParam("s")
list, err := models.ListUsers(search)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting users."})
}
return c.JSON(http.StatusOK, list)
2018-01-23 11:59:48 +00:00
}