fix: favorites issues
This commit is contained in:
@@ -21,5 +21,5 @@ type ChannelMessages struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
GroupID int64
|
GroupID int64
|
||||||
Published bool
|
Published bool
|
||||||
Like bool
|
Favorite bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type channelMessagesTable struct {
|
|||||||
CreatedAt postgres.ColumnTimestampz
|
CreatedAt postgres.ColumnTimestampz
|
||||||
GroupID postgres.ColumnInteger
|
GroupID postgres.ColumnInteger
|
||||||
Published postgres.ColumnBool
|
Published postgres.ColumnBool
|
||||||
Like postgres.ColumnBool
|
Favorite postgres.ColumnBool
|
||||||
|
|
||||||
AllColumns postgres.ColumnList
|
AllColumns postgres.ColumnList
|
||||||
MutableColumns postgres.ColumnList
|
MutableColumns postgres.ColumnList
|
||||||
@@ -76,9 +76,9 @@ func newChannelMessagesTableImpl(schemaName, tableName, alias string) channelMes
|
|||||||
CreatedAtColumn = postgres.TimestampzColumn("created_at")
|
CreatedAtColumn = postgres.TimestampzColumn("created_at")
|
||||||
GroupIDColumn = postgres.IntegerColumn("group_id")
|
GroupIDColumn = postgres.IntegerColumn("group_id")
|
||||||
PublishedColumn = postgres.BoolColumn("published")
|
PublishedColumn = postgres.BoolColumn("published")
|
||||||
LikeColumn = postgres.BoolColumn("like")
|
FavoriteColumn = postgres.BoolColumn("favorite")
|
||||||
allColumns = postgres.ColumnList{IDColumn, ChannelIDColumn, UUIDColumn, ContentColumn, MediaColumn, PublishedAtColumn, CreatedAtColumn, GroupIDColumn, PublishedColumn, LikeColumn}
|
allColumns = postgres.ColumnList{IDColumn, ChannelIDColumn, UUIDColumn, ContentColumn, MediaColumn, PublishedAtColumn, CreatedAtColumn, GroupIDColumn, PublishedColumn, FavoriteColumn}
|
||||||
mutableColumns = postgres.ColumnList{ChannelIDColumn, UUIDColumn, ContentColumn, MediaColumn, PublishedAtColumn, CreatedAtColumn, GroupIDColumn, PublishedColumn, LikeColumn}
|
mutableColumns = postgres.ColumnList{ChannelIDColumn, UUIDColumn, ContentColumn, MediaColumn, PublishedAtColumn, CreatedAtColumn, GroupIDColumn, PublishedColumn, FavoriteColumn}
|
||||||
)
|
)
|
||||||
|
|
||||||
return channelMessagesTable{
|
return channelMessagesTable{
|
||||||
@@ -94,7 +94,7 @@ func newChannelMessagesTableImpl(schemaName, tableName, alias string) channelMes
|
|||||||
CreatedAt: CreatedAtColumn,
|
CreatedAt: CreatedAtColumn,
|
||||||
GroupID: GroupIDColumn,
|
GroupID: GroupIDColumn,
|
||||||
Published: PublishedColumn,
|
Published: PublishedColumn,
|
||||||
Like: LikeColumn,
|
Favorite: FavoriteColumn,
|
||||||
|
|
||||||
AllColumns: allColumns,
|
AllColumns: allColumns,
|
||||||
MutableColumns: mutableColumns,
|
MutableColumns: mutableColumns,
|
||||||
|
|||||||
@@ -12,14 +12,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2">
|
<div class="grid grid-cols-2">
|
||||||
<button class="py-2 bg-slate-100 hover:bg-slate-50 text-center">Like</button>
|
<button class="py-2 bg-slate-100 hover:bg-slate-50 text-center" @click="toggleLike()">
|
||||||
|
{{ item.Favorite ? 'Unlike' : 'Like' }}
|
||||||
|
</button>
|
||||||
<button class="py-2 bg-slate-100 hover:bg-slate-50 text-center text-red-600" @click="delMessage()">Delete</button>
|
<button class="py-2 bg-slate-100 hover:bg-slate-50 text-center text-red-600" @click="delMessage()">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { deleteMessage } from "@/services/messages";
|
import { deleteMessage, toggleFavorite } from "@/services/messages";
|
||||||
import { computed, defineComponent } from "vue";
|
import { computed, defineComponent } from "vue";
|
||||||
import MediaItem from "./MediaItem.vue";
|
import MediaItem from "./MediaItem.vue";
|
||||||
|
|
||||||
@@ -43,6 +45,13 @@ export default defineComponent({
|
|||||||
return nl2br(content, false);
|
return nl2br(content, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const toggleLike = async () => {
|
||||||
|
const itemId = props.item.ID
|
||||||
|
await toggleFavorite(itemId);
|
||||||
|
props.item.Favorite = !props.item.Favorite;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const delMessage = async () => {
|
const delMessage = async () => {
|
||||||
console.log("delMessage")
|
console.log("delMessage")
|
||||||
if (!confirm("Are you sure?")) {
|
if (!confirm("Are you sure?")) {
|
||||||
@@ -73,6 +82,7 @@ export default defineComponent({
|
|||||||
item: props.item,
|
item: props.item,
|
||||||
processedContent,
|
processedContent,
|
||||||
delMessage,
|
delMessage,
|
||||||
|
toggleLike,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/favicon"
|
"github.com/gofiber/fiber/v2/middleware/favicon"
|
||||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||||
|
log "github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -41,6 +42,7 @@ func serveCmd(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
app.Static("/medias", "/share/telegram/outputs")
|
app.Static("/medias", "/share/telegram/outputs")
|
||||||
|
|
||||||
|
app.Use(log.New())
|
||||||
app.Use(favicon.New(favicon.Config{
|
app.Use(favicon.New(favicon.Config{
|
||||||
Data: frontend.Favicon,
|
Data: frontend.Favicon,
|
||||||
}))
|
}))
|
||||||
@@ -128,10 +130,8 @@ func serveCmd(cmd *cobra.Command, args []string) error {
|
|||||||
offsetPk := c.QueryInt("offset", 0)
|
offsetPk := c.QueryInt("offset", 0)
|
||||||
|
|
||||||
tbl := table.ChannelMessages
|
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 {
|
if offsetPk > 0 {
|
||||||
cond = cond.AND(tbl.ID.LT(Int64(int64(offsetPk))))
|
cond = cond.AND(tbl.ID.LT(Int64(int64(offsetPk))))
|
||||||
}
|
}
|
||||||
@@ -152,7 +152,7 @@ func serveCmd(cmd *cobra.Command, args []string) error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// toggle favorite message
|
// 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")
|
messageID, err := c.ParamsInt("message")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -172,11 +172,12 @@ func serveCmd(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tbl.
|
stmt := tbl.
|
||||||
UPDATE().
|
UPDATE().
|
||||||
SET(tbl.Like.SET(Bool(!msg.Like))).
|
SET(tbl.Favorite.SET(Bool(!msg.Favorite))).
|
||||||
WHERE(tbl.ID.EQ(Int64(int64(messageID)))).
|
WHERE(tbl.ID.EQ(Int64(int64(messageID))))
|
||||||
ExecContext(c.Context(), db)
|
|
||||||
|
_, err = stmt.ExecContext(c.Context(), db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user