From 51a53a25da45e5db0b735d641d1c452539c96dad Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 26 Aug 2024 00:33:57 +0800 Subject: [PATCH] :bug: Fix preloading issue --- .idea/workspace.xml | 6 +++--- pkg/internal/server/api/bot_token_api.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c278aec..b042984 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,7 +4,7 @@ - @@ -178,7 +177,8 @@ - true diff --git a/pkg/internal/server/api/bot_token_api.go b/pkg/internal/server/api/bot_token_api.go index 87cfb96..8e419c8 100644 --- a/pkg/internal/server/api/bot_token_api.go +++ b/pkg/internal/server/api/bot_token_api.go @@ -7,6 +7,7 @@ import ( "git.solsynth.dev/hydrogen/passport/pkg/internal/server/exts" "git.solsynth.dev/hydrogen/passport/pkg/internal/services" "github.com/gofiber/fiber/v2" + "gorm.io/gorm" ) func listBotKeys(c *fiber.Ctx) error { @@ -15,7 +16,7 @@ func listBotKeys(c *fiber.Ctx) error { } user := c.Locals("user").(models.Account) - tx := database.C.Preload("Ticket") + var tx *gorm.DB botId, _ := c.ParamsInt("botId", 0) if botId > 0 { @@ -35,7 +36,7 @@ func listBotKeys(c *fiber.Ctx) error { } var keys []models.ApiKey - if err := tx.Find(&keys).Error; err != nil { + if err := tx.Preload("Ticket").Find(&keys).Error; err != nil { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) }