Example #1
0
func (this *ProblemBankDenyController) Get() {
	// get id
	id, err := this.GetInt("id")
	if nil != err || id < 0 {
		id = 0
	}

	s := this.Ctx.Input.Param(":id")
	pageParm, err := strconv.Atoi(s)
	if nil != err || pageParm < 0 {
		pageParm = 0
	} else {
		id = pageParm
	}

	if 0 == id {
		id = 1
	}

	// deny via id
	prob := models.ProblemBank{}
	err = prob.DenyProblem(id)

	if err != nil {
		this.Data["json"] = map[string]interface{}{
			"result": false,
			"msg":    "deny problem failed",
			"refer":  nil,
			"debug":  err,
		}
	} else {
		this.Data["json"] = map[string]interface{}{
			"result": true,
			"msg":    "problem deny success",
			"refer":  nil,
		}
	}

	this.ServeJson()
}
Example #2
0
// uri /api/problem/list/:page
func (this *ProblemListController) Get() {
	page, err := this.GetInt("page")
	if nil != err || page < 0 {
		page = 0
	}

	s := this.Ctx.Input.Param(":page")
	pageParm, err := strconv.Atoi(s)
	if nil != err || pageParm < 0 {
		pageParm = 0
	} else {
		page = pageParm
	}

	if 0 == page {
		page = 1
	}

	status := this.GetString("status")
	if len(status) <= 0 {
		status = "ok"
	}

	if status == "ok" {
		pro := models.Problem{}
		data, hasNext, totalPage, err := pro.ListProblem(page, 20, "")

		if err != nil {
			this.Data["json"] = map[string]interface{}{
				"result":     false,
				"msg":        "get list failing",
				"list":       nil,
				"has_next":   false,
				"total_page": 0,
				"refer":      nil,
			}
		} else {
			log.Blueln(data)

			this.Data["json"] = map[string]interface{}{
				"result":     true,
				"msg":        "get list success",
				"list":       data,
				"has_next":   hasNext,
				"total_page": totalPage,
				"refer":      nil,
			}
		}
	} else {
		if status != "audit" && status != "ok" && status != "deleted" {
			this.Data["json"] = map[string]interface{}{
				"result":     false,
				"msg":        "invalid status",
				"list":       nil,
				"has_next":   false,
				"total_page": 0,
				"refer":      nil,
			}
		} else {

			pro := models.ProblemBank{}
			data, hasNext, totalPage, err := pro.ListProblem(page, 20, status)

			if err != nil {
				this.Data["json"] = map[string]interface{}{
					"result":     false,
					"msg":        "get list failing",
					"list":       nil,
					"has_next":   false,
					"total_page": 0,
					"refer":      nil,
				}
			} else {
				log.Blueln(data)

				this.Data["json"] = map[string]interface{}{
					"result":     true,
					"msg":        "get list success",
					"list":       data,
					"has_next":   hasNext,
					"total_page": totalPage,
					"refer":      nil,
				}
			}
		}
	}

	this.ServeJson()
}