You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by ro...@apache.org on 2024/08/21 07:13:48 UTC
(incubator-answer) 47/49: fix(embed): embed plugin type definition
This is an automated email from the ASF dual-hosted git repository.
robin0716 pushed a commit to branch develop/robin
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 60428d002af59f5e3742c74c06a43b0ca94699f9
Author: kumfo <ku...@sifou.com>
AuthorDate: Mon Aug 19 16:15:21 2024 +0800
fix(embed): embed plugin type definition
---
docs/docs.go | 24 ++++++++++++------------
docs/swagger.json | 24 ++++++++++++------------
docs/swagger.yaml | 16 ++++++++--------
internal/controller/embed_controller.go | 22 ++++------------------
internal/schema/plugin_option_schema.go | 25 -------------------------
plugin/embed.go | 8 ++++++++
6 files changed, 44 insertions(+), 75 deletions(-)
diff --git a/docs/docs.go b/docs/docs.go
index cfefe0ed..74cbfdd0 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -3115,7 +3115,7 @@ const docTemplate = `{
"data": {
"type": "array",
"items": {
- "$ref": "#/definitions/schema.GetEmbedOptionResp"
+ "$ref": "#/definitions/plugin.EmbedConfig"
}
}
}
@@ -7409,6 +7409,17 @@ const docTemplate = `{
"list": {}
}
},
+ "plugin.EmbedConfig": {
+ "type": "object",
+ "properties": {
+ "enable": {
+ "type": "boolean"
+ },
+ "platform": {
+ "type": "string"
+ }
+ }
+ },
"schema.AcceptAnswerReq": {
"type": "object",
"required": [
@@ -8368,17 +8379,6 @@ const docTemplate = `{
}
}
},
- "schema.GetEmbedOptionResp": {
- "type": "object",
- "properties": {
- "enable": {
- "type": "boolean"
- },
- "platform": {
- "type": "string"
- }
- }
- },
"schema.GetFollowingTagsResp": {
"type": "object",
"properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 234d2f13..3da2384a 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -3085,7 +3085,7 @@
"data": {
"type": "array",
"items": {
- "$ref": "#/definitions/schema.GetEmbedOptionResp"
+ "$ref": "#/definitions/plugin.EmbedConfig"
}
}
}
@@ -7379,6 +7379,17 @@
"list": {}
}
},
+ "plugin.EmbedConfig": {
+ "type": "object",
+ "properties": {
+ "enable": {
+ "type": "boolean"
+ },
+ "platform": {
+ "type": "string"
+ }
+ }
+ },
"schema.AcceptAnswerReq": {
"type": "object",
"required": [
@@ -8338,17 +8349,6 @@
}
}
},
- "schema.GetEmbedOptionResp": {
- "type": "object",
- "properties": {
- "enable": {
- "type": "boolean"
- },
- "platform": {
- "type": "string"
- }
- }
- },
"schema.GetFollowingTagsResp": {
"type": "object",
"properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 1a5979e6..19510978 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -127,6 +127,13 @@ definitions:
type: integer
list: {}
type: object
+ plugin.EmbedConfig:
+ properties:
+ enable:
+ type: boolean
+ platform:
+ type: string
+ type: object
schema.AcceptAnswerReq:
properties:
answer_id:
@@ -798,13 +805,6 @@ definitions:
description: website
type: string
type: object
- schema.GetEmbedOptionResp:
- properties:
- enable:
- type: boolean
- platform:
- type: string
- type: object
schema.GetFollowingTagsResp:
properties:
display_name:
@@ -4738,7 +4738,7 @@ paths:
- properties:
data:
items:
- $ref: '#/definitions/schema.GetEmbedOptionResp'
+ $ref: '#/definitions/plugin.EmbedConfig'
type: array
type: object
summary: GetEmbedConfig
diff --git a/internal/controller/embed_controller.go b/internal/controller/embed_controller.go
index c9691d29..a61bd68c 100644
--- a/internal/controller/embed_controller.go
+++ b/internal/controller/embed_controller.go
@@ -21,7 +21,6 @@ package controller
import (
"github.com/apache/incubator-answer/internal/base/handler"
- "github.com/apache/incubator-answer/internal/schema"
"github.com/apache/incubator-answer/plugin"
"github.com/gin-gonic/gin"
)
@@ -40,27 +39,14 @@ func NewEmbedController() *EmbedController {
// @Accept json
// @Produce json
// @Router /answer/api/v1/embed/config [get]
-// @Success 200 {object} handler.RespBody{data=[]schema.GetEmbedOptionResp}
+// @Success 200 {object} handler.RespBody{data=[]plugin.EmbedConfig}
func (c *EmbedController) GetEmbedConfig(ctx *gin.Context) {
- resp := make([]*schema.GetEmbedOptionResp, 0)
- var slugName string
+ resp := make([]*plugin.EmbedConfig, 0)
- _ = plugin.CallEmbed(func(base plugin.Embed) error {
- slugName = base.Info().SlugName
+ _ = plugin.CallEmbed(func(embed plugin.Embed) (err error) {
+ resp, err = embed.GetEmbedConfigs(ctx)
return nil
})
- _ = plugin.CallConfig(func(fn plugin.Config) error {
- if fn.Info().SlugName == slugName {
- for _, field := range fn.ConfigFields() {
- resp = append(resp, &schema.GetEmbedOptionResp{
- Platform: field.Name,
- Enable: field.Value.(bool),
- })
- }
- return nil
- }
- return nil
- })
handler.HandleResponse(ctx, nil, resp)
}
diff --git a/internal/schema/plugin_option_schema.go b/internal/schema/plugin_option_schema.go
deleted file mode 100644
index 8db22973..00000000
--- a/internal/schema/plugin_option_schema.go
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package schema
-
-type GetEmbedOptionResp struct {
- Platform string `json:"platform"`
- Enable bool `json:"enable"`
-}
diff --git a/plugin/embed.go b/plugin/embed.go
index 55149f66..e853c8c2 100644
--- a/plugin/embed.go
+++ b/plugin/embed.go
@@ -19,8 +19,16 @@
package plugin
+import "github.com/gin-gonic/gin"
+
+type EmbedConfig struct {
+ Platform string `json:"platform"`
+ Enable bool `json:"enable"`
+}
+
type Embed interface {
Base
+ GetEmbedConfigs(ctx *gin.Context) (embedConfigs []*EmbedConfig, err error)
}
var (