diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/service.go | 9 | ||||
-rw-r--r-- | service/transport.go | 15 |
2 files changed, 24 insertions, 0 deletions
diff --git a/service/service.go b/service/service.go index d548342..084993c 100644 --- a/service/service.go +++ b/service/service.go @@ -321,6 +321,15 @@ func (s *service) ThreadPage(c *client, id string, reply bool) (err error) { return s.renderer.Render(c.rctx, c.w, renderer.ThreadPage, data) } +func (svc *service) StatusPopup(c *client, id string) (err error) { + status, err := c.GetStatus(ctx, id) + if err != nil { + return + } + rCtx := getRendererContext(c) + return svc.renderer.Render(rCtx, c, renderer.StatusPopup, status) +} + func (s *service) LikedByPage(c *client, id string) (err error) { likers, err := c.GetFavouritedBy(c.ctx, id, nil) if err != nil { diff --git a/service/transport.go b/service/transport.go index f448cc3..ed083b6 100644 --- a/service/transport.go +++ b/service/transport.go @@ -54,6 +54,15 @@ func writeJson(c *client, data interface{}) error { }) } +func serveJsonError(w http.ResponseWriter, err error) { + var d = make(map[string]interface{}) + d["error"] = err.Error() + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusInternalServerError) + json.NewEncoder(w).Encode(d) + return +} + func redirect(c *client, url string) { c.w.Header().Add("Location", url) c.w.WriteHeader(http.StatusFound) @@ -620,6 +629,11 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return writeJson(c, count) }, CSRF, JSON) + fStatus := handle(func(c *client) error { + id, _ := mux.Vars(c.Req)["id"] + return s.StatusPopup(c, id) + }, SESSION, JSON) + r.HandleFunc("/", rootPage).Methods(http.MethodGet) r.HandleFunc("/nav", navPage).Methods(http.MethodGet) r.HandleFunc("/signin", signinPage).Methods(http.MethodGet) @@ -669,6 +683,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost) r.HandleFunc("/fluoride/retweet/{id}", fRetweet).Methods(http.MethodPost) r.HandleFunc("/fluoride/unretweet/{id}", fUnretweet).Methods(http.MethodPost) + r.HandleFunc("/fluoride/status/{id}", fStatus).Methods(http.MethodGet) r.PathPrefix("/static").Handler(http.StripPrefix("/static", http.FileServer(http.Dir(staticDir)))) |