forked from ZJGSU-Open-Source/GoOnlineJudge
/
news.go
60 lines (48 loc) · 1.17 KB
/
news.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
package controller
import (
"GoOnlineJudge/class"
"GoOnlineJudge/config"
"GoOnlineJudge/model"
"restweb"
"net/http"
"strconv"
)
//新闻控件
type NewsController struct {
class.Controller
} //@Controller
//列出所有新闻
//@URL: /news @method: GET
func (nc *NewsController) List() {
restweb.Logger.Debug("News List")
newsModel := model.NewsModel{}
newsList, err := newsModel.List(-1, -1)
if err != nil {
// http.Error(w, err.Error(), 500)
return
}
nc.Output["News"] = newsList
nc.Output["Title"] = "Welcome to ZJGSU Online Judge"
nc.Output["IsNews"] = true
nc.RenderTemplate("view/layout.tpl", "view/news_list.tpl")
}
//@URL: /news/(\d+) @method: GET
func (nc *NewsController) Detail(Nid string) {
nid, err := strconv.Atoi(Nid) //获取nid
if err != nil {
// http.Error(w, "args error", 400)
return
}
newsModel := model.NewsModel{}
one, err := newsModel.Detail(nid)
if err != nil {
http.Error(nc.W, err.Error(), 500)
}
nc.Output["Detail"] = one
if one.Status == config.StatusReverse {
nc.Err400("No such news", "No such news")
return
}
nc.Output["Title"] = "News Detail"
nc.RenderTemplate("view/layout.tpl", "view/news_detail.tpl")
}