diff options
Diffstat (limited to 'modules/lists')
-rw-r--r-- | modules/lists/lists.go | 43 |
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 | ||
63 | func (m *Module) getListGrils(list *List) error { | 66 | func (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 | ||
238 | func (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 |
236 | func New() *Module { | 264 | func New() *Module { |
237 | return &Module{} | 265 | return &Module{} |
238 | } | 266 | } |
267 | |||
268 | func 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 | } | ||