Esempio n. 1
0
//博客具体信息
func (c App) BlogInfor(id string, rcnt int) revel.Result {

	dao, err := models.NewDao()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}

	defer dao.Close()
	//根据ID查找博文
	blog := dao.FindBlogById(id)
	if blog.ReadCnt == rcnt {
		blog.ReadCnt = rcnt + 1
		dao.UpdateBlogById(id, blog)
	}

	comments := dao.FindCommentsByBlogId(blog.Id)
	if len(comments) == 0 && blog.CommentCnt != 0 {
		blog.CommentCnt = 0
		dao.UpdateBlogById(id, blog)
	} else if len(comments) != blog.CommentCnt {
		blog.CommentCnt = len(comments)
		dao.UpdateBlogById(id, blog)
	}
	return c.Render(blog, rcnt, comments)
}
Esempio n. 2
0
//提交博文
func (c WBlog) Putup(blog *models.Blog) revel.Result {
	fmt.Println("提交博文.....")
	blog.Title = strings.TrimSpace(blog.Title)
	blog.Email = strings.TrimSpace(blog.Email)
	blog.Subject = strings.TrimSpace(blog.Subject)
	blog.Validate(c.Validation)

	//提交过程中出现异常的处理
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		fmt.Println(c.Validation)
		return c.Redirect(App.WBlog)
	}

	dao, err := models.NewDao()
	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)
}
Esempio n. 3
0
//提交留言
func (c WMessage) Putup(message *models.Message) revel.Result {
	message.Email = strings.TrimSpace(message.Email)
	message.Url = strings.TrimSpace(message.Url)
	message.Content = strings.TrimSpace(message.Content)
	message.QQ = strings.TrimSpace(message.QQ)

	message.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		c.Flash.Error("Errs:The email and the content should not be null,or the maxsize of email is 50.")
		return c.Redirect(App.Message)
	}

	dao, err := models.NewDao()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}

	defer dao.Close()
	err = dao.InsertMessage(message)
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	return c.Redirect(App.Message)
}
Esempio n. 4
0
func (c App) Message() revel.Result {
	messagefun := ACTIVE

	dao, err := models.NewDao()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	defer dao.Close()
	messages := dao.FindAllMessage()
	return c.Render(messagefun, messages)
}
Esempio n. 5
0
//主页
func (c App) Index() revel.Result {
	home := ACTIVE

	dao, err := models.NewDao()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}

	defer dao.Close()
	blogs := dao.FindBlogs()

	return c.Render(home, blogs)
}
Esempio n. 6
0
//归档功能
func (c App) History() revel.Result {
	historyfun := ACTIVE

	dao, err := models.NewDao()
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}
	defer dao.Close()
	dao.CreateAllHistory()
	historys := dao.FindHistory()
	for i, _ := range historys {
		historys[i].Blogs = dao.FindBlogsByYear(historys[i].Year)
	}

	return c.Render(historyfun, historys)
}
Esempio n. 7
0
//写评论
func (c WComment) Docomment(id string, rcnt int, comment *models.Comment) revel.Result {

	if len(id) == 0 {
		return c.Redirect(App.Index)
	}

	dao, err := models.NewDao()
	if err != nil {
		c.Response.Status = 500
		return c.Redirect(App.Index)
	}

	defer dao.Close()
	blog := dao.FindBlogById(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() {
		c.Validation.Keep()
		c.FlashParams()
		c.Flash.Error("Errs:The email and the content should not be null,or the maxsize of email is 50.")
		return c.Redirect("/bloginfor/%s/%d", id, rcnt)
	}

	err = dao.InsertComment(comment)
	if err != nil {
		c.Response.Status = 500
		return c.RenderError(err)
	}

	blog.CommentCnt++
	dao.UpdateBlogById(id, blog)
	return c.Redirect("/bloginfor/%s/%d", id, rcnt)
}