add unlimited votes constant to avoid magic -1 value on the caller side

This commit is contained in:
Umputun
2018-11-24 12:13:07 -06:00
parent f8517fd6a8
commit 1432ec44d7
2 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ func prep(t *testing.T) (srv *Rest, ts *httptest.Server) {
EditDuration: 5 * time.Minute,
MaxCommentSize: 4000,
AdminStore: adminStore,
MaxVotes: -1,
MaxVotes: service.UnlimitedVotes,
}
srv = &Rest{
DataService: dataStore,
+5 -3
View File
@@ -29,7 +29,9 @@ type DataStore struct {
}
const defaultCommentMaxSize = 2000
const defaultVotesLimit = -1 // unlimited
// UnlimitedVotes doesn't restrict MaxVotes
const UnlimitedVotes = -1
// Create prepares comment and forward to Interface.Create
func (s *DataStore) Create(comment store.Comment) (commentID string, err error) {
@@ -100,8 +102,8 @@ func (s *DataStore) Vote(locator store.Locator, commentID string, userID string,
}
maxVotes := s.MaxVotes
if s.MaxVotes < 0 {
maxVotes = defaultVotesLimit
if s.MaxVotes <= 0 {
maxVotes = UnlimitedVotes
}
if maxVotes >= 0 && len(comment.Votes) >= maxVotes {