示例#1
0
文件: app.go 项目: caiya/iBlog
func (c App) Index() revel.Result {
	dao, err := modules.Conn()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	defer dao.Close()
	blogs := dao.FindBlogs()
	return c.Render(blogs)
}
示例#2
0
文件: app.go 项目: caiya/iBlog
func (c App) BlogInfo(id string, rcnt int) revel.Result {
	dao, err := modules.Conn()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	defer dao.Close()
	blog := dao.GetBlogFromId(id)
	if blog.ReadCnt == rcnt {
		blog.ReadCnt = rcnt + 1
		dao.UpdateBlogById(id, blog)
	}
	return c.Render(blog, rcnt)
}
示例#3
0
文件: comment.go 项目: caiya/iBlog
//保存回复
func (c Comment) Save(id string, rcnt int, comment *modules.Comment) revel.Result {
	if len(id) == 0 {
		return c.Redirect(App.Index())
	}
	dao, err := modules.Conn()
	if err != nil { //如果报错
		c.Response.Status = 500
		return c.Redirect(App.Index())
	}
	defer dao.Close()
	blog := dao.GetBlogFromId(id)
	if blog == nil {
		return c.Redirect(App.Index())
	}
	comment.BlogId = blog.Id_
	comment.Content = strings.TrimSpace(comment.Content)
	comment.Email = strings.TrimSpace(comment.Email)
	comment.Validate(c.Validation)
	if c.Validation.HasErrors() {

	}

}
示例#4
0
文件: blog.go 项目: caiya/iBlog
func (c WBlog) Save(blog *modules.Blog) revel.Result {
	blog.Title = strings.TrimSpace(blog.Title)
	blog.Content = strings.TrimSpace(blog.Content)
	blog.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		fmt.Println(c.Validation)
		return c.Redirect(App.Blog)
	}
	dao, err := modules.Conn()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	defer dao.Close()
	err = dao.CreateBlog(blog)
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	return c.Redirect(App.Index)
}