diff options
author | jan <jan@ruken.pw> | 2016-10-12 14:03:40 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-10-12 14:03:40 (UTC) |
commit | def8ba82c69891244eb0f8eebe0cb0b3bb23955b (patch) | |
tree | d126befcea381077bd3074661821602d4b0c4c42 | |
parent | c6165a8bbcca97867205fa87456ba238beb760f9 (diff) |
alle models verschoben
-rw-r--r-- | models/gril.go | 4 | ||||
-rw-r--r-- | models/list.go | 25 | ||||
-rw-r--r-- | models/series.go | 11 | ||||
-rw-r--r-- | modules/lists/lists.go | 49 | ||||
-rw-r--r-- | modules/series/module.go | 44 | ||||
-rw-r--r-- | modules/series/series.go | 49 |
6 files changed, 93 insertions, 89 deletions
diff --git a/models/gril.go b/models/gril.go index f0b8f8f..0ee0f84 100644 --- a/models/gril.go +++ b/models/gril.go | |||
@@ -7,8 +7,6 @@ import ( | |||
7 | "strings" | 7 | "strings" |
8 | "time" | 8 | "time" |
9 | 9 | ||
10 | "fagott.pw/grilist/modules/series" | ||
11 | |||
12 | "github.com/lib/pq" | 10 | "github.com/lib/pq" |
13 | ) | 11 | ) |
14 | 12 | ||
@@ -38,7 +36,7 @@ type Gril struct { | |||
38 | ForeignIDs map[DataSource]int | 36 | ForeignIDs map[DataSource]int |
39 | UpdatedAt time.Time | 37 | UpdatedAt time.Time |
40 | Lists []int | 38 | Lists []int |
41 | Series []series.Series | 39 | Series []Series |
42 | } | 40 | } |
43 | 41 | ||
44 | // Der kram hier sollte eigentlich auch eher wo anders hin als ins Model, oder?! | 42 | // Der kram hier sollte eigentlich auch eher wo anders hin als ins Model, oder?! |
diff --git a/models/list.go b/models/list.go new file mode 100644 index 0000000..1d67546 --- /dev/null +++ b/models/list.go | |||
@@ -0,0 +1,25 @@ | |||
1 | package models | ||
2 | |||
3 | import ( | ||
4 | "database/sql" | ||
5 | |||
6 | "fagott.pw/charakterin" | ||
7 | "github.com/lib/pq" | ||
8 | ) | ||
9 | |||
10 | // List ist eine Liste an DINGEN. | ||
11 | type List struct { | ||
12 | ID int | ||
13 | Name string | ||
14 | Description string | ||
15 | Owner *charakterin.User | ||
16 | ForkOf sql.NullInt64 | ||
17 | UpdatedAt pq.NullTime | ||
18 | Grils []*ListGril | ||
19 | } | ||
20 | |||
21 | // ListGril ist ein geranktes Gril | ||
22 | type ListGril struct { | ||
23 | Gril *Gril | ||
24 | Order int | ||
25 | } | ||
diff --git a/models/series.go b/models/series.go new file mode 100644 index 0000000..1ae3aa6 --- /dev/null +++ b/models/series.go | |||
@@ -0,0 +1,11 @@ | |||
1 | package models | ||
2 | |||
3 | type Series struct { | ||
4 | ID int | ||
5 | Name string | ||
6 | KanjiName string | ||
7 | RomajiName string | ||
8 | FuriganaName string | ||
9 | OtherNames []string | ||
10 | Tags []string | ||
11 | } | ||
diff --git a/modules/lists/lists.go b/modules/lists/lists.go index 65e969f..cf6d7c5 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go | |||
@@ -1,7 +1,6 @@ | |||
1 | package lists | 1 | package lists |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "database/sql" | ||
5 | "encoding/json" | 4 | "encoding/json" |
6 | "errors" | 5 | "errors" |
7 | "fmt" | 6 | "fmt" |
@@ -20,7 +19,6 @@ import ( | |||
20 | "fagott.pw/grilist/models" | 19 | "fagott.pw/grilist/models" |
21 | "fagott.pw/grilist/modules/grils" | 20 | "fagott.pw/grilist/modules/grils" |
22 | "github.com/julienschmidt/httprouter" | 21 | "github.com/julienschmidt/httprouter" |
23 | "github.com/lib/pq" | ||
24 | ) | 22 | ) |
25 | 23 | ||
26 | // Module und so. | 24 | // Module und so. |
@@ -30,25 +28,8 @@ type Module struct { | |||
30 | grils *grils.GrilsModule | 28 | grils *grils.GrilsModule |
31 | } | 29 | } |
32 | 30 | ||
33 | // List ist eine Liste an DINGEN. | ||
34 | type List struct { | ||
35 | ID int | ||
36 | Name string | ||
37 | Description string | ||
38 | Owner *charakterin.User | ||
39 | ForkOf sql.NullInt64 | ||
40 | UpdatedAt pq.NullTime | ||
41 | Grils []*ListGril | ||
42 | } | ||
43 | |||
44 | // ListGril ist ein geranktes Gril | ||
45 | type ListGril struct { | ||
46 | Gril *models.Gril | ||
47 | Order int | ||
48 | } | ||
49 | |||
50 | // ListGrils ist die Sort-Interface Implementation für Grils einer Liste. | 31 | // ListGrils ist die Sort-Interface Implementation für Grils einer Liste. |
51 | type ListGrils []*ListGril | 32 | type ListGrils []*models.ListGril |
52 | 33 | ||
53 | func (l ListGrils) Len() int { return len(l) } | 34 | func (l ListGrils) Len() int { return len(l) } |
54 | func (l ListGrils) Swap(i, j int) { l[i], l[j] = l[j], l[i] } | 35 | func (l ListGrils) Swap(i, j int) { l[i], l[j] = l[j], l[i] } |
@@ -88,7 +69,7 @@ func (m *Module) Init(g *grilist.Grilist) { | |||
88 | m.c = cache.New() | 69 | m.c = cache.New() |
89 | } | 70 | } |
90 | 71 | ||
91 | func (m *Module) getListGrils(list *List) error { | 72 | func (m *Module) getListGrils(list *models.List) error { |
92 | rows, err := m.g.DB.Query(`SELECT gril_id, "order" FROM grilist.lists_grils WHERE list_id = $1 ORDER BY "order" ASC`, list.ID) | 73 | rows, err := m.g.DB.Query(`SELECT gril_id, "order" FROM grilist.lists_grils WHERE list_id = $1 ORDER BY "order" ASC`, list.ID) |
93 | if err != nil { | 74 | if err != nil { |
94 | return err | 75 | return err |
@@ -98,7 +79,7 @@ func (m *Module) getListGrils(list *List) error { | |||
98 | list.Grils = list.Grils[:0] | 79 | list.Grils = list.Grils[:0] |
99 | for rows.Next() { | 80 | for rows.Next() { |
100 | var grilID int | 81 | var grilID int |
101 | lg := &ListGril{} | 82 | lg := &models.ListGril{} |
102 | 83 | ||
103 | if err := rows.Scan(&grilID, &lg.Order); err != nil { | 84 | if err := rows.Scan(&grilID, &lg.Order); err != nil { |
104 | log.Println("error scanning row in getListGrils:", err) | 85 | log.Println("error scanning row in getListGrils:", err) |
@@ -118,8 +99,8 @@ func (m *Module) getListGrils(list *List) error { | |||
118 | return nil | 99 | return nil |
119 | } | 100 | } |
120 | 101 | ||
121 | func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, error) { | 102 | func (m *Module) getLists(whereClause string, params ...interface{}) ([]*models.List, error) { |
122 | var lists []*List | 103 | var lists []*models.List |
123 | 104 | ||
124 | rows, err := m.g.DB.Query(fmt.Sprintf(`SELECT id, name, description, fork_of, updated_at, user_id FROM grilist.lists WHERE %s`, whereClause), params...) | 105 | rows, err := m.g.DB.Query(fmt.Sprintf(`SELECT id, name, description, fork_of, updated_at, user_id FROM grilist.lists WHERE %s`, whereClause), params...) |
125 | if err != nil { | 106 | if err != nil { |
@@ -128,7 +109,7 @@ func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, e | |||
128 | 109 | ||
129 | defer rows.Close() | 110 | defer rows.Close() |
130 | for rows.Next() { | 111 | for rows.Next() { |
131 | list := &List{} | 112 | list := &models.List{} |
132 | var ownerID int | 113 | var ownerID int |
133 | if err := rows.Scan(&list.ID, &list.Name, &list.Description, &list.ForkOf, &list.UpdatedAt, &ownerID); err != nil { | 114 | if err := rows.Scan(&list.ID, &list.Name, &list.Description, &list.ForkOf, &list.UpdatedAt, &ownerID); err != nil { |
134 | log.Println("error scanning row in getLists:", err) | 115 | log.Println("error scanning row in getLists:", err) |
@@ -151,7 +132,7 @@ func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, e | |||
151 | } | 132 | } |
152 | 133 | ||
153 | // GetUserLists gibt die Listen eines Benutzers zurück. | 134 | // GetUserLists gibt die Listen eines Benutzers zurück. |
154 | func (m *Module) GetUserLists(u *charakterin.User, withGrils bool) []*List { | 135 | func (m *Module) GetUserLists(u *charakterin.User, withGrils bool) []*models.List { |
155 | lists, err := m.getLists(`user_id = $1`, u.ID) | 136 | lists, err := m.getLists(`user_id = $1`, u.ID) |
156 | if err != nil { | 137 | if err != nil { |
157 | log.Println(err) | 138 | log.Println(err) |
@@ -168,9 +149,9 @@ func (m *Module) GetUserLists(u *charakterin.User, withGrils bool) []*List { | |||
168 | } | 149 | } |
169 | 150 | ||
170 | // FromID sucht nach der Liste mit der gegebenen ID und gibt sie, falls sie existiert, zurück. | 151 | // FromID sucht nach der Liste mit der gegebenen ID und gibt sie, falls sie existiert, zurück. |
171 | func (m *Module) FromID(id int, withGrils bool) (*List, error) { | 152 | func (m *Module) FromID(id int, withGrils bool) (*models.List, error) { |
172 | if lst, ok := m.c.Get(id); ok { | 153 | if lst, ok := m.c.Get(id); ok { |
173 | l := lst.(*List) | 154 | l := lst.(*models.List) |
174 | // einen neuen User holen, wir wollen ja sicher gehen und so. | 155 | // einen neuen User holen, wir wollen ja sicher gehen und so. |
175 | if owner, err := m.g.Charakterin.GetUserByID(l.Owner.ID); err == nil { | 156 | if owner, err := m.g.Charakterin.GetUserByID(l.Owner.ID); err == nil { |
176 | l.Owner = owner | 157 | l.Owner = owner |
@@ -204,7 +185,7 @@ func (m *Module) FromID(id int, withGrils bool) (*List, error) { | |||
204 | return lists[0], nil | 185 | return lists[0], nil |
205 | } | 186 | } |
206 | 187 | ||
207 | func ListsToCards(lists []*List) []frontend.Card { | 188 | func ListsToCards(lists []*models.List) []frontend.Card { |
208 | var cards []frontend.Card | 189 | var cards []frontend.Card |
209 | 190 | ||
210 | for _, list := range lists { | 191 | for _, list := range lists { |
@@ -553,7 +534,7 @@ func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprou | |||
553 | return | 534 | return |
554 | } | 535 | } |
555 | 536 | ||
556 | lg := &ListGril{gril, rank} | 537 | lg := &models.ListGril{gril, rank} |
557 | data := m.g.Renderer.DefaultData() | 538 | data := m.g.Renderer.DefaultData() |
558 | data["Index"] = len(list.Grils) | 539 | data["Index"] = len(list.Grils) |
559 | value := make(map[string]interface{}) | 540 | value := make(map[string]interface{}) |
@@ -667,7 +648,7 @@ func (m *Module) updateGrilOrder(w http.ResponseWriter, r *http.Request, p httpr | |||
667 | 648 | ||
668 | // wenn die liste im cache ist, die Grils clearen, damit beim naechsten aufruf die Gril-Liste neu geholt wird. | 649 | // wenn die liste im cache ist, die Grils clearen, damit beim naechsten aufruf die Gril-Liste neu geholt wird. |
669 | if l, ok := m.c.Get(listID); ok { | 650 | if l, ok := m.c.Get(listID); ok { |
670 | ls := l.(*List) | 651 | ls := l.(*models.List) |
671 | ls.Grils = ls.Grils[:0] | 652 | ls.Grils = ls.Grils[:0] |
672 | } | 653 | } |
673 | 654 | ||
@@ -724,7 +705,7 @@ func (m *Module) removeGrilFromList(w http.ResponseWriter, r *http.Request, p ht | |||
724 | } | 705 | } |
725 | 706 | ||
726 | if l, ok := m.c.Get(listID); ok { | 707 | if l, ok := m.c.Get(listID); ok { |
727 | ls := l.(*List) | 708 | ls := l.(*models.List) |
728 | ls.Grils = ls.Grils[:0] | 709 | ls.Grils = ls.Grils[:0] |
729 | } | 710 | } |
730 | 711 | ||
@@ -744,12 +725,12 @@ func (m *Module) APIgetUserLists(w http.ResponseWriter, r *http.Request, p httpr | |||
744 | } | 725 | } |
745 | 726 | ||
746 | lists := m.GetUserLists(user, false) | 727 | lists := m.GetUserLists(user, false) |
747 | var pubLists []List | 728 | var pubLists []models.List |
748 | 729 | ||
749 | for _, list := range lists { | 730 | for _, list := range lists { |
750 | // owner wegen SICHERHEIT rausfiltern (nodumppassword2k16) | 731 | // owner wegen SICHERHEIT rausfiltern (nodumppassword2k16) |
751 | // list.Owner = nil | 732 | // list.Owner = nil |
752 | var tempList List | 733 | var tempList models.List |
753 | tempList.Description = list.Description | 734 | tempList.Description = list.Description |
754 | tempList.ForkOf = list.ForkOf | 735 | tempList.ForkOf = list.ForkOf |
755 | tempList.ID = list.ID | 736 | tempList.ID = list.ID |
diff --git a/modules/series/module.go b/modules/series/module.go deleted file mode 100644 index 295e16b..0000000 --- a/modules/series/module.go +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | package series | ||
2 | |||
3 | import ( | ||
4 | "net/http" | ||
5 | "strconv" | ||
6 | |||
7 | "fagott.pw/charakterin" | ||
8 | "fagott.pw/grilist/grilist" | ||
9 | "github.com/julienschmidt/httprouter" | ||
10 | ) | ||
11 | |||
12 | type Module struct { | ||
13 | g *grilist.Grilist | ||
14 | } | ||
15 | |||
16 | func New() *Module { | ||
17 | return &Module{} | ||
18 | } | ||
19 | |||
20 | func (m *Module) Name() string { | ||
21 | return "Series" | ||
22 | } | ||
23 | |||
24 | func (m *Module) Init(g *grilist.Grilist) { | ||
25 | m.g = g | ||
26 | |||
27 | m.g.Router.GET("/series/:id", m.viewSeries) | ||
28 | } | ||
29 | |||
30 | func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { | ||
31 | return make([]grilist.DashboardCategory, 0) | ||
32 | } | ||
33 | |||
34 | func (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 | } | ||
diff --git a/modules/series/series.go b/modules/series/series.go index 1f50903..295e16b 100644 --- a/modules/series/series.go +++ b/modules/series/series.go | |||
@@ -1,11 +1,44 @@ | |||
1 | package series | 1 | package series |
2 | 2 | ||
3 | type Series struct { | 3 | import ( |
4 | ID int | 4 | "net/http" |
5 | Name string | 5 | "strconv" |
6 | KanjiName string | 6 | |
7 | RomajiName string | 7 | "fagott.pw/charakterin" |
8 | FuriganaName string | 8 | "fagott.pw/grilist/grilist" |
9 | OtherNames []string | 9 | "github.com/julienschmidt/httprouter" |
10 | Tags []string | 10 | ) |
11 | |||
12 | type Module struct { | ||
13 | g *grilist.Grilist | ||
14 | } | ||
15 | |||
16 | func New() *Module { | ||
17 | return &Module{} | ||
18 | } | ||
19 | |||
20 | func (m *Module) Name() string { | ||
21 | return "Series" | ||
22 | } | ||
23 | |||
24 | func (m *Module) Init(g *grilist.Grilist) { | ||
25 | m.g = g | ||
26 | |||
27 | m.g.Router.GET("/series/:id", m.viewSeries) | ||
28 | } | ||
29 | |||
30 | func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { | ||
31 | return make([]grilist.DashboardCategory, 0) | ||
32 | } | ||
33 | |||
34 | func (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) | ||
11 | } | 44 | } |