/
article.go
82 lines (70 loc) · 1.85 KB
/
article.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package controllers
import (
"github.com/astaxie/beego"
"strconv"
"github.com/RayFantasyStudio/blog/models"
"github.com/RayFantasyStudio/blog/utils"
)
type ArticleController struct {
beego.Controller
}
type articleItem struct{
article models.Article
tag []models.Tag
authorName string
}
func (c *ArticleController) Get() {
initHeaderFooterData(&c.Controller, owner + "的Blog")
var article_count int
op := c.Input().Get("op")
if op == "del" {
id, err := strconv.ParseInt(c.Input().Get("id"), 10, 64)
if err != nil {
beego.Error(err)
}
err = models.DeleteArticle(id)
if err != nil {
beego.Error(err)
}
c.Redirect("/",302)
}
page,err := c.GetInt("page")
if err != nil {
beego.Error(err)
}
order_by := c.GetString("order")
desc,err := c.GetBool("desc")
if err != nil {
beego.Error(err)
}
uid,err := c.GetInt64("by_uid")
if err != nil {
beego.Error(err)
}
category := c.GetString("cate")
c.Data["Category_tmp"] = category
c.Data["Order_tmp"] = order_by
c.Data["User_tmp"] = uid
c.Data["Desc_tmp"] = desc
beego.Info("the page is ",page,"the order is ",order_by," ","desc = ",desc,"cate = ",category)
var articles []*models.Article
articles, article_count,err = models.GetArticles(order_by,category,"",uid,desc,page)
if err != nil {
beego.Error(err)
}
beego.Info("the result of get articles = ",article_count)
c.Data["Articles"] = articles
c.Data["Paginator"] = utils.NewPaginator("/article?page=%d&order=created&desc=true&by_uid="+strconv.FormatInt(uid,10), page, models.ArticlePerPageLimit, int64(article_count))
author_name := make([]string,len(articles))
for index,x := range articles{
author_name[index],err = models.GetUserNameById(x.Author.Id)
if err != nil {
beego.Error(err)
}
}
beego.Info(author_name)
c.Data["Authors"] = author_name
c.TplName = "article.tpl"
}
func (c *ArticleController) Post() {
}