✨ Count post views
This commit is contained in:
@@ -24,6 +24,11 @@ func getWhatsNew(c *fiber.Ctx) error {
|
||||
|
||||
tx = tx.Where("id > ?", pivot)
|
||||
|
||||
var userId *uint
|
||||
if user, authenticated := c.Locals("user").(authm.Account); authenticated {
|
||||
userId = &user.ID
|
||||
}
|
||||
|
||||
countTx := tx
|
||||
count, err := services.CountPost(countTx)
|
||||
if err != nil {
|
||||
@@ -35,7 +40,7 @@ func getWhatsNew(c *fiber.Ctx) error {
|
||||
order = "published_at DESC, (COALESCE(total_upvote, 0) - COALESCE(total_downvote, 0)) DESC"
|
||||
}
|
||||
|
||||
items, err := services.ListPost(tx, 10, 0, order)
|
||||
items, err := services.ListPost(tx, 10, 0, order, userId)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
Reference in New Issue
Block a user