feat: remove loop and use GetVoteCountsByPostID
This commit is contained in:
@@ -291,24 +291,7 @@ func ensureSeedUser(userRepo repositories.UserRepository, passwordHash string) (
|
|||||||
|
|
||||||
|
|
||||||
func getVoteCounts(voteRepo repositories.VoteRepository, postID uint) (int, int, error) {
|
func getVoteCounts(voteRepo repositories.VoteRepository, postID uint) (int, int, error) {
|
||||||
votes, err := voteRepo.GetByPostID(postID)
|
return voteRepo.GetVoteCountsByPostID(postID)
|
||||||
if err != nil {
|
|
||||||
return 0, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
upVotes := 0
|
|
||||||
downVotes := 0
|
|
||||||
|
|
||||||
for _, vote := range votes {
|
|
||||||
switch vote.Type {
|
|
||||||
case database.VoteUp:
|
|
||||||
upVotes++
|
|
||||||
case database.VoteDown:
|
|
||||||
downVotes++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return upVotes, downVotes, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateSeedConsistency(postRepo repositories.PostRepository, voteRepo repositories.VoteRepository, users []database.User, posts []database.Post) error {
|
func validateSeedConsistency(postRepo repositories.PostRepository, voteRepo repositories.VoteRepository, users []database.User, posts []database.Post) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user