diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b042984..824b840 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,10 @@
-
+
+
@@ -153,7 +154,6 @@
-
@@ -178,7 +178,8 @@
-
+
+
true
diff --git a/pkg/internal/server/api/bot_token_api.go b/pkg/internal/server/api/bot_token_api.go
index 8e419c8..d995b61 100644
--- a/pkg/internal/server/api/bot_token_api.go
+++ b/pkg/internal/server/api/bot_token_api.go
@@ -123,8 +123,21 @@ func editBotKey(c *fiber.Ctx) error {
id, _ := c.ParamsInt("id", 0)
+ var tx *gorm.DB
+
+ botId, _ := c.ParamsInt("botId", 0)
+ if botId > 0 {
+ var bot models.Account
+ if err := database.C.Where("automated_id = ? AND id = ?", user.ID, botId).First(&bot).Error; err != nil {
+ return fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("bot not found: %v", err))
+ }
+ tx = database.C.Where("account_id = ?", bot.ID)
+ } else {
+ tx = database.C.Where("account_id = ?", user.ID)
+ }
+
var key models.ApiKey
- if err := database.C.Where("id = ? AND account_id = ?", id, user.ID).First(&key).Error; err != nil {
+ if err := tx.Where("id = ?", id).First(&key).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
@@ -147,8 +160,21 @@ func rollBotKey(c *fiber.Ctx) error {
id, _ := c.ParamsInt("id", 0)
+ var tx *gorm.DB
+
+ botId, _ := c.ParamsInt("botId", 0)
+ if botId > 0 {
+ var bot models.Account
+ if err := database.C.Where("automated_id = ? AND id = ?", user.ID, botId).First(&bot).Error; err != nil {
+ return fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("bot not found: %v", err))
+ }
+ tx = database.C.Where("account_id = ?", bot.ID)
+ } else {
+ tx = database.C.Where("account_id = ?", user.ID)
+ }
+
var key models.ApiKey
- if err := database.C.Where("id = ? AND account_id = ?", id, user.ID).First(&key).Error; err != nil {
+ if err := tx.Where("id = ?", id).First(&key).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
@@ -167,8 +193,21 @@ func revokeBotKey(c *fiber.Ctx) error {
id, _ := c.ParamsInt("id", 0)
+ var tx *gorm.DB
+
+ botId, _ := c.ParamsInt("botId", 0)
+ if botId > 0 {
+ var bot models.Account
+ if err := database.C.Where("automated_id = ? AND id = ?", user.ID, botId).First(&bot).Error; err != nil {
+ return fiber.NewError(fiber.StatusNotFound, fmt.Sprintf("bot not found: %v", err))
+ }
+ tx = database.C.Where("account_id = ?", bot.ID)
+ } else {
+ tx = database.C.Where("account_id = ?", user.ID)
+ }
+
var key models.ApiKey
- if err := database.C.Where("id = ? AND account_id = ?", id, user.ID).First(&key).Error; err != nil {
+ if err := tx.Where("id = ?", id).First(&key).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
diff --git a/pkg/internal/server/api/index.go b/pkg/internal/server/api/index.go
index 57f2b23..db04fdc 100644
--- a/pkg/internal/server/api/index.go
+++ b/pkg/internal/server/api/index.go
@@ -111,6 +111,9 @@ func MapAPIs(app *fiber.App, baseURL string) {
{
keys.Get("/", listBotKeys)
keys.Post("/", createBotKey)
+ keys.Post("/:id/roll", rollBotKey)
+ keys.Put("/:id", editBotKey)
+ keys.Delete("/:id", revokeBotKey)
}
}