aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorrtz12 <koenig@fagott.pw>2016-10-11 19:02:59 (UTC)
committerrtz12 <koenig@fagott.pw>2016-10-11 19:02:59 (UTC)
commitce5973c4024f22a8f8c63818109a2ca4f3be7bc4 (patch)
treee7b6b5d5c6e73451b489e97f90206a96bf9ed2df /modules
parentfbd746aef8c78067593f901afb0f255574392499 (diff)
parentb5051d2358e12f877e5c52053dcf1a16959e4ded (diff)
Merge branch 'master' of projekte.fagott.pw:grilist
Diffstat (limited to 'modules')
-rw-r--r--modules/grils/gril.go63
-rw-r--r--modules/grils/grils.go28
-rw-r--r--modules/lists/lists.go3
-rw-r--r--modules/search/search.go5
-rw-r--r--modules/series/module.go44
5 files changed, 62 insertions, 81 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go
deleted file mode 100644
index 7b54ab1..0000000
--- a/modules/grils/gril.go
+++ /dev/null
@@ -1,63 +0,0 @@
1package grils
2
3import (
4 "database/sql"
5 "fmt"
6 "strconv"
7 "strings"
8 "time"
9
10 "fagott.pw/grilist/modules/series"
11
12 "github.com/lib/pq"
13)
14
15type DataSource int
16
17const (
18 DataSourceACD DataSource = iota
19 DataSourceAniDB
20 DataSourceAnilist
21)
22
23type Trait struct {
24 Name string
25 Value string
26 OfficialValue string
27}
28
29type Gril struct {
30 ID int
31 KanjiName string
32 RomajiName string
33 OtherNames []string
34 Age sql.NullInt64
35 Birthday pq.NullTime
36 Tags []string
37 Traits []Trait
38 ForeignIDs map[DataSource]int
39 UpdatedAt time.Time
40 Lists []int
41 Series []series.Series
42}
43
44func (g *Gril) Slug() string {
45 if g.RomajiName == "" {
46 return strconv.Itoa(g.ID)
47 }
48 return fmt.Sprintf(
49 "%d/%s",
50 g.ID,
51 strings.Replace(g.RomajiName, " ", "", -1))
52}
53
54func ImagePath(id int, useThumbnail bool) string {
55 if useThumbnail {
56 return fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", id)
57 }
58 return fmt.Sprintf("http://img.grilist.moe/gril/full/%d.jpg", id)
59}
60
61func (g *Gril) ImagePath(prioritizeThumbnail bool) string {
62 return ImagePath(g.ID, prioritizeThumbnail)
63}
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index debb77b..4a9990f 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -14,15 +14,11 @@ import (
14 "fagott.pw/grilist/eventlogging" 14 "fagott.pw/grilist/eventlogging"
15 "fagott.pw/grilist/frontend" 15 "fagott.pw/grilist/frontend"
16 "fagott.pw/grilist/grilist" 16 "fagott.pw/grilist/grilist"
17 "fagott.pw/grilist/models"
17 18
18 "github.com/julienschmidt/httprouter" 19 "github.com/julienschmidt/httprouter"
19) 20)
20 21
21type CachedGril struct {
22 Created time.Time
23 Gril *Gril
24}
25
26var ( 22var (
27 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`) 23 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`)
28 pgValueIdx int 24 pgValueIdx int
@@ -55,8 +51,8 @@ func (m *GrilsModule) Init(g *grilist.Grilist) {
55 m.c = cache.New() 51 m.c = cache.New()
56} 52}
57 53
58func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { 54func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*models.Gril, error) {
59 var grils []*Gril 55 var grils []*models.Gril
60 56
61 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...) 57 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...)
62 if err != nil { 58 if err != nil {
@@ -65,7 +61,7 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gr
65 61
66 defer rows.Close() 62 defer rows.Close()
67 for rows.Next() { 63 for rows.Next() {
68 gril := &Gril{} 64 gril := &models.Gril{}
69 var tags []byte 65 var tags []byte
70 var otherNames []byte 66 var otherNames []byte
71 err = rows.Scan(&gril.ID, &gril.KanjiName, &gril.RomajiName, &otherNames, &gril.UpdatedAt, &gril.Age, &gril.Birthday, &tags) 67 err = rows.Scan(&gril.ID, &gril.KanjiName, &gril.RomajiName, &otherNames, &gril.UpdatedAt, &gril.Age, &gril.Birthday, &tags)
@@ -84,7 +80,7 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gr
84 return grils, nil 80 return grils, nil
85} 81}
86 82
87func (m *GrilsModule) GetListsOfGril(gril *Gril) error { 83func (m *GrilsModule) GetListsOfGril(gril *models.Gril) error {
88 rows, err := m.g.DB.Query(`SELECT list_id FROM grilist.lists_grils WHERE gril_id = $1`, gril.ID) 84 rows, err := m.g.DB.Query(`SELECT list_id FROM grilist.lists_grils WHERE gril_id = $1`, gril.ID)
89 if err != nil { 85 if err != nil {
90 return err 86 return err
@@ -121,7 +117,7 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
121 } 117 }
122 118
123 for rows.Next() { 119 for rows.Next() {
124 var g Gril 120 var g models.Gril
125 if err := rows.Scan(&g.ID, &g.RomajiName, &g.KanjiName); err != nil { 121 if err := rows.Scan(&g.ID, &g.RomajiName, &g.KanjiName); err != nil {
126 log.Println(err) 122 log.Println(err)
127 continue 123 continue
@@ -144,12 +140,12 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
144 return categories 140 return categories
145} 141}
146 142
147func (m *GrilsModule) FromID(id int) (*Gril, error) { 143func (m *GrilsModule) FromID(id int) (*models.Gril, error) {
148 if g, ok := m.c.Get(id); ok { 144 if g, ok := m.c.Get(id); ok {
149 return g.(*Gril), nil 145 return g.(*models.Gril), nil
150 } 146 }
151 147
152 gril := &Gril{ 148 gril := &models.Gril{
153 ID: id, 149 ID: id,
154 } 150 }
155 t1 := time.Now() 151 t1 := time.Now()
@@ -220,9 +216,9 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
220 return gril, nil 216 return gril, nil
221} 217}
222 218
223func (m *GrilsModule) FromIDs(ids []int) ([]*Gril, error) { 219func (m *GrilsModule) FromIDs(ids []int) ([]*models.Gril, error) {
224 if len(ids) == 0 { 220 if len(ids) == 0 {
225 return make([]*Gril, 0), nil 221 return make([]*models.Gril, 0), nil
226 } 222 }
227 223
228 idList := "(" 224 idList := "("
@@ -276,7 +272,7 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou
276 } 272 }
277 273
278 defer rows.Close() 274 defer rows.Close()
279 var similar []*Gril 275 var similar []*models.Gril
280 for rows.Next() { 276 for rows.Next() {
281 var id int 277 var id int
282 if err := rows.Scan(&id); err != nil { 278 if err := rows.Scan(&id); err != nil {
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 9c9eaf4..65e969f 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -17,6 +17,7 @@ import (
17 "fagott.pw/grilist/eventlogging" 17 "fagott.pw/grilist/eventlogging"
18 "fagott.pw/grilist/frontend" 18 "fagott.pw/grilist/frontend"
19 "fagott.pw/grilist/grilist" 19 "fagott.pw/grilist/grilist"
20 "fagott.pw/grilist/models"
20 "fagott.pw/grilist/modules/grils" 21 "fagott.pw/grilist/modules/grils"
21 "github.com/julienschmidt/httprouter" 22 "github.com/julienschmidt/httprouter"
22 "github.com/lib/pq" 23 "github.com/lib/pq"
@@ -42,7 +43,7 @@ type List struct {
42 43
43// ListGril ist ein geranktes Gril 44// ListGril ist ein geranktes Gril
44type ListGril struct { 45type ListGril struct {
45 Gril *grils.Gril 46 Gril *models.Gril
46 Order int 47 Order int
47} 48}
48 49
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
diff --git a/modules/series/module.go b/modules/series/module.go
new file mode 100644
index 0000000..295e16b
--- /dev/null
+++ b/modules/series/module.go
@@ -0,0 +1,44 @@
1package series
2
3import (
4 "net/http"
5 "strconv"
6
7 "fagott.pw/charakterin"
8 "fagott.pw/grilist/grilist"
9 "github.com/julienschmidt/httprouter"
10)
11
12type Module struct {
13 g *grilist.Grilist
14}
15
16func New() *Module {
17 return &Module{}
18}
19
20func (m *Module) Name() string {
21 return "Series"
22}
23
24func (m *Module) Init(g *grilist.Grilist) {
25 m.g = g
26
27 m.g.Router.GET("/series/:id", m.viewSeries)
28}
29
30func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
31 return make([]grilist.DashboardCategory, 0)
32}
33
34func (m *Module) viewSeries(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
35 _, _ = m.g.Charakterin.GetUserFromRequest(r)
36
37 _, err := strconv.Atoi(p.ByName("id"))
38 if err != nil {
39 http.Redirect(w, r, "/", 302)
40 return
41 }
42
43 http.Error(w, "not implemented", 500)
44}