add new methods and update current
This commit is contained in:
@@ -92,21 +92,33 @@ func (h *Handler) GetUsers(c echo.Context) error {
|
||||
func (h *Handler) UpdateUser(c echo.Context) (err error) {
|
||||
var user = new(model.User)
|
||||
var apiUser = new(model.APIUser)
|
||||
tx := h.DB
|
||||
|
||||
id := c.Param("id")
|
||||
tx = tx.Find(&user, id)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusNotFound)
|
||||
}
|
||||
|
||||
if err = c.Bind(apiUser); err != nil {
|
||||
return c.NoContent(http.StatusBadRequest)
|
||||
}
|
||||
|
||||
user.FirstName = apiUser.FirstName
|
||||
user.LastName = apiUser.LastName
|
||||
id := c.Param("id")
|
||||
tx := h.DB.Find(&user, id)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusNotFound)
|
||||
}
|
||||
|
||||
if apiUser.FirstName != "" {
|
||||
user.FirstName = apiUser.FirstName
|
||||
}
|
||||
if apiUser.LastName != "" {
|
||||
user.LastName = apiUser.LastName
|
||||
}
|
||||
if apiUser.PositionID.ID() != 0 {
|
||||
user.PositionID = apiUser.PositionID
|
||||
}
|
||||
if apiUser.Role != "" {
|
||||
user.Role = apiUser.Role
|
||||
}
|
||||
if apiUser.Password != "" {
|
||||
user.Password = fmt.Sprintf("%x", sha256.Sum256([]byte(apiUser.Password)))
|
||||
}
|
||||
|
||||
tx = h.DB.Save(&user)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user