Preload api key's ticket

This commit is contained in:
LittleSheep 2024-08-25 23:43:15 +08:00
parent 46c7b6dff1
commit 1bdeba58bc
2 changed files with 9 additions and 8 deletions

View File

@ -4,10 +4,9 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix api key wasn't in auto maintain range"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix api key missing account id">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/bot.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/bot.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/bot_token_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/bot_token_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/bot_token.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/bot_token.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -154,7 +153,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value=":bug: Fix model relation issue" />
<MESSAGE value=":arrow_up: Upgrade dealer" /> <MESSAGE value=":arrow_up: Upgrade dealer" />
<MESSAGE value=":sparkles: Support stream controller event emit" /> <MESSAGE value=":sparkles: Support stream controller event emit" />
<MESSAGE value=":recycle: Use dealer postman instead of built-in feature to deliver email and notify" /> <MESSAGE value=":recycle: Use dealer postman instead of built-in feature to deliver email and notify" />
@ -179,7 +177,8 @@
<MESSAGE value=":bug: Fix bot related bot key apis path error" /> <MESSAGE value=":bug: Fix bot related bot key apis path error" />
<MESSAGE value=":bug: Fix path parameters misplaced" /> <MESSAGE value=":bug: Fix path parameters misplaced" />
<MESSAGE value=":bug: Fix api key wasn't in auto maintain range" /> <MESSAGE value=":bug: Fix api key wasn't in auto maintain range" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix api key wasn't in auto maintain range" /> <MESSAGE value=":bug: Fix api key missing account id" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix api key missing account id" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

View File

@ -7,7 +7,6 @@ import (
"git.solsynth.dev/hydrogen/passport/pkg/internal/server/exts" "git.solsynth.dev/hydrogen/passport/pkg/internal/server/exts"
"git.solsynth.dev/hydrogen/passport/pkg/internal/services" "git.solsynth.dev/hydrogen/passport/pkg/internal/services"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"gorm.io/gorm"
) )
func listBotKeys(c *fiber.Ctx) error { func listBotKeys(c *fiber.Ctx) error {
@ -16,7 +15,7 @@ func listBotKeys(c *fiber.Ctx) error {
} }
user := c.Locals("user").(models.Account) user := c.Locals("user").(models.Account)
var tx *gorm.DB tx := database.C.Preload("Ticket")
botId, _ := c.ParamsInt("botId", 0) botId, _ := c.ParamsInt("botId", 0)
if botId > 0 { if botId > 0 {
@ -55,7 +54,10 @@ func getBotKey(c *fiber.Ctx) error {
id, _ := c.ParamsInt("id", 0) id, _ := c.ParamsInt("id", 0)
var key models.ApiKey var key models.ApiKey
if err := database.C.Where("id = ? AND account_id = ?", id, user.ID).First(&key).Error; err != nil { if err := database.C.
Where("id = ? AND account_id = ?", id, user.ID).
Preload("Ticket").
First(&key).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error()) return fiber.NewError(fiber.StatusNotFound, err.Error())
} }