vikunja-api/routes/api/v1/user_show.go

42 lines
944 B
Go
Raw Normal View History

2018-06-10 11:11:41 +02:00
package v1
import (
2018-07-25 16:24:46 +02:00
"code.vikunja.io/api/models"
2018-06-10 11:11:41 +02:00
"github.com/labstack/echo"
"net/http"
"strconv"
)
// UserShow gets all informations about a user
func UserShow(c echo.Context) error {
// TODO: only allow users to show itself/with privacy options
user := c.Param("id")
if user == "" {
return c.JSON(http.StatusBadRequest, models.Message{"User ID cannot be empty."})
}
// Make int
userID, err := strconv.ParseInt(user, 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, models.Message{"User ID is invalid."})
}
// Get User Infos
2018-08-30 19:14:02 +02:00
userInfos, err := models.GetUserByID(userID)
2018-06-10 11:11:41 +02:00
if err != nil {
2018-08-30 19:14:02 +02:00
if models.IsErrUserDoesNotExist(err) {
return c.JSON(http.StatusNotFound, models.Message{"The user does not exist."})
}
2018-06-10 11:11:41 +02:00
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
}
// Obfucate his password
userInfos.Password = ""
return c.JSON(http.StatusOK, userInfos)
}