aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--models/gril.go (renamed from modules/grils/gril.go)14
-rw-r--r--modules/grils/grils.go28
-rw-r--r--modules/lists/lists.go3
-rw-r--r--modules/search/search.go5
4 files changed, 24 insertions, 26 deletions
diff --git a/modules/grils/gril.go b/models/gril.go
index 7b54ab1..f0b8f8f 100644
--- a/modules/grils/gril.go
+++ b/models/gril.go
@@ -1,4 +1,4 @@
1package grils 1package models
2 2
3import ( 3import (
4 "database/sql" 4 "database/sql"
@@ -41,6 +41,7 @@ type Gril struct {
41 Series []series.Series 41 Series []series.Series
42} 42}
43 43
44// Der kram hier sollte eigentlich auch eher wo anders hin als ins Model, oder?!
44func (g *Gril) Slug() string { 45func (g *Gril) Slug() string {
45 if g.RomajiName == "" { 46 if g.RomajiName == "" {
46 return strconv.Itoa(g.ID) 47 return strconv.Itoa(g.ID)
@@ -51,13 +52,10 @@ func (g *Gril) Slug() string {
51 strings.Replace(g.RomajiName, " ", "", -1)) 52 strings.Replace(g.RomajiName, " ", "", -1))
52} 53}
53 54
54func ImagePath(id int, useThumbnail bool) string { 55// Das hier sollte auch irgendwo anders hin.
56func (g *Gril) ImagePath(useThumbnail bool) string {
55 if useThumbnail { 57 if useThumbnail {
56 return fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", id) 58 return fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", g.ID)
57 } 59 }
58 return fmt.Sprintf("http://img.grilist.moe/gril/full/%d.jpg", id) 60 return fmt.Sprintf("http://img.grilist.moe/gril/full/%d.jpg", g.ID)
59}
60
61func (g *Gril) ImagePath(prioritizeThumbnail bool) string {
62 return ImagePath(g.ID, prioritizeThumbnail)
63} 61}
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 4913e11..1b1bb5f 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -13,15 +13,11 @@ import (
13 "fagott.pw/grilist/cache" 13 "fagott.pw/grilist/cache"
14 "fagott.pw/grilist/frontend" 14 "fagott.pw/grilist/frontend"
15 "fagott.pw/grilist/grilist" 15 "fagott.pw/grilist/grilist"
16 "fagott.pw/grilist/models"
16 17
17 "github.com/julienschmidt/httprouter" 18 "github.com/julienschmidt/httprouter"
18) 19)
19 20
20type CachedGril struct {
21 Created time.Time
22 Gril *Gril
23}
24
25var ( 21var (
26 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`) 22 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`)
27 pgValueIdx int 23 pgValueIdx int
@@ -54,8 +50,8 @@ func (m *GrilsModule) Init(g *grilist.Grilist) {
54 m.c = cache.New() 50 m.c = cache.New()
55} 51}
56 52
57func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { 53func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*models.Gril, error) {
58 var grils []*Gril 54 var grils []*models.Gril
59 55
60 rows, err := m.g.DB.Query(fmt.Sprintf(`SELECT id, kanji_name, romaji_name, other_names, updated_at, age, birthday, tags FROM grilist.grils_flattened WHERE %s`, whereClause), params...) 56 rows, err := m.g.DB.Query(fmt.Sprintf(`SELECT id, kanji_name, romaji_name, other_names, updated_at, age, birthday, tags FROM grilist.grils_flattened WHERE %s`, whereClause), params...)
61 if err != nil { 57 if err != nil {
@@ -64,7 +60,7 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gr
64 60
65 defer rows.Close() 61 defer rows.Close()
66 for rows.Next() { 62 for rows.Next() {
67 gril := &Gril{} 63 gril := &models.Gril{}
68 var tags []byte 64 var tags []byte
69 var otherNames []byte 65 var otherNames []byte
70 err = rows.Scan(&gril.ID, &gril.KanjiName, &gril.RomajiName, &otherNames, &gril.UpdatedAt, &gril.Age, &gril.Birthday, &tags) 66 err = rows.Scan(&gril.ID, &gril.KanjiName, &gril.RomajiName, &otherNames, &gril.UpdatedAt, &gril.Age, &gril.Birthday, &tags)
@@ -83,7 +79,7 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gr
83 return grils, nil 79 return grils, nil
84} 80}
85 81
86func (m *GrilsModule) GetListsOfGril(gril *Gril) error { 82func (m *GrilsModule) GetListsOfGril(gril *models.Gril) error {
87 rows, err := m.g.DB.Query(`SELECT list_id FROM grilist.lists_grils WHERE gril_id = $1`, gril.ID) 83 rows, err := m.g.DB.Query(`SELECT list_id FROM grilist.lists_grils WHERE gril_id = $1`, gril.ID)
88 if err != nil { 84 if err != nil {
89 return err 85 return err
@@ -120,7 +116,7 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
120 } 116 }
121 117
122 for rows.Next() { 118 for rows.Next() {
123 var g Gril 119 var g models.Gril
124 if err := rows.Scan(&g.ID, &g.RomajiName, &g.KanjiName); err != nil { 120 if err := rows.Scan(&g.ID, &g.RomajiName, &g.KanjiName); err != nil {
125 log.Println(err) 121 log.Println(err)
126 continue 122 continue
@@ -143,12 +139,12 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
143 return categories 139 return categories
144} 140}
145 141
146func (m *GrilsModule) FromID(id int) (*Gril, error) { 142func (m *GrilsModule) FromID(id int) (*models.Gril, error) {
147 if g, ok := m.c.Get(id); ok { 143 if g, ok := m.c.Get(id); ok {
148 return g.(*Gril), nil 144 return g.(*models.Gril), nil
149 } 145 }
150 146
151 gril := &Gril{ 147 gril := &models.Gril{
152 ID: id, 148 ID: id,
153 } 149 }
154 t1 := time.Now() 150 t1 := time.Now()
@@ -219,9 +215,9 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
219 return gril, nil 215 return gril, nil
220} 216}
221 217
222func (m *GrilsModule) FromIDs(ids []int) ([]*Gril, error) { 218func (m *GrilsModule) FromIDs(ids []int) ([]*models.Gril, error) {
223 if len(ids) == 0 { 219 if len(ids) == 0 {
224 return make([]*Gril, 0), nil 220 return make([]*models.Gril, 0), nil
225 } 221 }
226 222
227 idList := "(" 223 idList := "("
@@ -274,7 +270,7 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou
274 } 270 }
275 271
276 defer rows.Close() 272 defer rows.Close()
277 var similar []*Gril 273 var similar []*models.Gril
278 for rows.Next() { 274 for rows.Next() {
279 var id int 275 var id int
280 if err := rows.Scan(&id); err != nil { 276 if err := rows.Scan(&id); err != nil {
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index d1913be..5934e9a 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -16,6 +16,7 @@ import (
16 "fagott.pw/grilist/cache" 16 "fagott.pw/grilist/cache"
17 "fagott.pw/grilist/frontend" 17 "fagott.pw/grilist/frontend"
18 "fagott.pw/grilist/grilist" 18 "fagott.pw/grilist/grilist"
19 "fagott.pw/grilist/models"
19 "fagott.pw/grilist/modules/grils" 20 "fagott.pw/grilist/modules/grils"
20 "github.com/julienschmidt/httprouter" 21 "github.com/julienschmidt/httprouter"
21 "github.com/lib/pq" 22 "github.com/lib/pq"
@@ -41,7 +42,7 @@ type List struct {
41 42
42// ListGril ist ein geranktes Gril 43// ListGril ist ein geranktes Gril
43type ListGril struct { 44type ListGril struct {
44 Gril *grils.Gril 45 Gril *models.Gril
45 Order int 46 Order int
46} 47}
47 48
diff --git a/modules/search/search.go b/modules/search/search.go
index a614c08..4048dbe 100644
--- a/modules/search/search.go
+++ b/modules/search/search.go
@@ -1,6 +1,7 @@
1package search 1package search
2 2
3import ( 3import (
4 "fmt"
4 "log" 5 "log"
5 "net/http" 6 "net/http"
6 7
@@ -72,7 +73,9 @@ func (m *Module) instantSearchGril(w http.ResponseWriter, r *http.Request, p htt
72 continue 73 continue
73 } 74 }
74 75
75 result.ImagePath = grils.ImagePath(result.ID, true) 76 // Jan: Das ist hier irgendwie scheisse, aber wir bauen ja grad irgendwie den kram auf Models um. Wir brauchen da
77 // irgendwas besseres.
78 result.ImagePath = fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", result.ID)
76 results = append(results, result) 79 results = append(results, result)
77 } 80 }
78 81