fix query user by id
This commit is contained in:
@@ -29,6 +29,22 @@ func (h *Handler) GetCurrentUser(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, &u)
|
||||
}
|
||||
|
||||
func (h *Handler) GetUser(c echo.Context) error {
|
||||
var user model.User
|
||||
id := c.Param("id")
|
||||
if id == "" {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
tx := h.DB.Preload("Position").Where("id = ?", id).Find(user)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusNotFound)
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
func (h *Handler) GetUsers(c echo.Context) error {
|
||||
var users []model.User
|
||||
|
||||
@@ -38,16 +54,11 @@ func (h *Handler) GetUsers(c echo.Context) error {
|
||||
|
||||
tx := h.DB.Limit(limit).Offset(offset)
|
||||
|
||||
utils.ApplyIdFilter(c, tx)
|
||||
utils.ApplySort(tx, sortCol, isDesc)
|
||||
utils.ApplyFilters(tx, filterCol, filterVal)
|
||||
|
||||
tx = tx.Preload("Position").Omit("Password").Find(&users)
|
||||
|
||||
if tx.RowsAffected == 1 {
|
||||
return c.JSON(http.StatusOK, users[0])
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user