A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: Add RenderController to handle rendering configuration
robin1af1f77a60af
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.goindex cc245aea..940c0dc1 100644--- a/cmd/wire_gen.go+++ b/cmd/wire_gen.go@@ -282,7 +282,8 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,userCenterController := controller.NewUserCenterController(userCenterLoginService, siteInfoCommonService)captchaController := controller.NewCaptchaController()embedController := controller.NewEmbedController()- pluginAPIRouter := router.NewPluginAPIRouter(connectorController, userCenterController, captchaController, embedController)+ renderController := controller.NewRenderController()+ pluginAPIRouter := router.NewPluginAPIRouter(connectorController, userCenterController, captchaController, embedController, renderController)ginEngine := server.NewHTTPServer(debug, staticRouter, answerAPIRouter, swaggerRouter, uiRouter, authUserMiddleware, avatarMiddleware, shortIDMiddleware, templateRouter, pluginAPIRouter, uiConf)scheduledTaskManager := cron.NewScheduledTaskManager(siteInfoCommonService, questionService)application := newApplication(serverConf, ginEngine, scheduledTaskManager)diff --git a/internal/controller/controller.go b/internal/controller/controller.goindex 8fad918a..cbf80f7f 100644--- a/internal/controller/controller.go+++ b/internal/controller/controller.go@@ -52,4 +52,5 @@ var ProviderSetController = wire.NewSet(NewMetaController,NewEmbedController,NewBadgeController,+ NewRenderController,)diff --git a/internal/controller/render_controller.go b/internal/controller/render_controller.gonew file mode 100644index 00000000..05e49d0b--- /dev/null+++ b/internal/controller/render_controller.go@@ -0,0 +1,52 @@+/*+ * 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 controller++import (+ "github.com/apache/incubator-answer/internal/base/handler"+ "github.com/apache/incubator-answer/plugin"+ "github.com/gin-gonic/gin"+)++type RenderController struct {+}++func NewRenderController() *RenderController {+ return &RenderController{}+}++// GetRenderConfig godoc+// @Summary GetRenderConfig+// @Description GetRenderConfig+// @Tags PluginRender+// @Accept json+// @Produce json+// @Router /answer/api/v1/render/config [get]+// @Success 200 {object} handler.RespBody{data=plugin.RenderConfig}+func (c *RenderController) GetRenderConfig(ctx *gin.Context) {+ var resp *plugin.RenderConfig++ _ = plugin.CallRender(func(render plugin.Render) (err error) {+ resp = render.GetRenderConfig(ctx)+ return nil+ })++ handler.HandleResponse(ctx, nil, resp)+}diff --git a/internal/router/plugin_api_router.go b/internal/router/plugin_api_router.goindex e4a85a15..e69e0b6b 100644--- a/internal/router/plugin_api_router.go+++ b/internal/router/plugin_api_router.go@@ -29,6 +29,7 @@ type PluginAPIRouter struct {userCenterController *controller.UserCenterControllercaptchaController *controller.CaptchaControllerembedController *controller.EmbedController+ renderController *controller.RenderController}func NewPluginAPIRouter(@@ -36,12 +37,14 @@ func NewPluginAPIRouter(userCenterController *controller.UserCenterController,captchaController *controller.CaptchaController,embedController *controller.EmbedController,+ renderController *controller.RenderController,) *PluginAPIRouter {return &PluginAPIRouter{connectorController: connectorController,userCenterController: userCenterController,captchaController: captchaController,embedController: embedController,+ renderController: renderController,}}@@ -64,6 +67,7 @@ func (pr *PluginAPIRouter) RegisterUnAuthConnectorRouter(r *gin.RouterGroup) {// captcha pluginr.GET("/captcha/config", pr.captchaController.GetCaptchaConfig)r.GET("/embed/config", pr.embedController.GetEmbedConfig)+ r.GET("/render/config", pr.renderController.GetRenderConfig)}func (pr *PluginAPIRouter) RegisterAuthUserConnectorRouter(r *gin.RouterGroup) {diff --git a/plugin/plugin.go b/plugin/plugin.goindex 85286855..9c144346 100644--- a/plugin/plugin.go+++ b/plugin/plugin.go@@ -103,6 +103,10 @@ func Register(p Base) {registerEmbed(p.(Embed))}+ if _, ok := p.(Render); ok {+ registerRender(p.(Render))+ }+if _, ok := p.(CDN); ok {registerCDN(p.(CDN))}diff --git a/plugin/render.go b/plugin/render.gonew file mode 100644index 00000000..4fc2edf6--- /dev/null+++ b/plugin/render.go@@ -0,0 +1,39 @@+/*+ * 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 plugin++import "github.com/gin-gonic/gin"++type RenderConfig struct {+ SelectTheme string `json:"select_theme"`+}++// select_theme++type Render interface {+ Base+ GetRenderConfig(ctx *gin.Context) (renderConfig *RenderConfig)+}++var (+ // CallReviewer is a function that calls all registered parsers+ CallRender,+ registerRender = MakePlugin[Render](false)+)