Pagination bots api

This commit is contained in:
2024-08-25 17:03:06 +08:00
parent 7a585ec5b9
commit 876cfa9956
3 changed files with 55 additions and 34 deletions

View File

@ -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 {

View File

@ -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 {