-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread.go
54 lines (50 loc) · 1.25 KB
/
thread.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
package main
import (
"fmt"
"github.com/nvcnvn/glog/dbctx"
"labix.org/v2/mgo/bson"
)
func NewThread(c *controller) {
data := c.ViewData("New Blog")
CatLst, err := c.db.GetAllCategory()
if err != nil {
fmt.Println("thread: getting cat issue ", err)
}
data["CatLst"] = CatLst
c.View("newthread_form.tmpl", data)
}
func NewThread2(c *controller) {
// cat := dbctx.Category{}
// cat.Name = "test cat"
// c.Print(c.db.SaveCategory(&cat))
thr := dbctx.Thread{}
if idStr := c.Post("CatId", false); bson.IsObjectIdHex(idStr) {
thr.CatId = bson.ObjectIdHex(idStr)
} else {
c.View("newthread_error.tmpl", "")
return
}
thr.Content = c.Post("Content", true)
thr.Tags = []string{"test", "demo"}
thr.Description = c.Post("Item.Description", true)
thr.Title = c.Post("Item.Title", true)
if err := c.db.SaveThread(&thr); err != nil {
c.View("newthread_error.tmpl", err.Error())
}
c.Redirect("/thread?id="+thr.GetId().Encode(), 303)
}
func ViewThread(c *controller) {
idStr := c.Get("id", false)
if !bson.IsObjectIdHex(idStr) {
c.Print("Not found")
return
}
id := bson.ObjectIdHex(idStr)
thr, err := c.db.GetThread(id)
if err != nil {
c.Print("Not found")
}
data := c.ViewData("View thread")
data["Thread"] = thr
c.View("thread_view.tmpl", data)
}