admin add tag

This commit is contained in:
aichy126 2022-11-15 11:53:46 +08:00
parent ba64be6845
commit a66cf236ef
6 changed files with 190 additions and 28 deletions

View File

@ -530,7 +530,7 @@ const docTemplate = `{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/schema.SiteWriteResp"
"$ref": "#/definitions/schema.SiteBrandingResp"
}
}
}
@ -717,6 +717,41 @@ const docTemplate = `{
}
},
"/answer/admin/api/siteinfo/write": {
"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": [
{
@ -5842,8 +5877,20 @@ const docTemplate = `{
"required_tag"
],
"properties": {
"recommend_tags": {
"type": "array",
"items": {
"type": "string"
}
},
"required_tag": {
"type": "boolean"
},
"reserved_tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
@ -5853,8 +5900,20 @@ const docTemplate = `{
"required_tag"
],
"properties": {
"recommend_tags": {
"type": "array",
"items": {
"type": "string"
}
},
"required_tag": {
"type": "boolean"
},
"reserved_tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},

View File

@ -518,7 +518,7 @@
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/schema.SiteWriteResp"
"$ref": "#/definitions/schema.SiteBrandingResp"
}
}
}
@ -705,6 +705,41 @@
}
},
"/answer/admin/api/siteinfo/write": {
"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": [
{
@ -5830,8 +5865,20 @@
"required_tag"
],
"properties": {
"recommend_tags": {
"type": "array",
"items": {
"type": "string"
}
},
"required_tag": {
"type": "boolean"
},
"reserved_tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
@ -5841,8 +5888,20 @@
"required_tag"
],
"properties": {
"recommend_tags": {
"type": "array",
"items": {
"type": "string"
}
},
"required_tag": {
"type": "boolean"
},
"reserved_tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
},

View File

@ -1168,15 +1168,31 @@ definitions:
type: object
schema.SiteWriteReq:
properties:
recommend_tags:
items:
type: string
type: array
required_tag:
type: boolean
reserved_tags:
items:
type: string
type: array
required:
- required_tag
type: object
schema.SiteWriteResp:
properties:
recommend_tags:
items:
type: string
type: array
required_tag:
type: boolean
reserved_tags:
items:
type: string
type: array
required:
- required_tag
type: object
@ -1843,7 +1859,7 @@ paths:
- $ref: '#/definitions/handler.RespBody'
- properties:
data:
$ref: '#/definitions/schema.SiteWriteResp'
$ref: '#/definitions/schema.SiteBrandingResp'
type: object
security:
- ApiKeyAuth: []
@ -1954,6 +1970,25 @@ paths:
tags:
- admin
/answer/admin/api/siteinfo/write:
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 write info
parameters:

View File

@ -66,7 +66,7 @@ func (sc *SiteInfoController) GetSiteBranding(ctx *gin.Context) {
// @Tags admin
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteWriteResp}
// @Router /answer/admin/api/siteinfo/branding [get]
// @Router /answer/admin/api/siteinfo/write [get]
func (sc *SiteInfoController) GetSiteWrite(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteWrite(ctx)
handler.HandleResponse(ctx, err, resp)

View File

@ -100,7 +100,7 @@ func (tr *tagRepo) GetRecommendTagList(ctx context.Context) (tagList []*entity.T
cond := &entity.Tag{}
session := tr.data.DB.Where("")
cond.Recommend = true
session.Where(builder.Eq{"status": entity.TagStatusAvailable})
// session.Where(builder.Eq{"status": entity.TagStatusAvailable})
session.Asc("slug_name")
session.UseBool("recommend")
err = session.Find(&tagList, cond)
@ -115,7 +115,7 @@ func (tr *tagRepo) GetReservedTagList(ctx context.Context) (tagList []*entity.Ta
cond := &entity.Tag{}
session := tr.data.DB.Where("")
cond.Reserved = true
session.Where(builder.Eq{"status": entity.TagStatusAvailable})
// session.Where(builder.Eq{"status": entity.TagStatusAvailable})
session.Asc("slug_name")
session.UseBool("reserved")
err = session.Find(&tagList, cond)
@ -129,7 +129,7 @@ func (tr *tagRepo) GetReservedTagList(ctx context.Context) (tagList []*entity.Ta
func (tr *tagRepo) GetTagListByNames(ctx context.Context, names []string) (tagList []*entity.Tag, err error) {
tagList = make([]*entity.Tag, 0)
session := tr.data.DB.In("slug_name", names)
session.Where(builder.Eq{"status": entity.TagStatusAvailable})
// session.Where(builder.Eq{"status": entity.TagStatusAvailable})
err = session.Find(&tagList)
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()

View File

@ -3,13 +3,15 @@ package tagcommon
import (
"context"
"encoding/json"
"fmt"
"strings"
"github.com/answerdev/answer/internal/service/revision_common"
"github.com/answerdev/answer/internal/service/siteinfo_common"
"github.com/answerdev/answer/internal/base/reason"
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service/revision_common"
"github.com/answerdev/answer/internal/service/siteinfo_common"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
)
@ -244,6 +246,7 @@ func (ts *TagCommonService) UpdateTag(ctx context.Context, tags []string, userID
}
addTagList := make([]*entity.Tag, 0)
addTagMsgList := make([]string, 0)
for _, tag := range tags {
_, ok := tagInDbMapping[tag]
if ok {
@ -256,27 +259,33 @@ func (ts *TagCommonService) UpdateTag(ctx context.Context, tags []string, userID
item.ParsedText = ""
item.Status = entity.TagStatusAvailable
addTagList = append(addTagList, item)
addTagMsgList = append(addTagMsgList, tag)
}
if len(addTagList) > 0 {
err = ts.tagRepo.AddTagList(ctx, addTagList)
if err != nil {
return err
}
for _, tag := range addTagList {
thisTagIDList = append(thisTagIDList, tag.ID)
revisionDTO := &schema.AddRevisionDTO{
UserID: userID,
ObjectID: tag.ID,
Title: tag.SlugName,
}
tagInfoJson, _ := json.Marshal(tag)
revisionDTO.Content = string(tagInfoJson)
err = ts.revisionService.AddRevision(ctx, revisionDTO, true)
if err != nil {
return err
}
}
err = fmt.Errorf("add a tag does not exist")
TagMsgList := strings.Replace(strings.Trim(fmt.Sprint(addTagMsgList), "[]"), " ", ",", -1)
errors.BadRequest(reason.TagNotFound).WithMsg(TagMsgList)
return err
// todo if need add
// err = ts.tagRepo.AddTagList(ctx, addTagList)
// if err != nil {
// return err
// }
// for _, tag := range addTagList {
// thisTagIDList = append(thisTagIDList, tag.ID)
// revisionDTO := &schema.AddRevisionDTO{
// UserID: userID,
// ObjectID: tag.ID,
// Title: tag.SlugName,
// }
// tagInfoJson, _ := json.Marshal(tag)
// revisionDTO.Content = string(tagInfoJson)
// err = ts.revisionService.AddRevision(ctx, revisionDTO, true)
// if err != nil {
// return err
// }
// }
}
return nil