🐛 Fix reaction and comment didn't count in spec api
This commit is contained in:
parent
562af023f1
commit
97e1d1f87e
@ -40,7 +40,9 @@ func getPost(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
item.ReactionList, err = mx.CountReactions(item.ID)
|
item.CommentCount = mx.CountComments(item.ID)
|
||||||
|
item.ReactionCount = mx.CountReactions(item.ID)
|
||||||
|
item.ReactionList, err = mx.ListReactions(item.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,29 @@ func (v *PostTypeContext) Count() (int64, error) {
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *PostTypeContext) CountReactions(id uint) (map[string]int64, error) {
|
func (v *PostTypeContext) CountComments(id uint) int64 {
|
||||||
|
var count int64
|
||||||
|
if err := database.C.Model(&models.Comment{}).
|
||||||
|
Where(v.ColumnName+"_id = ?", id).
|
||||||
|
Count(&count).Error; err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *PostTypeContext) CountReactions(id uint) int64 {
|
||||||
|
var count int64
|
||||||
|
if err := database.C.Model(&models.Reaction{}).
|
||||||
|
Where(v.ColumnName+"_id = ?", id).
|
||||||
|
Count(&count).Error; err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *PostTypeContext) ListReactions(id uint) (map[string]int64, error) {
|
||||||
var reactions []struct {
|
var reactions []struct {
|
||||||
Symbol string
|
Symbol string
|
||||||
Count int64
|
Count int64
|
||||||
|
Loading…
Reference in New Issue
Block a user