From 876cfa9956e7d679164927a6345037e936f98440 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 25 Aug 2024 17:03:06 +0800 Subject: [PATCH] :sparkles: Pagination bots api --- .idea/workspace.xml | 55 ++++++++++++------------ pkg/internal/server/api/bot_token_api.go | 17 ++++++-- pkg/internal/server/api/bots_api.go | 17 ++++++-- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1f6ae4e..e566224 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,9 +6,8 @@ - - - + + - { - "keyToString": { - "DefaultGoTemplateProperty": "Go File", - "Go Build.Backend.executor": "Run", - "Go 构建.Backend.executor": "Run", - "RunOnceActivity.ShowReadmeOnStart": "true", - "RunOnceActivity.go.formatter.settings.were.checked": "true", - "RunOnceActivity.go.migrated.go.modules.settings": "true", - "RunOnceActivity.go.modules.automatic.dependencies.download": "true", - "RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true", - "git-widget-placeholder": "master", - "go.import.settings.migrated": "true", - "go.sdk.automatically.set": "true", - "last_opened_file_path": "/Users/littlesheep", - "node.js.detected.package.eslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "nodejs_package_manager_path": "npm", - "run.code.analysis.last.selected.profile": "pProject Default", - "settings.editor.selected.configurable": "preferences.pluginManager", - "ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib", - "vue.rearranger.settings.migration": "true" + +}]]> diff --git a/pkg/internal/server/api/bot_token_api.go b/pkg/internal/server/api/bot_token_api.go index 3542b83..bf0252b 100644 --- a/pkg/internal/server/api/bot_token_api.go +++ b/pkg/internal/server/api/bot_token_api.go @@ -14,12 +14,23 @@ func listBotKeys(c *fiber.Ctx) error { } user := c.Locals("user").(models.Account) - var keys []models.ApiKey - if err := database.C.Where("account_id = ?", user.ID).Find(&keys).Error; err != nil { + tx := database.C.Where("account_id = ?", user.ID) + + countTx := tx + var count int64 + if err := countTx.Model(&models.ApiKey{}).Count(&count).Error; err != nil { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) } - return c.JSON(keys) + var keys []models.ApiKey + if err := tx.Find(&keys).Error; err != nil { + return fiber.NewError(fiber.StatusInternalServerError, err.Error()) + } + + return c.JSON(fiber.Map{ + "count": count, + "data": keys, + }) } func getBotKey(c *fiber.Ctx) error { diff --git a/pkg/internal/server/api/bots_api.go b/pkg/internal/server/api/bots_api.go index fdeb860..1628316 100644 --- a/pkg/internal/server/api/bots_api.go +++ b/pkg/internal/server/api/bots_api.go @@ -18,12 +18,23 @@ func listBots(c *fiber.Ctx) error { } user := c.Locals("user").(models.Account) - var bots []models.Account - if err := database.C.Where("automated_id = ?", user.AutomatedID).Find(&bots).Error; err != nil { + tx := database.C.Where("automated_id = ?", user.AutomatedID) + + countTx := tx + var count int64 + if err := countTx.Model(&models.Account{}).Count(&count).Error; err != nil { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) } - return c.JSON(bots) + var bots []models.Account + if err := tx.Find(&bots).Error; err != nil { + return fiber.NewError(fiber.StatusInternalServerError, err.Error()) + } + + return c.JSON(fiber.Map{ + "count": count, + "data": bots, + }) } func createBot(c *fiber.Ctx) error {