Skip to content

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.

update recommend tag

aichy1262f6448b2c757
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.go
index 7b7a6937..0e8bdc49 100644
--- a/cmd/answer/wire_gen.go
+++ b/cmd/answer/wire_gen.go
@@ -130,7 +130,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
revisionRepo := revision.NewRevisionRepo(dataData, uniqueIDRepo)
revisionService := revision_common.NewRevisionService(revisionRepo, userRepo)
followRepo := activity_common.NewFollowRepo(dataData, uniqueIDRepo, activityRepo)
- tagService := tag2.NewTagService(tagRepo, revisionService, followRepo)
+ tagService := tag2.NewTagService(tagRepo, revisionService, followRepo, siteInfoCommonService)
tagController := controller.NewTagController(tagService, rankService)
followFollowRepo := activity.NewFollowRepo(dataData, uniqueIDRepo, activityRepo)
followService := follow.NewFollowService(followFollowRepo, followRepo, tagRepo)
@@ -138,7 +138,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
collectionRepo := collection.NewCollectionRepo(dataData, uniqueIDRepo)
collectionGroupRepo := collection.NewCollectionGroupRepo(dataData)
tagRelRepo := tag.NewTagRelRepo(dataData)
- tagCommonService := tagcommon.NewTagCommonService(tagRepo, tagRelRepo, revisionService)
+ tagCommonService := tagcommon.NewTagCommonService(tagRepo, tagRelRepo, revisionService, siteInfoCommonService)
collectionCommon := collectioncommon.NewCollectionCommon(collectionRepo)
answerCommon := answercommon.NewAnswerCommon(answerRepo)
metaRepo := meta.NewMetaRepo(dataData)
diff --git a/docs/docs.go b/docs/docs.go
index 27ec7532..eb16fc2d 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -503,6 +503,77 @@ const docTemplate = `{
}
}
},
+ "/answer/admin/api/siteinfo/branding": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "get site interface",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "admin"
+ ],
+ "summary": "get site interface",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/handler.RespBody"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "$ref": "#/definitions/schema.SiteWriteResp"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ },
+ "put": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "update site info branding",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "admin"
+ ],
+ "summary": "update site info branding",
+ "parameters": [
+ {
+ "description": "branding info",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.SiteBrandingReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/answer/admin/api/siteinfo/general": {
"get": {
"security": [
@@ -645,6 +716,42 @@ const docTemplate = `{
}
}
},
+ "/answer/admin/api/siteinfo/write": {
+ "put": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "update site write info",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "admin"
+ ],
+ "summary": "update site write info",
+ "parameters": [
+ {
+ "description": "write info",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.SiteWriteReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/answer/admin/api/theme/options": {
"get": {
"security": [
@@ -5571,6 +5678,56 @@ const docTemplate = `{
}
}
},
+ "schema.SiteBrandingReq": {
+ "type": "object",
+ "required": [
+ "logo",
+ "square_icon"
+ ],
+ "properties": {
+ "favicon": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "logo": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "mobile_logo": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "square_icon": {
+ "type": "string",
+ "maxLength": 512
+ }
+ }
+ },
+ "schema.SiteBrandingResp": {
+ "type": "object",
+ "required": [
+ "logo",
+ "square_icon"
+ ],
+ "properties": {
+ "favicon": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "logo": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "mobile_logo": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "square_icon": {
+ "type": "string",
+ "maxLength": 512
+ }
+ }
+ },
"schema.SiteGeneralReq": {
"type": "object",
"required": [
@@ -5647,10 +5804,6 @@ const docTemplate = `{
"type": "string",
"maxLength": 128
},
- "logo": {
- "type": "string",
- "maxLength": 256
- },
"theme": {
"type": "string",
"maxLength": 128
@@ -5673,10 +5826,6 @@ const docTemplate = `{
"type": "string",
"maxLength": 128
},
- "logo": {
- "type": "string",
- "maxLength": 256
- },
"theme": {
"type": "string",
"maxLength": 128
@@ -5687,6 +5836,28 @@ const docTemplate = `{
}
}
},
+ "schema.SiteWriteReq": {
+ "type": "object",
+ "required": [
+ "required_tag"
+ ],
+ "properties": {
+ "required_tag": {
+ "type": "boolean"
+ }
+ }
+ },
+ "schema.SiteWriteResp": {
+ "type": "object",
+ "required": [
+ "required_tag"
+ ],
+ "properties": {
+ "required_tag": {
+ "type": "boolean"
+ }
+ }
+ },
"schema.TagItem": {
"type": "object",
"properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 39b4c363..4428992e 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -491,6 +491,77 @@
}
}
},
+ "/answer/admin/api/siteinfo/branding": {
+ "get": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "get site interface",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "admin"
+ ],
+ "summary": "get site interface",
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/handler.RespBody"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "$ref": "#/definitions/schema.SiteWriteResp"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ },
+ "put": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "update site info branding",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "admin"
+ ],
+ "summary": "update site info branding",
+ "parameters": [
+ {
+ "description": "branding info",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.SiteBrandingReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/answer/admin/api/siteinfo/general": {
"get": {
"security": [
@@ -633,6 +704,42 @@
}
}
},
+ "/answer/admin/api/siteinfo/write": {
+ "put": {
+ "security": [
+ {
+ "ApiKeyAuth": []
+ }
+ ],
+ "description": "update site write info",
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "admin"
+ ],
+ "summary": "update site write info",
+ "parameters": [
+ {
+ "description": "write info",
+ "name": "data",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/schema.SiteWriteReq"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/handler.RespBody"
+ }
+ }
+ }
+ }
+ },
"/answer/admin/api/theme/options": {
"get": {
"security": [
@@ -5559,6 +5666,56 @@
}
}
},
+ "schema.SiteBrandingReq": {
+ "type": "object",
+ "required": [
+ "logo",
+ "square_icon"
+ ],
+ "properties": {
+ "favicon": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "logo": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "mobile_logo": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "square_icon": {
+ "type": "string",
+ "maxLength": 512
+ }
+ }
+ },
+ "schema.SiteBrandingResp": {
+ "type": "object",
+ "required": [
+ "logo",
+ "square_icon"
+ ],
+ "properties": {
+ "favicon": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "logo": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "mobile_logo": {
+ "type": "string",
+ "maxLength": 512
+ },
+ "square_icon": {
+ "type": "string",
+ "maxLength": 512
+ }
+ }
+ },
"schema.SiteGeneralReq": {
"type": "object",
"required": [
@@ -5635,10 +5792,6 @@
"type": "string",
"maxLength": 128
},
- "logo": {
- "type": "string",
- "maxLength": 256
- },
"theme": {
"type": "string",
"maxLength": 128
@@ -5661,10 +5814,6 @@
"type": "string",
"maxLength": 128
},
- "logo": {
- "type": "string",
- "maxLength": 256
- },
"theme": {
"type": "string",
"maxLength": 128
@@ -5675,6 +5824,28 @@
}
}
},
+ "schema.SiteWriteReq": {
+ "type": "object",
+ "required": [
+ "required_tag"
+ ],
+ "properties": {
+ "required_tag": {
+ "type": "boolean"
+ }
+ }
+ },
+ "schema.SiteWriteResp": {
+ "type": "object",
+ "required": [
+ "required_tag"
+ ],
+ "properties": {
+ "required_tag": {
+ "type": "boolean"
+ }
+ }
+ },
"schema.TagItem": {
"type": "object",
"properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 72801460..03a44709 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1050,6 +1050,42 @@ definitions:
description: object_type
type: string
type: object
+ schema.SiteBrandingReq:
+ properties:
+ favicon:
+ maxLength: 512
+ type: string
+ logo:
+ maxLength: 512
+ type: string
+ mobile_logo:
+ maxLength: 512
+ type: string
+ square_icon:
+ maxLength: 512
+ type: string
+ required:
+ - logo
+ - square_icon
+ type: object
+ schema.SiteBrandingResp:
+ properties:
+ favicon:
+ maxLength: 512
+ type: string
+ logo:
+ maxLength: 512
+ type: string
+ mobile_logo:
+ maxLength: 512
+ type: string
+ square_icon:
+ maxLength: 512
+ type: string
+ required:
+ - logo
+ - square_icon
+ type: object
schema.SiteGeneralReq:
properties:
contact_email:
@@ -1103,9 +1139,6 @@ definitions:
language:
maxLength: 128
type: string
- logo:
- maxLength: 256
- type: string
theme:
maxLength: 128
type: string
@@ -1122,9 +1155,6 @@ definitions:
language:
maxLength: 128
type: string
- logo:
- maxLength: 256
- type: string
theme:
maxLength: 128
type: string
@@ -1136,6 +1166,20 @@ definitions:
- theme
- time_zone
type: object
+ schema.SiteWriteReq:
+ properties:
+ required_tag:
+ type: boolean
+ required:
+ - required_tag
+ type: object
+ schema.SiteWriteResp:
+ properties:
+ required_tag:
+ type: boolean
+ required:
+ - required_tag
+ type: object
schema.TagItem:
properties:
display_name:
@@ -1784,6 +1828,47 @@ paths:
summary: update smtp config
tags:
- admin
+ /answer/admin/api/siteinfo/branding:
+ get:
+ description: get site interface
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ allOf:
+ - $ref: '#/definitions/handler.RespBody'
+ - properties:
+ data:
+ $ref: '#/definitions/schema.SiteWriteResp'
+ type: object
+ security:
+ - ApiKeyAuth: []
+ summary: get site interface
+ tags:
+ - admin
+ put:
+ description: update site info branding
+ parameters:
+ - description: branding info
+ in: body
+ name: data
+ required: true
+ schema:
+ $ref: '#/definitions/schema.SiteBrandingReq'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/handler.RespBody'
+ security:
+ - ApiKeyAuth: []
+ summary: update site info branding
+ tags:
+ - admin
/answer/admin/api/siteinfo/general:
get:
description: get site general information
@@ -1866,6 +1951,28 @@ paths:
summary: update site info interface
tags:
- admin
+ /answer/admin/api/siteinfo/write:
+ put:
+ description: update site write info
+ parameters:
+ - description: write info
+ in: body
+ name: data
+ required: true
+ schema:
+ $ref: '#/definitions/schema.SiteWriteReq'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/handler.RespBody'
+ security:
+ - ApiKeyAuth: []
+ summary: update site write info
+ tags:
+ - admin
/answer/admin/api/theme/options:
get:
description: Get theme options
diff --git a/internal/entity/tag_entity.go b/internal/entity/tag_entity.go
index 2bef34d0..4fabe1f1 100644
--- a/internal/entity/tag_entity.go
+++ b/internal/entity/tag_entity.go
@@ -21,6 +21,7 @@ type Tag struct {
FollowCount int `xorm:"not null default 0 INT(11) follow_count"`
QuestionCount int `xorm:"not null default 0 INT(11) question_count"`
Status int `xorm:"not null default 1 INT(11) status"`
+ Recommend bool `xorm:"not null default false BOOL recommend"`
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
}
diff --git a/internal/repo/tag/tag_repo.go b/internal/repo/tag/tag_repo.go
index 44154593..e72a7cf9 100644
--- a/internal/repo/tag/tag_repo.go
+++ b/internal/repo/tag/tag_repo.go
@@ -73,10 +73,17 @@ func (tr *tagRepo) GetTagBySlugName(ctx context.Context, slugName string) (tagIn
// GetTagListByName get tag list all like name
func (tr *tagRepo) GetTagListByName(ctx context.Context, name string, limit int) (tagList []*entity.Tag, err error) {
tagList = make([]*entity.Tag, 0)
- session := tr.data.DB.Where("slug_name LIKE ?", name+"%")
+ cond := &entity.Tag{}
+ session := tr.data.DB.Where("")
+ if name != "" {
+ session.Where("slug_name LIKE ?", name+"%")
+ } else {
+ cond.Recommend = true
+ }
session.Where(builder.Eq{"status": entity.TagStatusAvailable})
session.Limit(limit).Asc("slug_name")
- err = session.Find(&tagList)
+ session.UseBool("recommend")
+ err = session.Find(&tagList, cond)
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
diff --git a/internal/schema/tag_schema.go b/internal/schema/tag_schema.go
index d6b70c39..84160570 100644
--- a/internal/schema/tag_schema.go
+++ b/internal/schema/tag_schema.go
@@ -11,7 +11,7 @@ import (
// SearchTagLikeReq get tag list all request
type SearchTagLikeReq struct {
// tag
- Tag string `validate:"required,gt=0,lte=35" form:"tag"`
+ Tag string `validate:"omitempty" form:"tag"`
}
// GetTagInfoReq get tag info request
@@ -218,3 +218,8 @@ type GetFollowingTagsResp struct {
// if main tag slug name is not empty, this tag is synonymous with the main tag
MainTagSlugName string `json:"main_tag_slug_name"`
}
+
+type SearchTagLikeResp struct {
+ SlugName string `json:"slug_name"`
+ Recommend bool `json:"recommend"`
+}
diff --git a/internal/service/tag/tag_service.go b/internal/service/tag/tag_service.go
index f9de052a..3e4966c7 100644
--- a/internal/service/tag/tag_service.go
+++ b/internal/service/tag/tag_service.go
@@ -44,13 +44,16 @@ func NewTagService(
}
// SearchTagLike get tag list all
-func (ts *TagService) SearchTagLike(ctx context.Context, req *schema.SearchTagLikeReq) (resp []string, err error) {
+func (ts *TagService) SearchTagLike(ctx context.Context, req *schema.SearchTagLikeReq) (resp []schema.SearchTagLikeResp, err error) {
tags, err := ts.tagRepo.GetTagListByName(ctx, req.Tag, 5)
if err != nil {
return
}
for _, tag := range tags {
- resp = append(resp, tag.SlugName)
+ item := schema.SearchTagLikeResp{}
+ item.SlugName = tag.SlugName
+ item.Recommend = tag.Recommend
+ resp = append(resp, item)
}
return resp, nil
}
diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go
index 8e91da62..4ed9a209 100644
--- a/internal/service/tag_common/tag_common.go
+++ b/internal/service/tag_common/tag_common.go
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/answerdev/answer/internal/service/revision_common"
+ "github.com/answerdev/answer/internal/service/siteinfo_common"
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/schema"
@@ -42,19 +43,31 @@ type TagCommonService struct {
revisionService *revision_common.RevisionService
tagRepo TagRepo
tagRelRepo TagRelRepo
+ siteInfoService *siteinfo_common.SiteInfoCommonService
}
// NewTagCommonService new tag service
func NewTagCommonService(tagRepo TagRepo, tagRelRepo TagRelRepo,
revisionService *revision_common.RevisionService,
+ siteInfoService *siteinfo_common.SiteInfoCommonService,
) *TagCommonService {
return &TagCommonService{
tagRepo: tagRepo,
tagRelRepo: tagRelRepo,
revisionService: revisionService,
+ siteInfoService: siteInfoService,
}
}
+func (ts *TagCommonService) GetSiteWriteTag(ctx context.Context) (tags []string, err error) {
+ return []string{}, nil
+}
+
+func (ts *TagCommonService) SetSiteWriteTag(ctx context.Context, tags []string, required bool) (err error) {
+
+ return nil
+}
+
// GetTagListByName
func (ts *TagCommonService) GetTagListByName(ctx context.Context, tagName string) (tagInfo *entity.Tag, exist bool, err error) {
tagName = strings.ToLower(tagName)