add limit param for user find

This commit is contained in:
Umputun
2018-03-18 22:12:52 -05:00
parent 9473d96c57
commit 72f16010f1
3 changed files with 13 additions and 8 deletions
+1 -1
View File
@@ -183,7 +183,7 @@ Sort can be `time` or `score`. Supported sort order with prefix -/+, i.e. `-time
* `GET /api/v1/last/{max}?site=site-id` - get up to `{max}` last comments
* `GET /api/v1/id/{id}?site=site-id` - get comment by `comment id`
* `GET /api/v1/comments?site=site-id&user=id` - get comment by `user id`, returns `response` object
* `GET /api/v1/comments?site=site-id&user=id&limit=N` - get comment by `user id`, returns `response` object
```go
type response struct {
Comments []store.Comment `json:"comments"`
+11 -6
View File
@@ -79,7 +79,7 @@ func (s *Rest) Run(port int) {
rapi.Get("/find", s.findCommentsCtrl)
rapi.Get("/id/{id}", s.commentByIDCtrl)
rapi.Get("/comments", s.findUserCommentsCtrl)
rapi.Get("/last/{max}", s.lastCommentsCtrl)
rapi.Get("/last/{limit}", s.lastCommentsCtrl)
rapi.Get("/count", s.countCtrl)
rapi.Post("/counts", s.countMultiCtrl)
rapi.Get("/list", s.listCtrl)
@@ -238,18 +238,18 @@ func (s *Rest) findCommentsCtrl(w http.ResponseWriter, r *http.Request) {
renderJSONFromBytes(w, r, data)
}
// GET /last/{max}?site=siteID - last comments for the siteID, across all posts, sorted by time
// GET /last/{limit}?site=siteID - last comments for the siteID, across all posts, sorted by time
func (s *Rest) lastCommentsCtrl(w http.ResponseWriter, r *http.Request) {
log.Printf("[DEBUG] get last comments for %s", r.URL.Query().Get("site"))
max, err := strconv.Atoi(chi.URLParam(r, "max"))
limit, err := strconv.Atoi(chi.URLParam(r, "limit"))
if err != nil {
max = 0
limit = 0
}
data, err := s.Cache.Get(rest.URLKey(r), time.Hour, func() ([]byte, error) {
comments, e := s.DataService.Last(r.URL.Query().Get("site"), max)
comments, e := s.DataService.Last(r.URL.Query().Get("site"), limit)
if e != nil {
return nil, e
}
@@ -289,6 +289,11 @@ func (s *Rest) findUserCommentsCtrl(w http.ResponseWriter, r *http.Request) {
userID := r.URL.Query().Get("user")
siteID := r.URL.Query().Get("site")
limit, err := strconv.Atoi(r.URL.Query().Get("limit"))
if err != nil {
limit = 0
}
resp := struct {
Comments []store.Comment
Count int
@@ -297,7 +302,7 @@ func (s *Rest) findUserCommentsCtrl(w http.ResponseWriter, r *http.Request) {
log.Printf("[DEBUG] get comments for userID %s, %s", userID, siteID)
data, err := s.Cache.Get(rest.URLKey(r), time.Hour, func() ([]byte, error) {
comments, count, e := s.DataService.User(siteID, userID, 0)
comments, count, e := s.DataService.User(siteID, userID, limit)
if e != nil {
return nil, e
}
+1 -1
View File
@@ -57,7 +57,7 @@ GET {{host}}/api/v1/id/3665976683?site=remark&url=https://radio-t.com/p/2017/12/
GET {{host}}/api/v1/id/a2ddb8d2f65008ee1a1e3af8df0f26beb042309c?site=remark&url=https://radio-t.com/blah1
### get comment by user id
GET {{host}}/api/v1/comments?site=remark&user=disqus_umputun
GET {{host}}/api/v1/comments?site=remark&user=disqus_umputun&limit=5
### get comment by user id2
GET {{host}}/api/v1/comments?site=remark&user=disqus_kpmy