diff options
author | r <r@freesoftwareextremist.com> | 2020-02-09 13:42:16 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2020-02-09 13:42:16 +0000 |
commit | cfec7879e3b3fc38956f2dce0acbbeb8a578f4c1 (patch) | |
tree | 5da9a9371fd10667cd6ee68bbd07f7f0f9d8d3d3 /service/transport.go | |
parent | a68a09a83ef2eb411e2a7a66e919f27c040c0b6a (diff) | |
download | bloat-cfec7879e3b3fc38956f2dce0acbbeb8a578f4c1.tar.gz bloat-cfec7879e3b3fc38956f2dce0acbbeb8a578f4c1.zip |
Add poll support
Currenlty only voting is possible.
Diffstat (limited to 'service/transport.go')
-rw-r--r-- | service/transport.go | 19 |
1 files changed, 19 insertions, 0 deletions
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) |