vikunja-api/routes/api/v1/user_show.go
2018-09-17 16:25:05 +00:00

30 lines
836 B
Go

package v1
import (
"code.vikunja.io/api/models"
"github.com/labstack/echo"
"net/http"
)
// UserShow gets all information about a user
func UserShow(c echo.Context) error {
userInfos, err := models.GetCurrentUser(c)
if err != nil {
if models.IsErrUserDoesNotExist(err) {
return c.JSON(http.StatusNotFound, models.Message{"The user does not exist."})
}
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
}
user, err := models.GetUserByID(userInfos.ID)
if err != nil {
if models.IsErrUserDoesNotExist(err) {
return c.JSON(http.StatusNotFound, models.Message{"The user does not exist."})
}
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
}
// Obfuscate his password
user.Password = ""
return c.JSON(http.StatusOK, user)
}