✨ Each post has total down/upvote count
This commit is contained in:
parent
37aa69e6ca
commit
30399be718
@ -34,6 +34,9 @@ type Post struct {
|
||||
PublishedAt *time.Time `json:"published_at"`
|
||||
PublishedUntil *time.Time `json:"published_until"`
|
||||
|
||||
TotalUpvote int `json:"total_upvote"`
|
||||
TotalDownvote int `json:"total_downvote"`
|
||||
|
||||
AuthorID uint `json:"author_id"`
|
||||
Author Account `json:"author"`
|
||||
|
||||
|
@ -295,6 +295,13 @@ func ReactPost(user models.Account, reaction models.Reaction) (bool, models.Reac
|
||||
err = database.C.Save(&reaction).Error
|
||||
if err == nil {
|
||||
_ = ModifyPosterVoteCount(op.Author, reaction.Attitude == models.AttitudePositive, 1)
|
||||
|
||||
if reaction.Attitude == models.AttitudePositive {
|
||||
op.TotalUpvote++
|
||||
} else {
|
||||
op.TotalDownvote++
|
||||
}
|
||||
database.C.Save(&op)
|
||||
}
|
||||
|
||||
return true, reaction, err
|
||||
@ -305,6 +312,13 @@ func ReactPost(user models.Account, reaction models.Reaction) (bool, models.Reac
|
||||
err = database.C.Delete(&reaction).Error
|
||||
if err == nil {
|
||||
_ = ModifyPosterVoteCount(op.Author, reaction.Attitude == models.AttitudePositive, -1)
|
||||
|
||||
if reaction.Attitude == models.AttitudePositive {
|
||||
op.TotalUpvote--
|
||||
} else {
|
||||
op.TotalDownvote--
|
||||
}
|
||||
database.C.Save(&op)
|
||||
}
|
||||
|
||||
return false, reaction, err
|
||||
|
Loading…
Reference in New Issue
Block a user