示例#1
0
文件: default.go 项目: Vin-Yang/inote
func (this *MainController) DeletePost() {
	res := &ResEntity{}
	id, err := strconv.Atoi(this.Ctx.Input.Param(":id"))
	if err != nil {
		beego.Error(err)
	}
	post := models.Post{Id: int64(id)}
	err = post.Delete()
	if err != nil {
		beego.Error("delete post error:", err.Error())
		res.Success = false
		res.Msg = "删除失败"
		this.Data["json"] = res
		this.ServeJson()
		return
	}

	o := orm.NewOrm()
	o.Raw("DELETE FROM message WHERE post_id=?", id).Exec()

	res.Success = true
	res.Msg = "删除成功"
	this.Data["json"] = res
	this.ServeJson()
	return
}
示例#2
0
文件: default.go 项目: Vin-Yang/inote
func (this *PostController) OnePost() {
	res := &ResEntity{}
	id, err := strconv.Atoi(this.Ctx.Input.Param(":id"))
	if err != nil {
		beego.Error(err)
	}
	qsPost := new(models.Post)
	post := models.Post{Id: int64(id)}
	if id == 0 {
		// last post
		qsPost.Query().OrderBy("-PublishAt").Limit(1).One(&post)
	} else {
		qsPost.Query().RelatedSel().Filter("id", id).One(&post)
	}

	/*if post == nil {
	    res.Success = false
	    res.Msg = "还没有内容"
	    this.Data["json"] = res
	    this.ServeJson()
	    return
	}*/
	messages := []models.Message{}
	qsMessages := new(models.Message)
	qsMessages.Query().Filter("PostId", post.Id).OrderBy("-CreatedAt").All(&messages)
	resPost := &ResPost{
		Post:     &post,
		Messages: &messages,
	}
	res.Success = true
	res.Data = resPost
	this.Data["json"] = res
	this.ServeJson()
	return
}
示例#3
0
文件: default.go 项目: Vin-Yang/inote
func (this *PostController) Posts() {
	posts := []models.Post{}
	qsPost := new(models.Post)
	qsPost.Query().OrderBy("-PublishAt").All(&posts)
	this.Data["json"] = posts
	this.ServeJson()
	return
}