Beispiel #1
0
// @Title delete
// @Description delete
// @Param	id	path string	true "the objectid you want to get"
// @Success 200
// @Failure 403 body is empty
// @router /delete/:id([0-9]+) [delete]
func (this *ManageController) Delete() {
	// convert the string value to an int
	articleId, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))

	o := orm.NewOrm()
	o.Using("default")

	article := models.Article{}

	// Check if the article exists first
	if exist := o.QueryTable(article.TableName()).Filter("Id", articleId).Exist(); exist {
		if _, err := o.Delete(&models.Article{Id: articleId}); err == nil {
			this.Data["json"] = "Record Deleted. "
		} else {
			this.Data["json"] = "Record couldn't be deleted. Reason: " + err.Error()
		}
	} else {
		this.Data["json"] = "Record Doesn't exist."
	}

	this.ServeJSON()
}