add rest for posts list
This commit is contained in:
@@ -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_
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user