From cfec7879e3b3fc38956f2dce0acbbeb8a578f4c1 Mon Sep 17 00:00:00 2001 From: r Date: Sun, 9 Feb 2020 13:42:16 +0000 Subject: Add poll support Currenlty only voting is possible. --- service/transport.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'service/transport.go') diff --git a/service/transport.go b/service/transport.go index 81af4fa..5ce0e56 100644 --- a/service/transport.go +++ b/service/transport.go @@ -419,6 +419,24 @@ func NewHandler(s Service, staticDir string) http.Handler { w.WriteHeader(http.StatusFound) } + vote := func(w http.ResponseWriter, req *http.Request) { + c := newClient(w) + ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token")) + id, _ := mux.Vars(req)["id"] + statusID := req.FormValue("status_id") + choices, _ := req.PostForm["choices"] + + err := s.Vote(ctx, c, id, choices) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + s.ServeErrorPage(ctx, c, err) + return + } + + w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+statusID) + w.WriteHeader(http.StatusFound) + } + follow := func(w http.ResponseWriter, req *http.Request) { c := newClient(w) ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token")) @@ -697,6 +715,7 @@ func NewHandler(s Service, staticDir string) http.Handler { r.HandleFunc("/unlike/{id}", unlike).Methods(http.MethodPost) r.HandleFunc("/retweet/{id}", retweet).Methods(http.MethodPost) r.HandleFunc("/unretweet/{id}", unretweet).Methods(http.MethodPost) + r.HandleFunc("/vote/{id}", vote).Methods(http.MethodPost) r.HandleFunc("/follow/{id}", follow).Methods(http.MethodPost) r.HandleFunc("/unfollow/{id}", unfollow).Methods(http.MethodPost) r.HandleFunc("/mute/{id}", mute).Methods(http.MethodPost) -- cgit v1.2.3