🐛 Fix manifest won't filter by author
This commit is contained in:
parent
dc57261b2e
commit
8b3a7d6324
@ -17,12 +17,24 @@ func listStickerManifest(c *fiber.Ctx) error {
|
||||
take = 100
|
||||
}
|
||||
|
||||
tx := database.C
|
||||
|
||||
if len(c.Query("author")) > 0 {
|
||||
var author models.Account
|
||||
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
tx = tx.Where("account_id = ?", author.ID)
|
||||
}
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := database.C.Model(&models.StickerPack{}).Count(&count).Error; err != nil {
|
||||
countTx := tx
|
||||
if err := countTx.Model(&models.StickerPack{}).Count(&count).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
stickers, err := services.ListStickerPackWithStickers(take, offset)
|
||||
stickers, err := services.ListStickerPackWithStickers(tx, take, offset)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func GetStickerPackWithUser(id, userId uint) (models.StickerPack, error) {
|
||||
@ -13,9 +14,9 @@ func GetStickerPackWithUser(id, userId uint) (models.StickerPack, error) {
|
||||
return pack, nil
|
||||
}
|
||||
|
||||
func ListStickerPackWithStickers(take, offset int) ([]models.StickerPack, error) {
|
||||
func ListStickerPackWithStickers(tx *gorm.DB, take, offset int) ([]models.StickerPack, error) {
|
||||
var packs []models.StickerPack
|
||||
if err := database.C.Limit(take).Offset(offset).Preload("Stickers").Preload("Stickers.Attachment").Find(&packs).Error; err != nil {
|
||||
if err := tx.Limit(take).Offset(offset).Preload("Stickers").Preload("Stickers.Attachment").Find(&packs).Error; err != nil {
|
||||
return packs, err
|
||||
}
|
||||
return packs, nil
|
||||
|
Loading…
Reference in New Issue
Block a user