aboutsummaryrefslogtreecommitdiff
path: root/modules/grils/grils.go
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-25 20:37:02 (UTC)
committerjan <jan@ruken.pw>2015-12-25 20:37:02 (UTC)
commita31b9dbddf94dba7be23fcb67b169e1fe5ffc81b (patch)
tree7ac12a3bd3fd44460f8cc8e1286575c09ebc95e2 /modules/grils/grils.go
parent3a79416f963d1c72298ac4eaf842e3fedd323022 (diff)
simple list & gril view und parsing
Diffstat (limited to 'modules/grils/grils.go')
-rw-r--r--modules/grils/grils.go37
1 files changed, 32 insertions, 5 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 41783a7..047385e 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -3,12 +3,14 @@ package grils
3import ( 3import (
4 "fagott.pw/charakterin" 4 "fagott.pw/charakterin"
5 "fagott.pw/grilist/grilist" 5 "fagott.pw/grilist/grilist"
6 "github.com/julienschmidt/httprouter"
7 "net/http"
8 "strconv"
6 "time" 9 "time"
7) 10)
8 11
9type GrilsModule struct { 12type GrilsModule struct {
10 g *grilist.Grilist 13 g *grilist.Grilist
11 Test []int
12} 14}
13 15
14func (m *GrilsModule) Name() string { 16func (m *GrilsModule) Name() string {
@@ -17,11 +19,10 @@ func (m *GrilsModule) Name() string {
17 19
18func (m *GrilsModule) Init(g *grilist.Grilist) { 20func (m *GrilsModule) Init(g *grilist.Grilist) {
19 m.g = g 21 m.g = g
20 m.Test = append(m.Test, len(m.Test)+1) 22 m.g.Router.GET("/gril/:id", m.viewGril)
21} 23}
22 24
23func (m *GrilsModule) Interface() interface{} { 25func (m *GrilsModule) Interface() interface{} {
24 m.Test = append(m.Test, len(m.Test)+1)
25 return m 26 return m
26} 27}
27 28
@@ -29,7 +30,7 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
29 return []grilist.DashboardCategory{} 30 return []grilist.DashboardCategory{}
30} 31}
31 32
32func (m *GrilsModule) FromID(id int) *Gril { 33func (m *GrilsModule) FromID(id int) (*Gril, error) {
33 return &Gril{ 34 return &Gril{
34 ID: id, 35 ID: id,
35 KanjiName: "藤林 杏", 36 KanjiName: "藤林 杏",
@@ -38,7 +39,33 @@ func (m *GrilsModule) FromID(id int) *Gril {
38 Age: 17, 39 Age: 17,
39 Birthday: time.Now(), 40 Birthday: time.Now(),
40 Tags: []string{"tsundere", "hair intakes", "hair ribbon", "school uniform", "school crest"}, 41 Tags: []string{"tsundere", "hair intakes", "hair ribbon", "school uniform", "school crest"},
42 }, nil
43}
44
45func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
46 loggedIn := false
47 if user, _ := m.g.Charakterin.GetUserFromRequest(r); user != nil {
48 loggedIn = true
49 }
50 sid := p.ByName("id")
51
52 id, err := strconv.Atoi(sid)
53 if err != nil {
54 http.Redirect(w, r, "/", 302)
55 return
41 } 56 }
57
58 gril, err := m.FromID(id)
59 if err != nil {
60 http.Redirect(w, r, "/", 302)
61 return
62 }
63
64 data := make(map[string]interface{})
65 data["loggedIn"] = loggedIn
66 data["gril"] = gril
67
68 m.g.Renderer.RenderPage("gril", w, data)
42} 69}
43 70
44func New() *GrilsModule { 71func New() *GrilsModule {