diff --git a/README.md b/README.md index 00175bd8..1190990b 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ Sort can be `time` or `score`. Supported sort order with prefix -/+, i.e. `-time - `GET /api/v1/id/{id}?site=site-id` - get comment by `id` - `GET /api/v1/comments?site=site-id&user=id` - get comment by `user id` - `GET /api/v1/count?site=site-id&url=post-url` - get comment's count for `{url}` +- `GET /api/v1/list?site=site-id` - list commented posts - `GET /api/v1/user` - get user info, _auth required_ - `PUT /api/v1/vote/{id}?site=site-id&url=post-url&vote=1` - vote for comment. `vote`=1 will increase score, -1 decrease. _auth required_ diff --git a/app/rest/server.go b/app/rest/server.go index dcc33bf5..03fa698a 100644 --- a/app/rest/server.go +++ b/app/rest/server.go @@ -79,6 +79,7 @@ func (s *Server) Run() { rapi.Get("/comments", s.findUserCommentsCtrl) rapi.Get("/last/{max}", s.lastCommentsCtrl) rapi.Get("/count", s.countCtrl) + rapi.Get("/list", s.listCtrl) // protected routes, require auth rapi.With(auth.Auth(s.SessionStore, s.Admins, maybeDevMode(auth.Full))).Group(func(rauth chi.Router) { @@ -285,6 +286,17 @@ func (s *Server) countCtrl(w http.ResponseWriter, r *http.Request) { render.JSON(w, r, JSON{"count": count, "loc": locator}) } +// GET /list?site=siteID - list posts with comments +func (s *Server) listCtrl(w http.ResponseWriter, r *http.Request) { + locator := store.Locator{SiteID: r.URL.Query().Get("site")} + posts, err := s.DataService.List(locator) + if err != nil { + httpError(w, r, http.StatusBadRequest, err, "can't get count") + return + } + render.JSON(w, r, JSON{"posts": posts, "loc": locator}) +} + // PUT /vote/{id}?site=siteID&url=post-url&vote=1 - vote for/against comment func (s *Server) voteCtrl(w http.ResponseWriter, r *http.Request) { diff --git a/remark.rest b/remark.rest index 18eb7222..ba1cb516 100644 --- a/remark.rest +++ b/remark.rest @@ -8,7 +8,7 @@ GET https://demo.remark42.com/api/v1/find?site=remark&url=https://radio-t.com/p/ ### last 10 comments GET https://demo.remark42.com/api/v1/last/50?site=remark -### create commnet +### create comment POST https://demo.remark42.com/api/v1/comment Content-Type: application/json @@ -42,3 +42,6 @@ GET https://demo.remark42.com/api/v1/comments?site=remark&user=umputun ### get counts GET https://demo.remark42.com/api/v1/count?site=remark&url=https://radio-t.com/p/2017/12/16/podcast-576/ + +### list commented posts +GET https://demo.remark42.com/api/v1/list?site=remark