update recommend tag

This commit is contained in:
aichy126 2022-11-14 16:41:10 +08:00
parent 9e5c6c7a44
commit 2f6448b2c7
9 changed files with 507 additions and 29 deletions

View File

@ -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)

View File

@ -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": {

View File

@ -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": {

View File

@ -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

View File

@ -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"`
}

View File

@ -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()
}

View File

@ -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"`
}

View File

@ -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
}

View File

@ -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)