Sticker will preload attachment

This commit is contained in:
LittleSheep 2024-08-03 22:04:44 +08:00
parent dfde530ca4
commit 75ab320bf1
3 changed files with 3 additions and 3 deletions

View File

@ -36,7 +36,7 @@ func listStickers(c *fiber.Ctx) error {
}
var stickers []models.Sticker
if err := tx.Limit(take).Offset(offset).Find(&stickers).Error; err != nil {
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)

View File

@ -15,7 +15,7 @@ func GetStickerPackWithUser(id, userId uint) (models.StickerPack, error) {
func ListStickerPackWithStickers(take, offset int) ([]models.StickerPack, error) {
var packs []models.StickerPack
if err := database.C.Limit(take).Offset(offset).Preload("Stickers").Find(&packs).Error; err != nil {
if err := database.C.Limit(take).Offset(offset).Preload("Stickers").Preload("Stickers.Attachment").Find(&packs).Error; err != nil {
return packs, err
}
return packs, nil

View File

@ -7,7 +7,7 @@ import (
func GetSticker(id uint) (models.Sticker, error) {
var sticker models.Sticker
if err := database.C.Where("id = ?", id).First(&sticker).Error; err != nil {
if err := database.C.Where("id = ?", id).Preload("Attachment").First(&sticker).Error; err != nil {
return sticker, err
}
return sticker, nil