aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/grils/grils.go4
-rw-r--r--modules/tags/tags.go24
2 files changed, 24 insertions, 4 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 0df93a0..5d548e6 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -153,6 +153,10 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
153} 153}
154 154
155func (m *GrilsModule) FromIDs(ids []int) ([]*Gril, error) { 155func (m *GrilsModule) FromIDs(ids []int) ([]*Gril, error) {
156 if len(ids) == 0 {
157 return make([]*Gril, 0), nil
158 }
159
156 idList := "(" 160 idList := "("
157 first := true 161 first := true
158 for _, v := range ids { 162 for _, v := range ids {
diff --git a/modules/tags/tags.go b/modules/tags/tags.go
index 9412e24..aca1b44 100644
--- a/modules/tags/tags.go
+++ b/modules/tags/tags.go
@@ -3,6 +3,7 @@ package tags
3import ( 3import (
4 "log" 4 "log"
5 "net/http" 5 "net/http"
6 "strconv"
6 7
7 "fagott.pw/charakterin" 8 "fagott.pw/charakterin"
8 "fagott.pw/grilist/frontend" 9 "fagott.pw/grilist/frontend"
@@ -33,6 +34,7 @@ func (m *Module) Init(g *grilist.Grilist) {
33 } 34 }
34 m.grils = gm.(*grils.GrilsModule) 35 m.grils = gm.(*grils.GrilsModule)
35 m.g.Router.GET("/tag/:tag", m.viewTag) 36 m.g.Router.GET("/tag/:tag", m.viewTag)
37 m.g.Router.GET("/tag/:tag/:page", m.viewTagPage)
36} 38}
37 39
38func (m *Module) Interface() interface{} { 40func (m *Module) Interface() interface{} {
@@ -44,21 +46,35 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar
44} 46}
45 47
46func (m *Module) viewTag(w http.ResponseWriter, r *http.Request, p httprouter.Params) { 48func (m *Module) viewTag(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
49 p = append(p, httprouter.Param{
50 Key: "page",
51 Value: "1",
52 })
53 m.viewTagPage(w, r, p)
54}
55
56func (m *Module) viewTagPage(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
47 user, _ := m.g.Charakterin.GetUserFromRequest(r) 57 user, _ := m.g.Charakterin.GetUserFromRequest(r)
48 tag := p.ByName("tag") 58 tag := p.ByName("tag")
49 var tagID int 59 var tagID int
50 row := m.g.DB.QueryRow("SELECT id FROM grilist.tags WHERE name = $1;", tag) 60 row := m.g.DB.QueryRow("SELECT id FROM grilist.tags WHERE name = $1;", tag)
51 if err := row.Scan(&tagID); err != nil { 61 if err := row.Scan(&tagID); err != nil {
52 log.Println(err) 62 log.Println("error getting tag id", err)
53 http.Redirect(w, r, "/", 302) 63 http.Redirect(w, r, "/", 302)
54 return 64 return
55 } 65 }
66
67 pageNumber, err := strconv.Atoi(p.ByName("page"))
68 if err != nil || pageNumber < 1 {
69 pageNumber = 1
70 }
71
56 idList := make([]int, 0) 72 idList := make([]int, 0)
57 rows, err := m.g.DB.Query( 73 rows, err := m.g.DB.Query(
58 "SELECT gril_id FROM grilist.grils_tags WHERE tag_id = $1", 74 "SELECT gril_id FROM grilist.grils_tags WHERE tag_id = $1 LIMIT 12 OFFSET $2",
59 tagID) 75 tagID, (pageNumber-1)*12)
60 if err != nil { 76 if err != nil {
61 log.Println(err) 77 log.Println("error getting idList", err)
62 http.Redirect(w, r, "/", 302) 78 http.Redirect(w, r, "/", 302)
63 return 79 return
64 } 80 }