chore: import upstream snapshot with attribution
CI / Check and lint (push) Failing after 1s
Lint / Lint (ubuntu-latest) (push) Failing after 1s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:22:32 +08:00
commit 39dbe3a57d
1131 changed files with 272709 additions and 0 deletions
@@ -0,0 +1,123 @@
/*
* 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_admin
import (
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/schema"
"github.com/apache/answer/internal/service/ai_conversation"
"github.com/apache/answer/internal/service/feature_toggle"
"github.com/gin-gonic/gin"
)
// AIConversationAdminController ai conversation admin controller
type AIConversationAdminController struct {
aiConversationService ai_conversation.AIConversationService
featureToggleSvc *feature_toggle.FeatureToggleService
}
// NewAIConversationAdminController new AI conversation admin controller
func NewAIConversationAdminController(
aiConversationService ai_conversation.AIConversationService,
featureToggleSvc *feature_toggle.FeatureToggleService,
) *AIConversationAdminController {
return &AIConversationAdminController{
aiConversationService: aiConversationService,
featureToggleSvc: featureToggleSvc,
}
}
func (ctrl *AIConversationAdminController) ensureEnabled(ctx *gin.Context) bool {
if ctrl.featureToggleSvc == nil {
return true
}
if err := ctrl.featureToggleSvc.EnsureEnabled(ctx, feature_toggle.FeatureAIChatbot); err != nil {
handler.HandleResponse(ctx, err, nil)
return false
}
return true
}
// GetConversationList gets conversation list
// @Summary get conversation list for admin
// @Description get conversation list for admin
// @Tags ai-conversation-admin
// @Accept json
// @Produce json
// @Param page query int false "page"
// @Param page_size query int false "page size"
// @Success 200 {object} handler.RespBody{data=pager.PageModel{list=[]schema.AIConversationAdminListItem}}
// @Router /answer/admin/api/ai/conversation/page [get]
func (ctrl *AIConversationAdminController) GetConversationList(ctx *gin.Context) {
if !ctrl.ensureEnabled(ctx) {
return
}
req := &schema.AIConversationAdminListReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := ctrl.aiConversationService.GetConversationListForAdmin(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// GetConversationDetail get conversation detail
// @Summary get conversation detail for admin
// @Description get conversation detail for admin
// @Tags ai-conversation-admin
// @Accept json
// @Produce json
// @Param conversation_id query string true "conversation id"
// @Success 200 {object} handler.RespBody{data=schema.AIConversationAdminDetailResp}
// @Router /answer/admin/api/ai/conversation [get]
func (ctrl *AIConversationAdminController) GetConversationDetail(ctx *gin.Context) {
if !ctrl.ensureEnabled(ctx) {
return
}
req := &schema.AIConversationAdminDetailReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := ctrl.aiConversationService.GetConversationDetailForAdmin(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// DeleteConversation delete conversation
// @Summary delete conversation for admin
// @Description delete conversation and its related records for admin
// @Tags ai-conversation-admin
// @Accept json
// @Produce json
// @Param data body schema.AIConversationAdminDeleteReq true "apikey"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/ai/conversation [delete]
func (ctrl *AIConversationAdminController) DeleteConversation(ctx *gin.Context) {
if !ctrl.ensureEnabled(ctx) {
return
}
req := &schema.AIConversationAdminDeleteReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := ctrl.aiConversationService.DeleteConversationForAdmin(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
@@ -0,0 +1,86 @@
/*
* 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_admin
import (
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/base/pager"
"github.com/apache/answer/internal/schema"
"github.com/apache/answer/internal/service/badge"
"github.com/gin-gonic/gin"
)
type BadgeController struct {
badgeService *badge.BadgeService
}
func NewBadgeController(badgeService *badge.BadgeService) *BadgeController {
return &BadgeController{
badgeService: badgeService,
}
}
// GetBadgeList list all badges by page
// @Summary list all badges by page
// @Description list all badges by page
// @Tags AdminBadge
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param page query int false "page"
// @Param page_size query int false "page size"
// @Param status query string false "badge status" Enums(, active, inactive)
// @Param q query string false "search param"
// @Success 200 {object} handler.RespBody{data=[]schema.GetBadgeListPagedResp}
// @Router /answer/admin/api/badges [get]
func (b *BadgeController) GetBadgeList(ctx *gin.Context) {
req := &schema.GetBadgeListPagedReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, total, err := b.badgeService.ListPaged(ctx, req)
if err != nil {
handler.HandleResponse(ctx, err, nil)
return
}
handler.HandleResponse(ctx, nil, pager.NewPageModel(total, resp))
}
// UpdateBadgeStatus update badge status
// @Summary update badge status
// @Description update badge status
// @Tags AdminBadge
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param data body schema.UpdateBadgeStatusReq true "UpdateBadgeStatusReq"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/badge/status [put]
func (b *BadgeController) UpdateBadgeStatus(ctx *gin.Context) {
req := &schema.UpdateBadgeStatusReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := b.badgeService.UpdateStatus(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
+34
View File
@@ -0,0 +1,34 @@
/*
* 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_admin
import "github.com/google/wire"
// ProviderSetController is controller providers.
var ProviderSetController = wire.NewSet(
NewUserAdminController,
NewThemeController,
NewSiteInfoController,
NewRoleController,
NewPluginController,
NewBadgeController,
NewAdminAPIKeyController,
NewAIConversationAdminController,
)
@@ -0,0 +1,116 @@
/*
* 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_admin
import (
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/base/middleware"
"github.com/apache/answer/internal/schema"
"github.com/apache/answer/internal/service/apikey"
"github.com/gin-gonic/gin"
)
// AdminAPIKeyController site info controller
type AdminAPIKeyController struct {
apiKeyService *apikey.APIKeyService
}
// NewAdminAPIKeyController new site info controller
func NewAdminAPIKeyController(apiKeyService *apikey.APIKeyService) *AdminAPIKeyController {
return &AdminAPIKeyController{
apiKeyService: apiKeyService,
}
}
// GetAllAPIKeys get all api keys
// @Summary get all api keys
// @Description get all api keys
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=[]schema.GetAPIKeyResp}
// @Router /answer/admin/api/api-key/all [get]
func (sc *AdminAPIKeyController) GetAllAPIKeys(ctx *gin.Context) {
resp, err := sc.apiKeyService.GetAPIKeyList(ctx, &schema.GetAPIKeyReq{})
handler.HandleResponse(ctx, err, resp)
}
// AddAPIKey add apikey
// @Summary add apikey
// @Description add apikey
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.AddAPIKeyReq true "apikey"
// @Success 200 {object} handler.RespBody{data=schema.AddAPIKeyResp}
// @Router /answer/admin/api/api-key [post]
func (sc *AdminAPIKeyController) AddAPIKey(ctx *gin.Context) {
req := &schema.AddAPIKeyReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
resp, err := sc.apiKeyService.AddAPIKey(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UpdateAPIKey update apikey
// @Summary update apikey
// @Description update apikey
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.UpdateAPIKeyReq true "apikey"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/api-key [put]
func (sc *AdminAPIKeyController) UpdateAPIKey(ctx *gin.Context) {
req := &schema.UpdateAPIKeyReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
err := sc.apiKeyService.UpdateAPIKey(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// DeleteAPIKey delete apikey
// @Summary delete apikey
// @Description delete apikey
// @Security ApiKeyAuth
// @Tags admin
// @Param data body schema.DeleteAPIKeyReq true "apikey"
// @Produce json
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/api-key [delete]
func (sc *AdminAPIKeyController) DeleteAPIKey(ctx *gin.Context) {
req := &schema.DeleteAPIKeyReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
err := sc.apiKeyService.DeleteAPIKey(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
@@ -0,0 +1,224 @@
/*
* 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_admin
import (
"encoding/json"
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/schema"
"github.com/apache/answer/internal/service/plugin_common"
"github.com/apache/answer/plugin"
"github.com/gin-gonic/gin"
)
// PluginController role controller
type PluginController struct {
pluginCommonService *plugin_common.PluginCommonService
}
// NewPluginController new controller
func NewPluginController(pluginCommonService *plugin_common.PluginCommonService) *PluginController {
return &PluginController{pluginCommonService: pluginCommonService}
}
// GetAllPluginStatus get all plugins status
// @Summary get all plugins status
// @Description get all plugins status
// @Tags Plugin
// @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
// @Tags AdminPlugin
// @Security ApiKeyAuth
// @Accept json
// @Produce json
// @Param status query string false "status: active/inactive"
// @Param have_config query boolean false "have config"
// @Success 200 {object} handler.RespBody{data=[]schema.GetPluginListResp}
// @Router /answer/admin/api/plugins [get]
func (pc *PluginController) GetPluginList(ctx *gin.Context) {
req := &schema.GetPluginListReq{}
if handler.BindAndCheck(ctx, req) {
return
}
pluginConfigMapping := make(map[string]bool)
_ = plugin.CallConfig(func(fn plugin.Config) error {
if len(fn.ConfigFields()) > 0 {
pluginConfigMapping[fn.Info().SlugName] = true
}
return nil
})
resp := make([]*schema.GetPluginListResp, 0)
_ = plugin.CallBase(func(base plugin.Base) error {
info := base.Info()
resp = append(resp, &schema.GetPluginListResp{
Name: info.Name.Translate(ctx),
SlugName: info.SlugName,
Description: info.Description.Translate(ctx),
Version: info.Version,
Enabled: plugin.StatusManager.IsEnabled(info.SlugName),
HaveConfig: pluginConfigMapping[info.SlugName],
Link: info.Link,
})
return nil
})
if len(req.Status) > 0 {
resp = pc.filterPluginByStatus(resp, req.Status)
}
if req.HaveConfig {
resp = pc.filterNoConfigPlugin(resp)
}
handler.HandleResponse(ctx, nil, resp)
}
func (pc *PluginController) filterNoConfigPlugin(list []*schema.GetPluginListResp) []*schema.GetPluginListResp {
resp := make([]*schema.GetPluginListResp, 0)
for _, t := range list {
if t.HaveConfig {
resp = append(resp, t)
}
}
return resp
}
func (pc *PluginController) filterPluginByStatus(list []*schema.GetPluginListResp, status schema.PluginStatus,
) []*schema.GetPluginListResp {
resp := make([]*schema.GetPluginListResp, 0)
for _, t := range list {
if status == schema.PluginStatusActive && t.Enabled {
resp = append(resp, t)
} else if status == schema.PluginStatusInactive && !t.Enabled {
resp = append(resp, t)
}
}
return resp
}
// UpdatePluginStatus update plugin status
// @Summary update plugin status
// @Description update plugin status
// @Tags AdminPlugin
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param data body schema.UpdatePluginStatusReq true "UpdatePluginStatusReq"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/plugin/status [put]
func (pc *PluginController) UpdatePluginStatus(ctx *gin.Context) {
req := &schema.UpdatePluginStatusReq{}
if handler.BindAndCheck(ctx, req) {
return
}
plugin.StatusManager.Enable(req.PluginSlugName, req.Enabled)
err := pc.pluginCommonService.UpdatePluginStatus(ctx)
handler.HandleResponse(ctx, err, nil)
}
// GetPluginConfig get plugin config
// @Summary get plugin config
// @Description get plugin config
// @Tags AdminPlugin
// @Security ApiKeyAuth
// @Produce json
// @Param plugin_slug_name query string true "plugin_slug_name"
// @Success 200 {object} handler.RespBody{data=schema.GetPluginConfigResp}
// @Router /answer/admin/api/plugin/config [get]
func (pc *PluginController) GetPluginConfig(ctx *gin.Context) {
req := &schema.GetPluginConfigReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp := &schema.GetPluginConfigResp{}
_ = plugin.CallBase(func(base plugin.Base) error {
if base.Info().SlugName != req.PluginSlugName {
return nil
}
info := base.Info()
resp.Name = info.Name.Translate(ctx)
resp.SlugName = info.SlugName
resp.Description = info.Description.Translate(ctx)
resp.Version = info.Version
return nil
})
_ = plugin.CallConfig(func(fn plugin.Config) error {
if fn.Info().SlugName != req.PluginSlugName {
return nil
}
resp.SetConfigFields(ctx, fn.ConfigFields())
return nil
})
handler.HandleResponse(ctx, nil, resp)
}
// UpdatePluginConfig update plugin config
// @Summary update plugin config
// @Description update plugin config
// @Tags AdminPlugin
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param data body schema.UpdatePluginConfigReq true "UpdatePluginConfigReq"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/plugin/config [put]
func (pc *PluginController) UpdatePluginConfig(ctx *gin.Context) {
req := &schema.UpdatePluginConfigReq{}
if handler.BindAndCheck(ctx, req) {
return
}
configFields, _ := json.Marshal(req.ConfigFields)
err := plugin.CallConfig(func(fn plugin.Config) error {
if fn.Info().SlugName == req.PluginSlugName {
return fn.ConfigReceiver(configFields)
}
return nil
})
if err != nil {
handler.HandleResponse(ctx, err, nil)
return
}
err = pc.pluginCommonService.UpdatePluginConfig(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
@@ -0,0 +1,54 @@
/*
* 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_admin
import (
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/schema"
service "github.com/apache/answer/internal/service/role"
"github.com/gin-gonic/gin"
)
// RoleController role controller
type RoleController struct {
roleService *service.RoleService
}
// NewRoleController new controller
func NewRoleController(roleService *service.RoleService) *RoleController {
return &RoleController{roleService: roleService}
}
// GetRoleList get role list
// @Summary get role list
// @Description get role list
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=[]schema.GetRoleResp}
// @Router /answer/admin/api/roles [get]
func (rc *RoleController) GetRoleList(ctx *gin.Context) {
req := &schema.GetRoleResp{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := rc.roleService.GetRoleList(ctx)
handler.HandleResponse(ctx, err, resp)
}
@@ -0,0 +1,689 @@
/*
* 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_admin
import (
"html"
"net/http"
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/base/middleware"
"github.com/apache/answer/internal/schema"
"github.com/apache/answer/internal/service/siteinfo"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/log"
)
// SiteInfoController site info controller
type SiteInfoController struct {
siteInfoService *siteinfo.SiteInfoService
}
// NewSiteInfoController new site info controller
func NewSiteInfoController(siteInfoService *siteinfo.SiteInfoService) *SiteInfoController {
return &SiteInfoController{
siteInfoService: siteInfoService,
}
}
// GetGeneral get site general information
// @Summary get site general information
// @Description get site general information
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteGeneralResp}
// @Router /answer/admin/api/siteinfo/general [get]
func (sc *SiteInfoController) GetGeneral(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteGeneral(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetInterface get site interface
// @Summary get site interface
// @Description get site interface
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteInterfaceSettingsResp}
// @Router /answer/admin/api/siteinfo/interface [get]
func (sc *SiteInfoController) GetInterface(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteInterface(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetUsersSettings get site interface
// @Summary get site interface
// @Description get site interface
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteUsersSettingsResp}
// @Router /answer/admin/api/siteinfo/users-settings [get]
func (sc *SiteInfoController) GetUsersSettings(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteUsersSettings(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteBranding get site interface
// @Summary get site interface
// @Description get site interface
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteBrandingResp}
// @Router /answer/admin/api/siteinfo/branding [get]
func (sc *SiteInfoController) GetSiteBranding(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteBranding(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteTag get site tags setting
// @Summary get site tags setting
// @Description get site tags setting
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteTagsResp}
// @Router /answer/admin/api/siteinfo/tag [get]
func (sc *SiteInfoController) GetSiteTag(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteTag(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteQuestion get site questions setting
// @Summary get site questions setting
// @Description get site questions setting
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteQuestionsResp}
// @Router /answer/admin/api/siteinfo/question [get]
func (sc *SiteInfoController) GetSiteQuestion(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteQuestion(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteAdvanced get site advanced setting
// @Summary get site advanced setting
// @Description get site advanced setting
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteAdvancedResp}
// @Router /answer/admin/api/siteinfo/advanced [get]
func (sc *SiteInfoController) GetSiteAdvanced(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteAdvanced(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSitePolicies Get the policies information for the site
// @Summary Get the policies information for the site
// @Description Get the policies information for the site
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SitePoliciesResp}
// @Router /answer/admin/api/siteinfo/polices [get]
func (sc *SiteInfoController) GetSitePolicies(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSitePolicies(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteSecurity Get the security information for the site
// @Summary Get the security information for the site
// @Description Get the security information for the site
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteSecurityResp}
// @Router /answer/admin/api/siteinfo/security [get]
func (sc *SiteInfoController) GetSiteSecurity(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteSecurity(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSeo get site seo information
// @Summary get site seo information
// @Description get site seo information
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteSeoResp}
// @Router /answer/admin/api/siteinfo/seo [get]
func (sc *SiteInfoController) GetSeo(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSeo(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteLogin get site info login config
// @Summary get site info login config
// @Description get site info login config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteLoginResp}
// @Router /answer/admin/api/siteinfo/login [get]
func (sc *SiteInfoController) GetSiteLogin(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteLogin(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteCustomCssHTML get site info custom html css config
// @Summary get site info custom html css config
// @Description get site info custom html css config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteCustomCssHTMLResp}
// @Router /answer/admin/api/siteinfo/custom-css-html [get]
func (sc *SiteInfoController) GetSiteCustomCssHTML(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteCustomCssHTML(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteTheme get site info theme config
// @Summary get site info theme config
// @Description get site info theme config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteThemeResp}
// @Router /answer/admin/api/siteinfo/theme [get]
func (sc *SiteInfoController) GetSiteTheme(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteTheme(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetSiteUsers get site user config
// @Summary get site user config
// @Description get site user config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteUsersResp}
// @Router /answer/admin/api/siteinfo/users [get]
func (sc *SiteInfoController) GetSiteUsers(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteUsers(ctx)
handler.HandleResponse(ctx, err, resp)
}
// GetRobots get site robots information
// @Summary get site robots information
// @Description get site robots information
// @Tags site
// @Produce json
// @Success 200 {string} txt ""
// @Router /robots.txt [get]
func (sc *SiteInfoController) GetRobots(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSeo(ctx)
if err != nil {
ctx.String(http.StatusOK, "")
return
}
ctx.String(http.StatusOK, resp.Robots)
}
// GetCss get site custom CSS
// @Summary get site custom CSS
// @Description get site custom CSS
// @Tags site
// @Produce text/css
// @Success 200 {string} css ""
// @Router /custom.css [get]
func (sc *SiteInfoController) GetCss(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteCustomCssHTML(ctx)
if err != nil {
ctx.String(http.StatusOK, "")
return
}
ctx.Header("content-type", "text/css;charset=utf-8")
ctx.String(http.StatusOK, resp.CustomCss)
}
// UpdateSeo update site seo information
// @Summary update site seo information
// @Description update site seo information
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteSeoReq true "seo"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/seo [put]
func (sc *SiteInfoController) UpdateSeo(ctx *gin.Context) {
req := schema.SiteSeoReq{}
if handler.BindAndCheck(ctx, &req) {
return
}
err := sc.siteInfoService.SaveSeo(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateGeneral update site general information
// @Summary update site general information
// @Description update site general information
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteGeneralReq true "general"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/general [put]
func (sc *SiteInfoController) UpdateGeneral(ctx *gin.Context) {
req := schema.SiteGeneralReq{}
if handler.BindAndCheck(ctx, &req) {
return
}
err := sc.siteInfoService.SaveSiteGeneral(ctx, req)
req.Name = html.UnescapeString(req.Name)
handler.HandleResponse(ctx, err, req)
}
// UpdateInterface update site interface
// @Summary update site info interface
// @Description update site info interface
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteInterfaceReq true "general"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/interface [put]
func (sc *SiteInfoController) UpdateInterface(ctx *gin.Context) {
req := schema.SiteInterfaceReq{}
if handler.BindAndCheck(ctx, &req) {
return
}
err := sc.siteInfoService.SaveSiteInterface(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateUsersSettings update users settings
// @Summary update site info users settings
// @Description update site info users settings
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteUsersSettingsReq true "general"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/users-settings [put]
func (sc *SiteInfoController) UpdateUsersSettings(ctx *gin.Context) {
req := schema.SiteUsersSettingsReq{}
if handler.BindAndCheck(ctx, &req) {
return
}
err := sc.siteInfoService.SaveSiteUsersSettings(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateBranding update site branding
// @Summary update site info branding
// @Description update site info branding
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteBrandingReq true "branding info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/branding [put]
func (sc *SiteInfoController) UpdateBranding(ctx *gin.Context) {
req := &schema.SiteBrandingReq{}
if handler.BindAndCheck(ctx, req) {
return
}
currentBranding, getBrandingErr := sc.siteInfoService.GetSiteBranding(ctx)
if getBrandingErr == nil {
cleanUpErr := sc.siteInfoService.CleanUpRemovedBrandingFiles(ctx, req, currentBranding)
if cleanUpErr != nil {
log.Errorf("failed to clean up removed branding file(s): %v", cleanUpErr)
}
} else {
log.Errorf("failed to get current site branding: %v", getBrandingErr)
}
saveErr := sc.siteInfoService.SaveSiteBranding(ctx, req)
handler.HandleResponse(ctx, saveErr, nil)
}
// UpdateSiteQuestion update site question settings
// @Summary update site question settings
// @Description update site question settings
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteQuestionsReq true "questions settings"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/question [put]
func (sc *SiteInfoController) UpdateSiteQuestion(ctx *gin.Context) {
req := &schema.SiteQuestionsReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := sc.siteInfoService.SaveSiteQuestions(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UpdateSiteTag update site tag settings
// @Summary update site tag settings
// @Description update site tag settings
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteTagsReq true "tags settings"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/tag [put]
func (sc *SiteInfoController) UpdateSiteTag(ctx *gin.Context) {
req := &schema.SiteTagsReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
resp, err := sc.siteInfoService.SaveSiteTags(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UpdateSiteAdvanced update site advanced info
// @Summary update site advanced info
// @Description update site advanced info
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteAdvancedReq true "advanced settings"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/advanced [put]
func (sc *SiteInfoController) UpdateSiteAdvanced(ctx *gin.Context) {
req := &schema.SiteAdvancedReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := sc.siteInfoService.SaveSiteAdvanced(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UpdateSitePolices update site policies configuration
// @Summary update site policies configuration
// @Description update site policies configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SitePoliciesReq true "write info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/polices [put]
func (sc *SiteInfoController) UpdateSitePolices(ctx *gin.Context) {
req := &schema.SitePoliciesReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSitePolicies(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateSiteSecurity update site security configuration
// @Summary update site security configuration
// @Description update site security configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteSecurityReq true "write info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/security [put]
func (sc *SiteInfoController) UpdateSiteSecurity(ctx *gin.Context) {
req := &schema.SiteSecurityReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteSecurity(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateSiteLogin update site login
// @Summary update site login
// @Description update site login
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteLoginReq true "login info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/login [put]
func (sc *SiteInfoController) UpdateSiteLogin(ctx *gin.Context) {
req := &schema.SiteLoginReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteLogin(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateSiteCustomCssHTML update site custom css html config
// @Summary update site custom css html config
// @Description update site custom css html config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteCustomCssHTMLReq true "login info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/custom-css-html [put]
func (sc *SiteInfoController) UpdateSiteCustomCssHTML(ctx *gin.Context) {
req := &schema.SiteCustomCssHTMLReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteCustomCssHTML(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// SaveSiteTheme update site custom css html config
// @Summary update site custom css html config
// @Description update site custom css html config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteThemeReq true "login info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/theme [put]
func (sc *SiteInfoController) SaveSiteTheme(ctx *gin.Context) {
req := &schema.SiteThemeReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteTheme(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateSiteUsers update site config about users
// @Summary update site info config about users
// @Description update site info config about users
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteUsersReq true "users info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/users [put]
func (sc *SiteInfoController) UpdateSiteUsers(ctx *gin.Context) {
req := &schema.SiteUsersReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteUsers(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetSMTPConfig get smtp config
// @Summary GetSMTPConfig get smtp config
// @Description GetSMTPConfig get smtp config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.GetSMTPConfigResp}
// @Router /answer/admin/api/setting/smtp [get]
func (sc *SiteInfoController) GetSMTPConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSMTPConfig(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdateSMTPConfig update smtp config
// @Summary update smtp config
// @Description update smtp config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.UpdateSMTPConfigReq true "smtp config"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/setting/smtp [put]
func (sc *SiteInfoController) UpdateSMTPConfig(ctx *gin.Context) {
req := &schema.UpdateSMTPConfigReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.UpdateSMTPConfig(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetPrivilegesConfig get privileges config
// @Summary GetPrivilegesConfig get privileges config
// @Description GetPrivilegesConfig get privileges config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.GetPrivilegesConfigResp}
// @Router /answer/admin/api/setting/privileges [get]
func (sc *SiteInfoController) GetPrivilegesConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetPrivilegesConfig(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdatePrivilegesConfig update privileges config
// @Summary update privileges config
// @Description update privileges config
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.UpdatePrivilegesConfigReq true "config"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/setting/privileges [put]
func (sc *SiteInfoController) UpdatePrivilegesConfig(ctx *gin.Context) {
req := &schema.UpdatePrivilegesConfigReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.UpdatePrivilegesConfig(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetAIConfig get AI configuration
// @Summary get AI configuration
// @Description get AI configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteAIResp}
// @Router /answer/admin/api/ai-config [get]
func (sc *SiteInfoController) GetAIConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteAI(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdateAIConfig update AI configuration
// @Summary update AI configuration
// @Description update AI configuration
// @Security ApiKeyAuth
// @Tags admin
// @Param data body schema.SiteAIReq true "AI config"
// @Produce json
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/ai-config [put]
func (sc *SiteInfoController) UpdateAIConfig(ctx *gin.Context) {
req := &schema.SiteAIReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteAI(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetAIProvider get AI provider configuration
// @Summary get AI provider configuration
// @Description get AI provider configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=[]schema.GetAIProviderResp}
// @Router /answer/admin/api/ai-provider [get]
func (sc *SiteInfoController) GetAIProvider(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetAIProvider(ctx)
if err != nil {
handler.HandleResponse(ctx, err, nil)
return
}
handler.HandleResponse(ctx, nil, resp)
}
// RequestAIModels get AI models
// @Summary get AI models
// @Description get AI models
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=[]schema.GetAIModelResp}
// @Router /answer/admin/api/ai-models [post]
func (sc *SiteInfoController) RequestAIModels(ctx *gin.Context) {
req := &schema.GetAIModelsReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := sc.siteInfoService.GetAIModels(ctx, req)
if err != nil {
handler.HandleResponse(ctx, err, nil)
return
}
handler.HandleResponse(ctx, nil, resp)
}
// GetMCPConfig get MCP configuration
// @Summary get MCP configuration
// @Description get MCP configuration
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteMCPResp}
// @Router /answer/admin/api/mcp-config [get]
func (sc *SiteInfoController) GetMCPConfig(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteMCP(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UpdateMCPConfig update MCP configuration
// @Summary update MCP configuration
// @Description update MCP configuration
// @Security ApiKeyAuth
// @Tags admin
// @Param data body schema.SiteMCPReq true "MCP config"
// @Produce json
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/mcp-config [put]
func (sc *SiteInfoController) UpdateMCPConfig(ctx *gin.Context) {
req := &schema.SiteMCPReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := sc.siteInfoService.SaveSiteMCP(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
@@ -0,0 +1,45 @@
/*
* 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_admin
import (
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/schema"
"github.com/gin-gonic/gin"
)
type ThemeController struct{}
// NewThemeController new theme controller.
func NewThemeController() *ThemeController {
return &ThemeController{}
}
// GetThemeOptions godoc
// @Summary Get theme options
// @Description Get theme options
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/theme/options [get]
func (t *ThemeController) GetThemeOptions(ctx *gin.Context) {
handler.HandleResponse(ctx, nil, schema.GetThemeOptions)
}
@@ -0,0 +1,264 @@
/*
* 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_admin
import (
"github.com/apache/answer/internal/base/handler"
"github.com/apache/answer/internal/base/middleware"
"github.com/apache/answer/internal/base/reason"
"github.com/apache/answer/internal/base/translator"
"github.com/apache/answer/internal/schema"
"github.com/apache/answer/internal/service/user_admin"
"github.com/apache/answer/plugin"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
)
// UserAdminController user controller
type UserAdminController struct {
userService *user_admin.UserAdminService
}
// NewUserAdminController new controller
func NewUserAdminController(userService *user_admin.UserAdminService) *UserAdminController {
return &UserAdminController{userService: userService}
}
// UpdateUserStatus update user
// @Summary update user
// @Description update user
// @Security ApiKeyAuth
// @Tags admin
// @Accept json
// @Produce json
// @Param data body schema.UpdateUserStatusReq true "user"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/user/status [put]
func (uc *UserAdminController) UpdateUserStatus(ctx *gin.Context) {
if u, ok := plugin.GetUserCenter(); ok && u.Description().UserStatusAgentEnabled {
handler.HandleResponse(ctx, errors.Forbidden(reason.ForbiddenError), nil)
return
}
req := &schema.UpdateUserStatusReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
err := uc.userService.UpdateUserStatus(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// UpdateUserRole update user role
// @Summary update user role
// @Description update user role
// @Security ApiKeyAuth
// @Tags admin
// @Accept json
// @Produce json
// @Param data body schema.UpdateUserRoleReq true "user"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/user/role [put]
func (uc *UserAdminController) UpdateUserRole(ctx *gin.Context) {
req := &schema.UpdateUserRoleReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
err := uc.userService.UpdateUserRole(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// AddUser add user
// @Summary add user
// @Description add user
// @Security ApiKeyAuth
// @Tags admin
// @Accept json
// @Produce json
// @Param data body schema.AddUserReq true "user"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/user [post]
func (uc *UserAdminController) AddUser(ctx *gin.Context) {
req := &schema.AddUserReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
err := uc.userService.AddUser(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// AddUsers add users
// @Summary add users
// @Description add users
// @Security ApiKeyAuth
// @Tags admin
// @Accept json
// @Produce json
// @Param data body schema.AddUsersReq true "user"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/users [post]
func (uc *UserAdminController) AddUsers(ctx *gin.Context) {
req := &schema.AddUsersReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := uc.userService.AddUsers(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UpdateUserPassword update user password
// @Summary update user password
// @Description update user password
// @Security ApiKeyAuth
// @Tags admin
// @Accept json
// @Produce json
// @Param data body schema.UpdateUserPasswordReq true "user"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/user/password [put]
func (uc *UserAdminController) UpdateUserPassword(ctx *gin.Context) {
req := &schema.UpdateUserPasswordReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
err := uc.userService.UpdateUserPassword(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// EditUserProfile edit user profile
// @Summary edit user profile
// @Description edit user profile
// @Security ApiKeyAuth
// @Tags admin
// @Accept json
// @Produce json
// @Param data body schema.EditUserProfileReq true "user"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/user/profile [put]
func (uc *UserAdminController) EditUserProfile(ctx *gin.Context) {
req := &schema.EditUserProfileReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.IsAdmin = middleware.GetUserIsAdminModerator(ctx)
if !req.IsAdmin {
handler.HandleResponse(ctx, errors.Forbidden(reason.ForbiddenError), nil)
return
}
errFields, err := uc.userService.EditUserProfile(ctx, req)
for _, field := range errFields {
field.ErrorMsg = translator.Tr(handler.GetLangByCtx(ctx), field.ErrorMsg)
}
handler.HandleResponse(ctx, err, errFields)
}
// GetUserPage get user page
// @Summary get user page
// @Description get user page
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param page query int false "page size"
// @Param page_size query int false "page size"
// @Param query query string false "search query: email, username or id:[id]"
// @Param staff query bool false "staff user"
// @Param status query string false "user status" Enums(suspended, deleted, inactive)
// @Success 200 {object} handler.RespBody{data=pager.PageModel{records=[]schema.GetUserPageResp}}
// @Router /answer/admin/api/users/page [get]
func (uc *UserAdminController) GetUserPage(ctx *gin.Context) {
req := &schema.GetUserPageReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := uc.userService.GetUserPage(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// GetUserActivation get user activation
// @Summary get user activation
// @Description get user activation
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param user_id query string true "user id"
// @Success 200 {object} handler.RespBody{data=schema.GetUserActivationResp}
// @Router /answer/admin/api/user/activation [get]
func (uc *UserAdminController) GetUserActivation(ctx *gin.Context) {
req := &schema.GetUserActivationReq{}
if handler.BindAndCheck(ctx, req) {
return
}
resp, err := uc.userService.GetUserActivation(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// SendUserActivation send user activation
// @Summary send user activation
// @Description send user activation
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SendUserActivationReq true "SendUserActivationReq"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/users/activation [post]
func (uc *UserAdminController) SendUserActivation(ctx *gin.Context) {
req := &schema.SendUserActivationReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := uc.userService.SendUserActivation(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// DeletePermanently delete permanently
// @Summary delete permanently
// @Description delete permanently
// @Security ApiKeyAuth
// @Tags admin
// @Accept json
// @Produce json
// @Param data body schema.DeletePermanentlyReq true "DeletePermanentlyReq"
// @Success 200 {object} handler.RespBody
// @Router /answer/admin/api/delete/permanently [delete]
func (uc *UserAdminController) DeletePermanently(ctx *gin.Context) {
req := &schema.DeletePermanentlyReq{}
if handler.BindAndCheck(ctx, req) {
return
}
err := uc.userService.DeletePermanently(ctx, req)
handler.HandleResponse(ctx, err, nil)
}