support vote reset

This commit is contained in:
Umputun
2018-01-06 12:37:12 -06:00
parent 45df3c8f3e
commit 440974f365
4 changed files with 29 additions and 9 deletions
+5 -5
View File
@@ -28,16 +28,16 @@ Remark42 is a self-hosted, lightweight, and simple (yet functional) comment engi
| Command line | Environment | Default | Multi | Scope | Description |
| --------------- | -------------------- | ---------------------- | ----- | ------ | ------------------------------- |
| --bolt | BOLTDB_PATH | `/tmp` | no | all | path to data directory |
| --site | SITE | `remark` | yes | server | site name(s) |
| --url | REMARK_URL | `https://remark42.com` | no | all | url to remark server |
| --bolt | BOLTDB_PATH | `/tmp` | no | all | path to data directory |
| --dbg | DEBUG | `false` | no | all | debug mode |
| --dev | DEV | `false` | no | all | development mode, no auth! |
| --site | SITE | `remark` | yes | server | site name(s) |
| --admin | ADMIN | | yes | server | admin(s) names (user id) |
| --backup | BACKUP_PATH | `/tmp` | no | server | backups location |
| --max-back | MAX_BACKUP_FILES | `10` | no | server | max backup files to keep |
| --session | SESSION_STORE | `/tmp` | no | server | path to session store directory |
| --store-key | STORE_KEY | `secure-store-key` | no | server | session store encryption key |
| --dbg | DEBUG | `false` | no | all | debug mode |
| --dev | DEV | `false` | no | all | development mode, no auth! |
| --google-cid | REMARK_GOOGLE_CID | | no | server | Google OAuth client ID |
| --google-csec | REMARK_GOOGLE_CSEC | | no | server | Google OAuth client secret |
| --facebook-cid | REMARK_FACEBOOK_CID | | no | server | Facebook OAuth client ID |
@@ -168,7 +168,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 `id`
- `GET /api/v1/id/{id}?site=site-id` - get comment by `commen 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
+14 -3
View File
@@ -30,12 +30,23 @@ func (s *Service) Vote(locator Locator, commentID string, userID string, val boo
return comment, err
}
if _, voted := comment.Votes[userID]; voted {
v, voted := comment.Votes[userID]
if voted && v == val {
return comment, errors.Errorf("user %s already voted for %s", userID, commentID)
}
// update votes and score
comment.Votes[userID] = val
// reset vote if user changed to opposite
if voted && v != val {
delete(comment.Votes, userID)
}
// add to voted map if first vote
if !voted {
comment.Votes[userID] = val
}
// update score
if val {
comment.Score++
} else {
+9
View File
@@ -31,6 +31,15 @@ func TestService_Vote(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 2, len(res))
assert.Equal(t, 1, res[0].Score)
_, err = b.Vote(Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, res[0].ID, "user1", false)
assert.Nil(t, err, "vote reset")
res, err = b.Last(Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, 0)
assert.Nil(t, err)
assert.Equal(t, 2, len(res))
assert.Equal(t, 0, res[0].Score)
assert.Equal(t, map[string]bool{}, res[0].Votes)
}
func TestBoltDB_Pin(t *testing.T) {
+1 -1
View File
@@ -35,7 +35,7 @@ Content-Type: application/json
}
### pin comment
PUT https://demo.remark42.com/api/v1/admin/pin/3665976683?site=remark&url=https://radio-t.com/p/2017/12/16/podcast-576/&pin=1
PUT https://demo.remark42.com/api/v1/admin/pin/3665976683?site=remark&url=https://radio-t.com/p/2017/12/16/podcast-576/&pin=0
### vote for comment
PUT https://demo.remark42.com/api/v1/vote/3665976683?site=remark&url=https://radio-t.com/p/2017/12/16/podcast-576/&vote=1