diff options
Diffstat (limited to 'modules/lists')
-rw-r--r-- | modules/lists/lists.go | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/modules/lists/lists.go b/modules/lists/lists.go index cf6d7c5..39cc4d0 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go | |||
@@ -18,6 +18,7 @@ import ( | |||
18 | "fagott.pw/grilist/grilist" | 18 | "fagott.pw/grilist/grilist" |
19 | "fagott.pw/grilist/models" | 19 | "fagott.pw/grilist/models" |
20 | "fagott.pw/grilist/modules/grils" | 20 | "fagott.pw/grilist/modules/grils" |
21 | "fagott.pw/grilist/util" | ||
21 | "github.com/julienschmidt/httprouter" | 22 | "github.com/julienschmidt/httprouter" |
22 | ) | 23 | ) |
23 | 24 | ||
@@ -243,9 +244,7 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar | |||
243 | func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | 244 | func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { |
244 | user, _ := m.g.Charakterin.GetUserFromRequest(r) | 245 | user, _ := m.g.Charakterin.GetUserFromRequest(r) |
245 | el := m.g.EventLogger(r) | 246 | el := m.g.EventLogger(r) |
246 | sid := p.ByName("id") | 247 | id, err := util.ParseIDFromParams(p) |
247 | |||
248 | id, err := strconv.Atoi(sid) | ||
249 | if err != nil { | 248 | if err != nil { |
250 | log.Println("redir") | 249 | log.Println("redir") |
251 | http.Redirect(w, r, "/", 302) | 250 | http.Redirect(w, r, "/", 302) |
@@ -283,7 +282,7 @@ func (m *Module) deleteList(w http.ResponseWriter, r *http.Request, p httprouter | |||
283 | return | 282 | return |
284 | } | 283 | } |
285 | 284 | ||
286 | id, err := strconv.Atoi(p.ByName("id")) | 285 | id, err := util.ParseIDFromParams(p) |
287 | if err != nil { | 286 | if err != nil { |
288 | log.Println("invalid deleteList ID") | 287 | log.Println("invalid deleteList ID") |
289 | http.Redirect(w, r, "/", 400) | 288 | http.Redirect(w, r, "/", 400) |
@@ -370,7 +369,7 @@ func (m *Module) updateListSettings(w http.ResponseWriter, r *http.Request, p ht | |||
370 | return | 369 | return |
371 | } | 370 | } |
372 | 371 | ||
373 | id, err := strconv.Atoi(p.ByName("id")) | 372 | id, err := util.ParseIDFromParams(p) |
374 | if err != nil { | 373 | if err != nil { |
375 | log.Println("invalid updateListSettings ID") | 374 | log.Println("invalid updateListSettings ID") |
376 | http.Redirect(w, r, "/", 400) | 375 | http.Redirect(w, r, "/", 400) |
@@ -477,7 +476,6 @@ func (m *Module) updateListSettings(w http.ResponseWriter, r *http.Request, p ht | |||
477 | 476 | ||
478 | func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | 477 | func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { |
479 | el := m.g.EventLogger(r) | 478 | el := m.g.EventLogger(r) |
480 | slistID := p.ByName("id") | ||
481 | 479 | ||
482 | user, err := m.g.Charakterin.GetUserFromRequest(r) | 480 | user, err := m.g.Charakterin.GetUserFromRequest(r) |
483 | if err != nil { | 481 | if err != nil { |
@@ -485,7 +483,7 @@ func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprou | |||
485 | return | 483 | return |
486 | } | 484 | } |
487 | 485 | ||
488 | listID, err := strconv.Atoi(slistID) | 486 | listID, err := util.ParseIDFromParams(p) |
489 | if err != nil { | 487 | if err != nil { |
490 | log.Println("invalid list id") | 488 | log.Println("invalid list id") |
491 | return | 489 | return |
@@ -596,7 +594,6 @@ func (m *Module) createList(w http.ResponseWriter, r *http.Request, p httprouter | |||
596 | 594 | ||
597 | func (m *Module) updateGrilOrder(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | 595 | func (m *Module) updateGrilOrder(w http.ResponseWriter, r *http.Request, p httprouter.Params) { |
598 | el := m.g.EventLogger(r) | 596 | el := m.g.EventLogger(r) |
599 | slistID := p.ByName("id") | ||
600 | 597 | ||
601 | user, err := m.g.Charakterin.GetUserFromRequest(r) | 598 | user, err := m.g.Charakterin.GetUserFromRequest(r) |
602 | if err != nil { | 599 | if err != nil { |
@@ -604,7 +601,7 @@ func (m *Module) updateGrilOrder(w http.ResponseWriter, r *http.Request, p httpr | |||
604 | return | 601 | return |
605 | } | 602 | } |
606 | 603 | ||
607 | listID, err := strconv.Atoi(slistID) | 604 | listID, err := util.ParseIDFromParams(p) |
608 | if err != nil { | 605 | if err != nil { |
609 | http.Error(w, "invalid list ID (type mismatch)", 400) | 606 | http.Error(w, "invalid list ID (type mismatch)", 400) |
610 | return | 607 | return |
@@ -664,7 +661,6 @@ func (m *Module) updateGrilOrder(w http.ResponseWriter, r *http.Request, p httpr | |||
664 | 661 | ||
665 | func (m *Module) removeGrilFromList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | 662 | func (m *Module) removeGrilFromList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { |
666 | el := m.g.EventLogger(r) | 663 | el := m.g.EventLogger(r) |
667 | slistID := p.ByName("id") | ||
668 | 664 | ||
669 | user, err := m.g.Charakterin.GetUserFromRequest(r) | 665 | user, err := m.g.Charakterin.GetUserFromRequest(r) |
670 | if err != nil { | 666 | if err != nil { |
@@ -672,12 +668,17 @@ func (m *Module) removeGrilFromList(w http.ResponseWriter, r *http.Request, p ht | |||
672 | return | 668 | return |
673 | } | 669 | } |
674 | 670 | ||
675 | listID, err := strconv.Atoi(slistID) | 671 | listID, err := util.ParseIDFromParams(p) |
676 | if err != nil { | 672 | if err != nil { |
677 | http.Error(w, "invalid list ID (type mismatch)", 400) | 673 | http.Error(w, "invalid list ID (type mismatch)", 400) |
678 | return | 674 | return |
679 | } | 675 | } |
680 | //TODO: noch mal gucken ob der User Rechte hat | 676 | |
677 | list, err := m.FromID(listID, false) | ||
678 | if err != nil { | ||
679 | http.Error(w, "list not found", 404) | ||
680 | return | ||
681 | } | ||
681 | 682 | ||
682 | values, err := readBody(r) | 683 | values, err := readBody(r) |
683 | if err != nil { | 684 | if err != nil { |
@@ -704,10 +705,7 @@ func (m *Module) removeGrilFromList(w http.ResponseWriter, r *http.Request, p ht | |||
704 | return | 705 | return |
705 | } | 706 | } |
706 | 707 | ||
707 | if l, ok := m.c.Get(listID); ok { | 708 | list.Grils = list.Grils[:0] |
708 | ls := l.(*models.List) | ||
709 | ls.Grils = ls.Grils[:0] | ||
710 | } | ||
711 | 709 | ||
712 | w.WriteHeader(200) | 710 | w.WriteHeader(200) |
713 | w.Write([]byte("ok")) | 711 | w.Write([]byte("ok")) |