From def8ba82c69891244eb0f8eebe0cb0b3bb23955b Mon Sep 17 00:00:00 2001 From: jan Date: Wed, 12 Oct 2016 16:03:40 +0200 Subject: alle models verschoben 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 ( "strings" "time" - "fagott.pw/grilist/modules/series" - "github.com/lib/pq" ) @@ -38,7 +36,7 @@ type Gril struct { ForeignIDs map[DataSource]int UpdatedAt time.Time Lists []int - Series []series.Series + Series []Series } // 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 @@ +package models + +import ( + "database/sql" + + "fagott.pw/charakterin" + "github.com/lib/pq" +) + +// List ist eine Liste an DINGEN. +type List struct { + ID int + Name string + Description string + Owner *charakterin.User + ForkOf sql.NullInt64 + UpdatedAt pq.NullTime + Grils []*ListGril +} + +// ListGril ist ein geranktes Gril +type ListGril struct { + Gril *Gril + Order int +} 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 @@ +package models + +type Series struct { + ID int + Name string + KanjiName string + RomajiName string + FuriganaName string + OtherNames []string + Tags []string +} 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 @@ package lists import ( - "database/sql" "encoding/json" "errors" "fmt" @@ -20,7 +19,6 @@ import ( "fagott.pw/grilist/models" "fagott.pw/grilist/modules/grils" "github.com/julienschmidt/httprouter" - "github.com/lib/pq" ) // Module und so. @@ -30,25 +28,8 @@ type Module struct { grils *grils.GrilsModule } -// List ist eine Liste an DINGEN. -type List struct { - ID int - Name string - Description string - Owner *charakterin.User - ForkOf sql.NullInt64 - UpdatedAt pq.NullTime - Grils []*ListGril -} - -// ListGril ist ein geranktes Gril -type ListGril struct { - Gril *models.Gril - Order int -} - // ListGrils ist die Sort-Interface Implementation für Grils einer Liste. -type ListGrils []*ListGril +type ListGrils []*models.ListGril func (l ListGrils) Len() int { return len(l) } 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) { m.c = cache.New() } -func (m *Module) getListGrils(list *List) error { +func (m *Module) getListGrils(list *models.List) error { rows, err := m.g.DB.Query(`SELECT gril_id, "order" FROM grilist.lists_grils WHERE list_id = $1 ORDER BY "order" ASC`, list.ID) if err != nil { return err @@ -98,7 +79,7 @@ func (m *Module) getListGrils(list *List) error { list.Grils = list.Grils[:0] for rows.Next() { var grilID int - lg := &ListGril{} + lg := &models.ListGril{} if err := rows.Scan(&grilID, &lg.Order); err != nil { log.Println("error scanning row in getListGrils:", err) @@ -118,8 +99,8 @@ func (m *Module) getListGrils(list *List) error { return nil } -func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, error) { - var lists []*List +func (m *Module) getLists(whereClause string, params ...interface{}) ([]*models.List, error) { + var lists []*models.List 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...) if err != nil { @@ -128,7 +109,7 @@ func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, e defer rows.Close() for rows.Next() { - list := &List{} + list := &models.List{} var ownerID int if err := rows.Scan(&list.ID, &list.Name, &list.Description, &list.ForkOf, &list.UpdatedAt, &ownerID); err != nil { log.Println("error scanning row in getLists:", err) @@ -151,7 +132,7 @@ func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, e } // GetUserLists gibt die Listen eines Benutzers zurück. -func (m *Module) GetUserLists(u *charakterin.User, withGrils bool) []*List { +func (m *Module) GetUserLists(u *charakterin.User, withGrils bool) []*models.List { lists, err := m.getLists(`user_id = $1`, u.ID) if err != nil { log.Println(err) @@ -168,9 +149,9 @@ func (m *Module) GetUserLists(u *charakterin.User, withGrils bool) []*List { } // FromID sucht nach der Liste mit der gegebenen ID und gibt sie, falls sie existiert, zurück. -func (m *Module) FromID(id int, withGrils bool) (*List, error) { +func (m *Module) FromID(id int, withGrils bool) (*models.List, error) { if lst, ok := m.c.Get(id); ok { - l := lst.(*List) + l := lst.(*models.List) // einen neuen User holen, wir wollen ja sicher gehen und so. if owner, err := m.g.Charakterin.GetUserByID(l.Owner.ID); err == nil { l.Owner = owner @@ -204,7 +185,7 @@ func (m *Module) FromID(id int, withGrils bool) (*List, error) { return lists[0], nil } -func ListsToCards(lists []*List) []frontend.Card { +func ListsToCards(lists []*models.List) []frontend.Card { var cards []frontend.Card for _, list := range lists { @@ -553,7 +534,7 @@ func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprou return } - lg := &ListGril{gril, rank} + lg := &models.ListGril{gril, rank} data := m.g.Renderer.DefaultData() data["Index"] = len(list.Grils) value := make(map[string]interface{}) @@ -667,7 +648,7 @@ func (m *Module) updateGrilOrder(w http.ResponseWriter, r *http.Request, p httpr // wenn die liste im cache ist, die Grils clearen, damit beim naechsten aufruf die Gril-Liste neu geholt wird. if l, ok := m.c.Get(listID); ok { - ls := l.(*List) + ls := l.(*models.List) ls.Grils = ls.Grils[:0] } @@ -724,7 +705,7 @@ func (m *Module) removeGrilFromList(w http.ResponseWriter, r *http.Request, p ht } if l, ok := m.c.Get(listID); ok { - ls := l.(*List) + ls := l.(*models.List) ls.Grils = ls.Grils[:0] } @@ -744,12 +725,12 @@ func (m *Module) APIgetUserLists(w http.ResponseWriter, r *http.Request, p httpr } lists := m.GetUserLists(user, false) - var pubLists []List + var pubLists []models.List for _, list := range lists { // owner wegen SICHERHEIT rausfiltern (nodumppassword2k16) // list.Owner = nil - var tempList List + var tempList models.List tempList.Description = list.Description tempList.ForkOf = list.ForkOf 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 @@ -package series - -import ( - "net/http" - "strconv" - - "fagott.pw/charakterin" - "fagott.pw/grilist/grilist" - "github.com/julienschmidt/httprouter" -) - -type Module struct { - g *grilist.Grilist -} - -func New() *Module { - return &Module{} -} - -func (m *Module) Name() string { - return "Series" -} - -func (m *Module) Init(g *grilist.Grilist) { - m.g = g - - m.g.Router.GET("/series/:id", m.viewSeries) -} - -func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { - return make([]grilist.DashboardCategory, 0) -} - -func (m *Module) viewSeries(w http.ResponseWriter, r *http.Request, p httprouter.Params) { - _, _ = m.g.Charakterin.GetUserFromRequest(r) - - _, err := strconv.Atoi(p.ByName("id")) - if err != nil { - http.Redirect(w, r, "/", 302) - return - } - - http.Error(w, "not implemented", 500) -} 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 @@ package series -type Series struct { - ID int - Name string - KanjiName string - RomajiName string - FuriganaName string - OtherNames []string - Tags []string +import ( + "net/http" + "strconv" + + "fagott.pw/charakterin" + "fagott.pw/grilist/grilist" + "github.com/julienschmidt/httprouter" +) + +type Module struct { + g *grilist.Grilist +} + +func New() *Module { + return &Module{} +} + +func (m *Module) Name() string { + return "Series" +} + +func (m *Module) Init(g *grilist.Grilist) { + m.g = g + + m.g.Router.GET("/series/:id", m.viewSeries) +} + +func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { + return make([]grilist.DashboardCategory, 0) +} + +func (m *Module) viewSeries(w http.ResponseWriter, r *http.Request, p httprouter.Params) { + _, _ = m.g.Charakterin.GetUserFromRequest(r) + + _, err := strconv.Atoi(p.ByName("id")) + if err != nil { + http.Redirect(w, r, "/", 302) + return + } + + http.Error(w, "not implemented", 500) } -- cgit v0.10.1