🐛 Fix bot related key api issue
This commit is contained in:
		
							
								
								
									
										7
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										7
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@@ -4,9 +4,10 @@
 | 
			
		||||
    <option name="autoReloadType" value="ALL" />
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="ChangeListManager">
 | 
			
		||||
    <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Preload api key's ticket">
 | 
			
		||||
    <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix preloading issue">
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/server/api/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/index.go" afterDir="false" />
 | 
			
		||||
    </list>
 | 
			
		||||
    <option name="SHOW_DIALOG" value="false" />
 | 
			
		||||
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
 | 
			
		||||
@@ -153,7 +154,6 @@
 | 
			
		||||
    </option>
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="VcsManagerConfiguration">
 | 
			
		||||
    <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=":bug: Fix push notification to wrong person" />
 | 
			
		||||
    <MESSAGE value=":sparkles: Account groups" />
 | 
			
		||||
@@ -178,7 +178,8 @@
 | 
			
		||||
    <MESSAGE value=":bug: Fix api key wasn't in auto maintain range" />
 | 
			
		||||
    <MESSAGE value=":bug: Fix api key missing account id" />
 | 
			
		||||
    <MESSAGE value=":sparkles: Preload api key's ticket" />
 | 
			
		||||
    <option name="LAST_COMMIT_MESSAGE" value=":sparkles: Preload api key's ticket" />
 | 
			
		||||
    <MESSAGE value=":bug: Fix preloading issue" />
 | 
			
		||||
    <option name="LAST_COMMIT_MESSAGE" value=":bug: Fix preloading issue" />
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="VgoProject">
 | 
			
		||||
    <settings-migrated>true</settings-migrated>
 | 
			
		||||
 
 | 
			
		||||
@@ -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())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user