aboutsummaryrefslogtreecommitdiff
path: root/modules/lists
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-31 00:19:09 (UTC)
committerjan <jan@ruken.pw>2015-12-31 00:19:09 (UTC)
commit16f6b2565d33be12c84dc78ed5fef147d8f435d3 (patch)
tree38da730fd72a2f06a721bc9f804337392804e471 /modules/lists
parentc2503cab34c1abe3e0ab9de2ac2321a42db8989c (diff)
listen können jetzt erstellt werden.
Diffstat (limited to 'modules/lists')
-rw-r--r--modules/lists/lists.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 2b1ced3..ae1ec65 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -61,6 +61,8 @@ func (m *Module) Init(g *grilist.Grilist) {
61 m.grils = grilsModule 61 m.grils = grilsModule
62 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) 63 m.g.Router.POST("/list/:id", m.addGrilToList)
64 m.g.Router.GET("/new/list", m.displayCreateList)
65 m.g.Router.POST("/new/list", m.createList)
64} 66}
65 67
66func (m *Module) getListGrils(list *List) error { 68func (m *Module) getListGrils(list *List) error {
@@ -260,6 +262,41 @@ func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprou
260 http.Error(w, "not implemented", 500) 262 http.Error(w, "not implemented", 500)
261} 263}
262 264
265func (m *Module) displayCreateList(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
266 user, _ := m.g.Charakterin.GetUserFromRequest(r)
267
268 data := m.g.Renderer.DefaultData()
269 data["user"] = user
270
271 m.g.Renderer.RenderPage("create_list", w, data)
272}
273
274func (m *Module) createList(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
275 user, err := m.g.Charakterin.GetUserFromRequest(r)
276 if err != nil {
277 log.Println(err)
278 http.Error(w, "500", http.StatusInternalServerError)
279 return
280 }
281
282 values, err := readBody(r)
283 if err != nil {
284 log.Println(err)
285 http.Error(w, "500", http.StatusInternalServerError)
286 return
287 }
288
289 var id int
290 err = m.g.DB.QueryRow(`INSERT INTO grilist.lists(user_id, name, description) VALUES($1, $2, $3) RETURNING id`, user.ID, values.Get("name"), values.Get("description")).Scan(&id)
291 if err != nil {
292 log.Println(err)
293 http.Error(w, "500", http.StatusInternalServerError)
294 return
295 }
296
297 http.Redirect(w, r, fmt.Sprintf("/list/%d", id), 302)
298}
299
263// New erstellt eine neue Instanz des Modules 300// New erstellt eine neue Instanz des Modules
264func New() *Module { 301func New() *Module {
265 return &Module{} 302 return &Module{}