Count post views

This commit is contained in:
2025-02-17 17:21:15 +08:00
parent 14c17eded8
commit 269e79ca58
11 changed files with 141 additions and 20 deletions

View File

@@ -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())
}