🐛 Just forgot to add pagination data into response

This commit is contained in:
LittleSheep 2024-08-03 22:45:50 +08:00
parent 75ab320bf1
commit c381b53a29
2 changed files with 30 additions and 3 deletions

View File

@ -17,11 +17,20 @@ func listStickerManifest(c *fiber.Ctx) error {
take = 100
}
var count int64
if err := database.C.Model(&models.StickerPack{}).Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
stickers, err := services.ListStickerPackWithStickers(take, offset)
if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(stickers)
return c.JSON(fiber.Map{
"count": count,
"data": stickers,
})
}
func listStickerPacks(c *fiber.Ctx) error {
@ -43,11 +52,20 @@ func listStickerPacks(c *fiber.Ctx) error {
}
}
var count int64
if err := database.C.Model(&models.StickerPack{}).Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
var packs []models.StickerPack
if err := tx.Limit(take).Offset(offset).Find(&packs).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(packs)
return c.JSON(fiber.Map{
"count": count,
"data": packs,
})
}
func createStickerPack(c *fiber.Ctx) error {

View File

@ -35,11 +35,20 @@ func listStickers(c *fiber.Ctx) error {
tx = tx.Where("pack_id = ?", val)
}
var count int64
if err := database.C.Model(&models.Sticker{}).Count(&count).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
var stickers []models.Sticker
if err := tx.Limit(take).Offset(offset).Preload("Attachment").Find(&stickers).Error; err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(stickers)
return c.JSON(fiber.Map{
"count": count,
"data": stickers,
})
}
func getSticker(c *fiber.Ctx) error {