fix: favorites issues

This commit is contained in:
Rogee
2024-09-21 14:09:23 +08:00
parent f8a7e87965
commit 63b0eb8b44
4 changed files with 27 additions and 16 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/favicon"
"github.com/gofiber/fiber/v2/middleware/filesystem"
log "github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/spf13/cobra"
)
@@ -41,6 +42,7 @@ func serveCmd(cmd *cobra.Command, args []string) error {
app.Static("/medias", "/share/telegram/outputs")
app.Use(log.New())
app.Use(favicon.New(favicon.Config{
Data: frontend.Favicon,
}))
@@ -128,10 +130,8 @@ func serveCmd(cmd *cobra.Command, args []string) error {
offsetPk := c.QueryInt("offset", 0)
tbl := table.ChannelMessages
cond := tbl.ChannelID.EQ(Int64(int64(channelID))).AND(
tbl.Like.EQ(Bool(true)),
)
cond := tbl.Favorite.EQ(Bool(true))
if offsetPk > 0 {
cond = cond.AND(tbl.ID.LT(Int64(int64(offsetPk))))
}
@@ -152,7 +152,7 @@ func serveCmd(cmd *cobra.Command, args []string) error {
})
// toggle favorite message
group.Patch("message/:message/favorite", func(c *fiber.Ctx) error {
group.Patch("messages/:message/favorite", func(c *fiber.Ctx) error {
messageID, err := c.ParamsInt("message")
if err != nil {
return err
@@ -172,11 +172,12 @@ func serveCmd(cmd *cobra.Command, args []string) error {
return err
}
_, err = tbl.
stmt := tbl.
UPDATE().
SET(tbl.Like.SET(Bool(!msg.Like))).
WHERE(tbl.ID.EQ(Int64(int64(messageID)))).
ExecContext(c.Context(), db)
SET(tbl.Favorite.SET(Bool(!msg.Favorite))).
WHERE(tbl.ID.EQ(Int64(int64(messageID))))
_, err = stmt.ExecContext(c.Context(), db)
if err != nil {
return err
}