This is an automated email from the ASF dual-hosted git repository.

kumfo pushed a commit to branch feat/1.4.0/embed
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 1d9f88f803cb6427c9eb7d1166436494a2314d83
Author: kumfo <[email protected]>
AuthorDate: Mon Aug 19 16:15:21 2024 +0800

    fix(embed): embed plugin type definition
---
 docs/docs.go                            | 90 ++++++++++++++++++++++++--------
 docs/swagger.json                       | 92 ++++++++++++++++++++++++---------
 docs/swagger.yaml                       | 65 ++++++++++++++++-------
 internal/controller/embed_controller.go | 22 ++------
 internal/schema/plugin_option_schema.go | 25 ---------
 plugin/embed.go                         |  8 +++
 6 files changed, 195 insertions(+), 107 deletions(-)

diff --git a/docs/docs.go b/docs/docs.go
index cf1264d1..fab0d8e9 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -2738,7 +2738,7 @@ const docTemplate = `{
                                         "data": {
                                             "type": "array",
                                             "items": {
-                                                "$ref": 
"#/definitions/schema.GetEmbedOptionResp"
+                                                "$ref": 
"#/definitions/plugin.EmbedConfig"
                                             }
                                         }
                                     }
@@ -4410,7 +4410,7 @@ const docTemplate = `{
                                         "data": {
                                             "type": "array",
                                             "items": {
-                                                "$ref": 
"#/definitions/schema.GetTagResp"
+                                                "$ref": 
"#/definitions/schema.GetTagBasicResp"
                                             }
                                         }
                                     }
@@ -5380,7 +5380,7 @@ const docTemplate = `{
         },
         "/answer/api/v1/tags": {
             "get": {
-                "description": "get tags list",
+                "description": "get tags list by slug name",
                 "produces": [
                     "application/json"
                 ],
@@ -5404,7 +5404,22 @@ const docTemplate = `{
                     "200": {
                         "description": "OK",
                         "schema": {
-                            "$ref": "#/definitions/handler.RespBody"
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/handler.RespBody"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": 
"#/definitions/schema.GetTagBasicResp"
+                                            }
+                                        }
+                                    }
+                                }
+                            ]
                         }
                     }
                 }
@@ -6571,14 +6586,14 @@ const docTemplate = `{
         },
         "/custom.css": {
             "get": {
-                "description": "get site robots information",
+                "description": "get site custom CSS",
                 "produces": [
-                    "application/json"
+                    "text/css"
                 ],
                 "tags": [
                     "site"
                 ],
-                "summary": "get site robots information",
+                "summary": "get site custom CSS",
                 "responses": {
                     "200": {
                         "description": "OK",
@@ -7004,6 +7019,17 @@ const docTemplate = `{
                 "list": {}
             }
         },
+        "plugin.EmbedConfig": {
+            "type": "object",
+            "properties": {
+                "enable": {
+                    "type": "boolean"
+                },
+                "platform": {
+                    "type": "string"
+                }
+            }
+        },
         "schema.AcceptAnswerReq": {
             "type": "object",
             "required": [
@@ -7813,17 +7839,6 @@ const docTemplate = `{
                 }
             }
         },
-        "schema.GetEmbedOptionResp": {
-            "type": "object",
-            "properties": {
-                "enable": {
-                    "type": "boolean"
-                },
-                "platform": {
-                    "type": "string"
-                }
-            }
-        },
         "schema.GetFollowingTagsResp": {
             "type": "object",
             "properties": {
@@ -8242,6 +8257,23 @@ const docTemplate = `{
                 }
             }
         },
+        "schema.GetTagBasicResp": {
+            "type": "object",
+            "properties": {
+                "display_name": {
+                    "type": "string"
+                },
+                "recommend": {
+                    "type": "boolean"
+                },
+                "reserved": {
+                    "type": "boolean"
+                },
+                "slug_name": {
+                    "type": "string"
+                }
+            }
+        },
         "schema.GetTagPageResp": {
             "type": "object",
             "properties": {
@@ -9819,7 +9851,7 @@ const docTemplate = `{
                 "recommend_tags": {
                     "type": "array",
                     "items": {
-                        "type": "string"
+                        "$ref": "#/definitions/schema.SiteWriteTag"
                     }
                 },
                 "required_tag": {
@@ -9828,7 +9860,7 @@ const docTemplate = `{
                 "reserved_tags": {
                     "type": "array",
                     "items": {
-                        "type": "string"
+                        "$ref": "#/definitions/schema.SiteWriteTag"
                     }
                 },
                 "restrict_answer": {
@@ -9842,7 +9874,7 @@ const docTemplate = `{
                 "recommend_tags": {
                     "type": "array",
                     "items": {
-                        "type": "string"
+                        "$ref": "#/definitions/schema.SiteWriteTag"
                     }
                 },
                 "required_tag": {
@@ -9851,7 +9883,7 @@ const docTemplate = `{
                 "reserved_tags": {
                     "type": "array",
                     "items": {
-                        "type": "string"
+                        "$ref": "#/definitions/schema.SiteWriteTag"
                     }
                 },
                 "restrict_answer": {
@@ -9859,6 +9891,20 @@ const docTemplate = `{
                 }
             }
         },
+        "schema.SiteWriteTag": {
+            "type": "object",
+            "required": [
+                "slug_name"
+            ],
+            "properties": {
+                "display_name": {
+                    "type": "string"
+                },
+                "slug_name": {
+                    "type": "string"
+                }
+            }
+        },
         "schema.TagItem": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 1e93d2b0..9ea2d2ee 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -2708,7 +2708,7 @@
                                         "data": {
                                             "type": "array",
                                             "items": {
-                                                "$ref": 
"#/definitions/schema.GetEmbedOptionResp"
+                                                "$ref": 
"#/definitions/plugin.EmbedConfig"
                                             }
                                         }
                                     }
@@ -4380,7 +4380,7 @@
                                         "data": {
                                             "type": "array",
                                             "items": {
-                                                "$ref": 
"#/definitions/schema.GetTagResp"
+                                                "$ref": 
"#/definitions/schema.GetTagBasicResp"
                                             }
                                         }
                                     }
@@ -5350,7 +5350,7 @@
         },
         "/answer/api/v1/tags": {
             "get": {
-                "description": "get tags list",
+                "description": "get tags list by slug name",
                 "produces": [
                     "application/json"
                 ],
@@ -5374,7 +5374,22 @@
                     "200": {
                         "description": "OK",
                         "schema": {
-                            "$ref": "#/definitions/handler.RespBody"
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/handler.RespBody"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "type": "array",
+                                            "items": {
+                                                "$ref": 
"#/definitions/schema.GetTagBasicResp"
+                                            }
+                                        }
+                                    }
+                                }
+                            ]
                         }
                     }
                 }
@@ -6541,14 +6556,14 @@
         },
         "/custom.css": {
             "get": {
-                "description": "get site robots information",
+                "description": "get site custom CSS",
                 "produces": [
-                    "application/json"
+                    "text/css"
                 ],
                 "tags": [
                     "site"
                 ],
-                "summary": "get site robots information",
+                "summary": "get site custom CSS",
                 "responses": {
                     "200": {
                         "description": "OK",
@@ -6974,6 +6989,17 @@
                 "list": {}
             }
         },
+        "plugin.EmbedConfig": {
+            "type": "object",
+            "properties": {
+                "enable": {
+                    "type": "boolean"
+                },
+                "platform": {
+                    "type": "string"
+                }
+            }
+        },
         "schema.AcceptAnswerReq": {
             "type": "object",
             "required": [
@@ -7783,17 +7809,6 @@
                 }
             }
         },
-        "schema.GetEmbedOptionResp": {
-            "type": "object",
-            "properties": {
-                "enable": {
-                    "type": "boolean"
-                },
-                "platform": {
-                    "type": "string"
-                }
-            }
-        },
         "schema.GetFollowingTagsResp": {
             "type": "object",
             "properties": {
@@ -8212,6 +8227,23 @@
                 }
             }
         },
+        "schema.GetTagBasicResp": {
+            "type": "object",
+            "properties": {
+                "display_name": {
+                    "type": "string"
+                },
+                "recommend": {
+                    "type": "boolean"
+                },
+                "reserved": {
+                    "type": "boolean"
+                },
+                "slug_name": {
+                    "type": "string"
+                }
+            }
+        },
         "schema.GetTagPageResp": {
             "type": "object",
             "properties": {
@@ -8809,7 +8841,7 @@
                     "enum": [
                         "newest",
                         "active",
-                        "frequent",
+                        "hot",
                         "score",
                         "unanswered"
                     ]
@@ -9789,7 +9821,7 @@
                 "recommend_tags": {
                     "type": "array",
                     "items": {
-                        "type": "string"
+                        "$ref": "#/definitions/schema.SiteWriteTag"
                     }
                 },
                 "required_tag": {
@@ -9798,7 +9830,7 @@
                 "reserved_tags": {
                     "type": "array",
                     "items": {
-                        "type": "string"
+                        "$ref": "#/definitions/schema.SiteWriteTag"
                     }
                 },
                 "restrict_answer": {
@@ -9812,7 +9844,7 @@
                 "recommend_tags": {
                     "type": "array",
                     "items": {
-                        "type": "string"
+                        "$ref": "#/definitions/schema.SiteWriteTag"
                     }
                 },
                 "required_tag": {
@@ -9821,7 +9853,7 @@
                 "reserved_tags": {
                     "type": "array",
                     "items": {
-                        "type": "string"
+                        "$ref": "#/definitions/schema.SiteWriteTag"
                     }
                 },
                 "restrict_answer": {
@@ -9829,6 +9861,20 @@
                 }
             }
         },
+        "schema.SiteWriteTag": {
+            "type": "object",
+            "required": [
+                "slug_name"
+            ],
+            "properties": {
+                "display_name": {
+                    "type": "string"
+                },
+                "slug_name": {
+                    "type": "string"
+                }
+            }
+        },
         "schema.TagItem": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 93f8116a..1b176960 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -117,6 +117,13 @@ definitions:
         type: integer
       list: {}
     type: object
+  plugin.EmbedConfig:
+    properties:
+      enable:
+        type: boolean
+      platform:
+        type: string
+    type: object
   schema.AcceptAnswerReq:
     properties:
       answer_id:
@@ -687,13 +694,6 @@ definitions:
         description: website
         type: string
     type: object
-  schema.GetEmbedOptionResp:
-    properties:
-      enable:
-        type: boolean
-      platform:
-        type: string
-    type: object
   schema.GetFollowingTagsResp:
     properties:
       display_name:
@@ -983,6 +983,17 @@ definitions:
       terms_of_service_parsed_text:
         type: string
     type: object
+  schema.GetTagBasicResp:
+    properties:
+      display_name:
+        type: string
+      recommend:
+        type: boolean
+      reserved:
+        type: boolean
+      slug_name:
+        type: string
+    type: object
   schema.GetTagPageResp:
     properties:
       created_at:
@@ -1401,7 +1412,7 @@ definitions:
         enum:
         - newest
         - active
-        - frequent
+        - hot
         - score
         - unanswered
         type: string
@@ -2071,13 +2082,13 @@ definitions:
     properties:
       recommend_tags:
         items:
-          type: string
+          $ref: '#/definitions/schema.SiteWriteTag'
         type: array
       required_tag:
         type: boolean
       reserved_tags:
         items:
-          type: string
+          $ref: '#/definitions/schema.SiteWriteTag'
         type: array
       restrict_answer:
         type: boolean
@@ -2086,17 +2097,26 @@ definitions:
     properties:
       recommend_tags:
         items:
-          type: string
+          $ref: '#/definitions/schema.SiteWriteTag'
         type: array
       required_tag:
         type: boolean
       reserved_tags:
         items:
-          type: string
+          $ref: '#/definitions/schema.SiteWriteTag'
         type: array
       restrict_answer:
         type: boolean
     type: object
+  schema.SiteWriteTag:
+    properties:
+      display_name:
+        type: string
+      slug_name:
+        type: string
+    required:
+    - slug_name
+    type: object
   schema.TagItem:
     properties:
       display_name:
@@ -4353,7 +4373,7 @@ paths:
             - properties:
                 data:
                   items:
-                    $ref: '#/definitions/schema.GetEmbedOptionResp'
+                    $ref: '#/definitions/plugin.EmbedConfig'
                   type: array
               type: object
       summary: GetEmbedConfig
@@ -5382,7 +5402,7 @@ paths:
             - properties:
                 data:
                   items:
-                    $ref: '#/definitions/schema.GetTagResp'
+                    $ref: '#/definitions/schema.GetTagBasicResp'
                   type: array
               type: object
       security:
@@ -5965,7 +5985,7 @@ paths:
       - Tag
   /answer/api/v1/tags:
     get:
-      description: get tags list
+      description: get tags list by slug name
       parameters:
       - collectionFormat: csv
         description: string collection
@@ -5980,7 +6000,14 @@ paths:
         "200":
           description: OK
           schema:
-            $ref: '#/definitions/handler.RespBody'
+            allOf:
+            - $ref: '#/definitions/handler.RespBody'
+            - properties:
+                data:
+                  items:
+                    $ref: '#/definitions/schema.GetTagBasicResp'
+                  type: array
+              type: object
       summary: get tags list
       tags:
       - Tag
@@ -6677,15 +6704,15 @@ paths:
       - Activity
   /custom.css:
     get:
-      description: get site robots information
+      description: get site custom CSS
       produces:
-      - application/json
+      - text/css
       responses:
         "200":
           description: OK
           schema:
             type: string
-      summary: get site robots information
+      summary: get site custom CSS
       tags:
       - site
   /installation/base-info:
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 (

Reply via email to