// Rename a username of one user func (*UsersController) Rename(ctx *gin.Context) { var renameJSON renameUserJSON ctx.Bind(&renameJSON) var userToRename = models.User{} err := userToRename.FindByUsername(renameJSON.Username) if err != nil { AbortWithReturnError(ctx, http.StatusBadRequest, fmt.Errorf("user with username %s does not exist", renameJSON.Username)) return } err = userToRename.Rename(renameJSON.NewUsername) if err != nil { AbortWithReturnError(ctx, http.StatusBadRequest, fmt.Errorf("Rename %s user to %s failed", renameJSON.Username, renameJSON.NewUsername)) return } ctx.JSON(http.StatusCreated, "") }