Exemple #1
0
// post: /user/edit/1
func (uc *UserController) EditPost(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	var id int
	if id, err = parseId(ctx); err != nil {
		return
	}

	u := User{
		Id:       id,
		Location: ctx.FV("location"),
		Gender:   ctx.FV("gender"),
		Skills:   ctx.Request.Form["skill"],
	}
	if userRepo.Update(u) {
		return wk.Redirect(fmt.Sprintf("/user/view/%d", id), false), nil
	}
	return wk.View("user/edit.html"), nil
}
Exemple #2
0
// get/post: /user/add
func (uc *UserController) AddPost(ctx *wk.HttpContext) (result wk.HttpResult, err error) {
	id := 0
	if name := ctx.FV("name"); name == "" {
		ctx.ViewData["errmsg"] = "name is required"
	} else if name == "error" {
		ctx.ViewData["errmsg"] = "name is error"
	} else if userRepo.Exists(name) {
		ctx.ViewData["errmsg"] = "name exists"
	} else {
		u := User{
			Name:     ctx.FV("name"),
			Location: ctx.FV("location"),
			Gender:   ctx.FV("gender"),
			Skills:   ctx.Request.Form["skill"],
		}
		id = userRepo.Add(u)
	}

	if id <= 0 {
		ctx.ViewData["ctx"] = ctx
		return wk.View("user/add.html"), nil
	}
	return wk.Redirect(fmt.Sprintf("/user/view/%d", id), false), nil
}
Exemple #3
0
func TestRedirectResult(t *testing.T) {
	var result wk.HttpResult = wk.Redirect(`http://golanr.org`, true)
	t.Log("NotImplemented", result)
}