コード例 #1
0
func viewAdminDeleteCommand(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	rid := vars["rid"]
	cid, _ := strconv.Atoi(vars["cid"])

	com, err := database.GetCommand(int64(cid))

	if err == nil {
		com.Delete()
	}

	uri := fmt.Sprintf("/admin/repository/%s", rid)
	http.Redirect(w, r, uri, 302)
}
コード例 #2
0
func viewAdminUpdateCommand(w http.ResponseWriter, r *http.Request) {
	template := "command/admin/update.html"
	ctx := make(responseContext)

	vars := mux.Vars(r)
	rid, _ := strconv.Atoi(vars["rid"])
	cid, _ := strconv.Atoi(vars["cid"])

	repo, err := database.GetRepositoryByID(int64(rid))

	if err != nil {
		render(w, r, "403.html", make(responseContext)) // TODO: create 500
		return
	}

	com, err := database.GetCommand(int64(cid))

	if err != nil {
		render(w, r, "403.html", make(responseContext)) // TODO: create 500
		return
	}

	ctx["repository"] = repo
	ctx["command"] = com
	ctx["kinds"] = []string{
		database.CommandKindBuild,
		database.CommandKindDeploy,
		database.CommandKindTest,
	}

	if r.Method == "POST" {
		err := commandAdminForm{}.update(r, com)

		if err == nil {
			ctx["message"] = "Update successful."
		} else {
			ctx["error"] = err.Error()
		}
	}

	render(w, r, template, ctx)
}