示例#1
0
func (this *ManageController) Get() {
	wp := models.NewWebPage("博客")
	wp.IncrViewCount()

	// this.Data["OneBlog"] = ms.ToMap()

	s := this.Ctx.Input.Param(":key")
	if _, err := strconv.Atoi(s); err != nil {
		this.checkError()
		return
	}
	b, _ := models.GetBlogById(1)
	if nil == b.ReadBlogByID(s) {
		this.Data["ArticleTitle"] = b.Title
		this.Data["ArticleContent"] = b.Content

	} else {
		this.checkError()
		return
	}
	this.Data["PageTitle"] = wp.GetPageTitle()
	this.Data["ImgHost"] = wp.GetImgHost()
	this.Data["StaticHost"] = wp.GetStaticHost()

	this.TplNames = "manage.tpl"
}
示例#2
0
// @router /v1/blog::key([0-9]+).html [get]
func (this *BlogController) ShowBlog() {

	skey := this.Ctx.Input.Param(":key")
	key, err := strconv.Atoi(skey)
	if err != nil {
		this.Ctx.WriteString("Error")
		return
	}
	blog, err := models.GetBlogById(int64(key))
	if err != nil {
		this.Ctx.WriteString("Error")
		return
	}
	this.Data["Article"] = blog
	this.TplNames = "blog.tpl"
}
示例#3
0
func (this *BlogController) Post() {
	log.Debug("Post oKKKKKKKK")
	code, _ := this.GetInt32("code")
	switch code {
	case 1:
		id, err := this.GetInt64("id")
		if err != nil {
			this.Ctx.WriteString(`{"code":-2,"data":"Get err id "}`)
			break
		}
		blog, err := models.GetBlogById(id)
		if err != nil {
			this.Ctx.WriteString(`{"code":-3,"data":"Get err blog "}`)
			break
		}
		log.Debug("...")
		this.Ctx.WriteString(`{"code":-3,"data":` + blog.ToJSON() + `}`)
		return
	default:
		this.Ctx.WriteString(`{"code":-1,"data":"Crying"}`)
	}
}
示例#4
0
func TestBlog(t *testing.T) {
	models.RegistDB()
	Convey("should be test Blog", t, func() {
		blog := &models.Blog{
			Title:   "Test Blog",
			Summary: "Test Blog content ",
			Content: "something test",
		}
		Convey("`blog` should not be nil", func() {
			So(blog, ShouldNotBeNil)
		})
		Convey("insert blog to database", func() {
			e := blog.Insert()
			So(e, ShouldEqual, nil)
		})
		Convey("update blog to database", func() {
			blog.Insert()
			blog.Title = "Test Blog(new)"
			blog.Status = -1
			e := blog.Update()
			So(e, ShouldEqual, nil)
		})
		Convey("get blog by id", func() {
			blog.Insert()
			newblog, e := models.GetBlogById(blog.Id)
			So(e, ShouldEqual, nil)
			So(newblog.Title, ShouldEqual, blog.Title)
		})
		Convey("write blog into db", func() {
			blog.AddTagName("tag1")
			blog.AddTagName("tag5")
			blog.AddTagName("tag3")
			e := blog.WriteToDB()
			So(e, ShouldEqual, nil)
		})
	})
}