diff --git a/internal/controller_admin/plugin_controller.go b/internal/controller_admin/plugin_controller.go index e565f2bdc..61b058b9f 100644 --- a/internal/controller_admin/plugin_controller.go +++ b/internal/controller_admin/plugin_controller.go @@ -20,6 +20,28 @@ func NewPluginController(PluginCommonService *plugin_common.PluginCommonService) return &PluginController{PluginCommonService: PluginCommonService} } +// GetAllPluginStatus get all plugins status +// @Summary get all plugins status +// @Description get all plugins status +// @Tags Plugin +// @Security ApiKeyAuth +// @Accept json +// @Produce json +// @Success 200 {object} handler.RespBody{data=[]schema.GetPluginListResp} +// @Router /answer/api/v1/plugin/status [get] +func (pc *PluginController) GetAllPluginStatus(ctx *gin.Context) { + resp := make([]*schema.GetAllPluginStatusResp, 0) + _ = plugin.CallBase(func(base plugin.Base) error { + info := base.Info() + resp = append(resp, &schema.GetAllPluginStatusResp{ + SlugName: info.SlugName, + Enabled: plugin.StatusManager.IsEnabled(info.SlugName), + }) + return nil + }) + handler.HandleResponse(ctx, nil, resp) +} + // GetPluginList get plugin list // @Summary get plugin list // @Description get plugin list diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go index a5948fccc..e109cf560 100644 --- a/internal/router/answer_api_router.go +++ b/internal/router/answer_api_router.go @@ -115,6 +115,9 @@ func (a *AnswerAPIRouter) RegisterMustUnAuthAnswerAPIRouter(authUserMiddleware * routerGroup.POST("/user/password/reset", a.userController.RetrievePassWord) routerGroup.POST("/user/password/replacement", a.userController.UseRePassWord) routerGroup.PUT("/user/notification/unsubscribe", a.userController.UserUnsubscribeNotification) + + // plugins + r.GET("/plugin/status", a.pluginController.GetAllPluginStatus) } func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) { diff --git a/internal/schema/plugin_admin_schema.go b/internal/schema/plugin_admin_schema.go index 7684e2642..1b1ea90d6 100644 --- a/internal/schema/plugin_admin_schema.go +++ b/internal/schema/plugin_admin_schema.go @@ -27,6 +27,11 @@ type GetPluginListResp struct { Link string `json:"link"` } +type GetAllPluginStatusResp struct { + SlugName string `json:"slug_name"` + Enabled bool `json:"enabled"` +} + type UpdatePluginStatusReq struct { PluginSlugName string `validate:"required,gt=1,lte=100" json:"plugin_slug_name"` Enabled bool `json:"enabled"`