コード例 #1
0
ファイル: news.go プロジェクト: B88000005/GoOnlineJudge
//@URL: /admin/news/(\d+)/status/ @method: POST
func (nc *AdminNews) Status(Nid string) {
	restweb.Logger.Debug("Admin News Status")

	if nc.Privilege != config.PrivilegeAD {
		nc.Err400("Warning", "Error Privilege to change news status")
		return
	}

	nid, err := strconv.Atoi(Nid)
	if err != nil {
		nc.Error("args error", 400)
		return
	}

	newsModle := model.NewsModel{}
	one, err := newsModle.Detail(nid)
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}
	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	default:
		status = config.StatusAvailable
	}

	err = newsModle.Status(nid, status)
	if err != nil {
		nc.Error(err.Error(), 400)
		return
	}
	nc.Redirect("/admin/news", http.StatusFound)
}
コード例 #2
0
ファイル: news.go プロジェクト: netyum/GoOnlineJudge
func (this *NewsController) Status(w http.ResponseWriter, r *http.Request) {
	class.Logger.Debug("Admin News Status")
	if r.Method != "POST" {
		this.Err400(w, r, "Error", "Error Method to change news status")
		return
	}

	this.Init(w, r)

	if this.Privilege != config.PrivilegeAD {
		this.Err400(w, r, "Warning", "Error Privilege to change news status")
		return
	}

	args := this.ParseURL(r.URL.String())
	nid, err := strconv.Atoi(args["nid"])
	if err != nil {
		http.Error(w, "args error", 400)
		return
	}

	newsModle := model.NewsModel{}
	one, err := newsModle.Detail(nid)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	var status int
	switch one.Status {
	case config.StatusAvailable:
		status = config.StatusReverse
	default:
		status = config.StatusAvailable
	}

	err = newsModle.Status(nid, status)
	if err != nil {
		http.Error(w, err.Error(), 400)
		return
	}
	http.Redirect(w, r, "/admin/news?list", http.StatusFound)
}