aboutsummaryrefslogtreecommitdiff
path: root/modules/lists
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-30 15:49:59 (UTC)
committerjan <jan@ruken.pw>2015-12-30 15:49:59 (UTC)
commitee37b31502bc46527a5db51f73459f5f7946e1b2 (patch)
treee34ae3c9357ed536e1ab589483e999f8bf9d1df2 /modules/lists
parentb203f34144896436db3925c63b3c91bda59f7e77 (diff)
hover für search-results. beim klicken auf ein gril wird ein request gestartet, fehlt nur noch die implementation, um ein gril zu einer liste hinzuzufügen.
Diffstat (limited to 'modules/lists')
-rw-r--r--modules/lists/lists.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 4c4288f..2b1ced3 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -10,8 +10,10 @@ import (
10 "fmt" 10 "fmt"
11 "github.com/julienschmidt/httprouter" 11 "github.com/julienschmidt/httprouter"
12 "github.com/lib/pq" 12 "github.com/lib/pq"
13 "io/ioutil"
13 "log" 14 "log"
14 "net/http" 15 "net/http"
16 "net/url"
15 "strconv" 17 "strconv"
16) 18)
17 19
@@ -58,6 +60,7 @@ func (m *Module) Init(g *grilist.Grilist) {
58 } 60 }
59 m.grils = grilsModule 61 m.grils = grilsModule
60 m.g.Router.GET("/list/:id", m.viewList) 62 m.g.Router.GET("/list/:id", m.viewList)
63 m.g.Router.POST("/list/:id", m.addGrilToList)
61} 64}
62 65
63func (m *Module) getListGrils(list *List) error { 66func (m *Module) getListGrils(list *List) error {
@@ -232,7 +235,47 @@ func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.P
232 m.g.Renderer.RenderPage("list", w, data) 235 m.g.Renderer.RenderPage("list", w, data)
233} 236}
234 237
238func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
239 slistID := p.ByName("id")
240
241 listID, err := strconv.Atoi(slistID)
242 if err != nil {
243 log.Println("invalid list id")
244 return
245 }
246
247 values, err := readBody(r)
248 if err != nil {
249 log.Println("invalid POST data")
250 return
251 }
252
253 grilID, err := strconv.Atoi(values.Get("id"))
254 if err != nil {
255 log.Println("invalid gril id")
256 return
257 }
258
259 log.Println("implement: add gril", grilID, "to list", listID)
260 http.Error(w, "not implemented", 500)
261}
262
235// New erstellt eine neue Instanz des Modules 263// New erstellt eine neue Instanz des Modules
236func New() *Module { 264func New() *Module {
237 return &Module{} 265 return &Module{}
238} 266}
267
268func readBody(r *http.Request) (url.Values, error) {
269 defer r.Body.Close()
270 data, err := ioutil.ReadAll(r.Body)
271 if err != nil {
272 return nil, err
273 }
274
275 values, err := url.ParseQuery(string(data))
276 if err != nil {
277 return nil, err
278 }
279
280 return values, nil
281}