作者 tangxvhui

处理文章标签

... ... @@ -8,13 +8,40 @@ info(
version: "v1"
)
@server(
prefix: v1/system
group: tags
jwt: SystemAuth
)
service Core {
@doc "后台创建文章标签"
@handler CreateTag
post /article_tag (TagCreateRequest) returns (TagCreateResponse)
@doc "后台编辑文章标签"
@handler EditTag
put /article_tag (TagEditRequest) returns (TagEditResponse)
@doc "后台获取文章标签"
@handler GetTag
get /article_tag/:id (TagGetRequest) returns (TagGetResponse)
@doc "后台删除文章标签"
@handler DeleteTag
delete /article_tag/:id (TagDeleteRequest) returns (TagDeleteResponse)
@doc "后台搜索标签"
@handler SearchTag
post/article_tag/search (TagListRequest) returns (TagListResponse)
}
// 创建标签
type (
TagCreateRequest {
CompanyId int64 `json:"companyId"`
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
... ... @@ -27,10 +54,10 @@ type (
type (
TagEditRequest {
Id int64 `json:"id"`
CompanyId int64 `json:"-"`
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
... ... @@ -43,13 +70,13 @@ type (
type (
TagGetRequest {
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
CompanyId int64 `path:",optional"`
}
TagGetResponse {
Id int64 `json:"id"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类
Remark string `json:"remark"` // 备注
}
)
... ... @@ -59,9 +86,9 @@ type (
TagListRequest {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"-"`
CompanyId int64 `json:",optional"`
TagName string `json:"tagName,optional"`
Group string `json:"group,optional"`
Category string `json:"category,optional"`
Remark string `json:"remark,optional"`
}
TagListResponse {
... ... @@ -72,7 +99,7 @@ type (
Id int64 `json:"id"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类
Remark string `json:"remark"` // 备注
CreatedAt int64 `json:"createdAt"`
}
... ... @@ -82,36 +109,9 @@ type (
type (
TagDeleteRequest {
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
CompanyId int64 `path:",optional"`
}
TagDeleteResponse {
Id int64 `json:"id"`
}
)
\ No newline at end of file
@server(
prefix: v1/system
group: tags
jwt: MiniAuth
)
service Core {
@doc "后台创建文章标签"
@handler CreateTag
post /article_tag (TagCreateRequest) returns (TagCreateResponse)
@doc "后台编辑文章标签"
@handler EditTag
put /article_tag (TagEditRequest) returns (TagEditResponse)
@doc "后台获取文章标签"
@handler GetTag
get /article_tag/:id (TagGetRequest) returns (TagGetResponse)
@doc "后台删除文章标签"
@handler DeleteTag
delete /article_tag/:id (TagDeleteRequest) returns (TagDeleteResponse)
@doc "后台搜索标签"
@handler SearchTag
post/article_tag/search (TagListRequest) returns (TagListResponse)
}
\ No newline at end of file
... ...
... ... @@ -120,7 +120,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: tags.SearchTagHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1/system"),
)
... ...
... ... @@ -7,6 +7,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -18,11 +20,9 @@ func CreateTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := tags.NewCreateTagLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.CreateTag(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -7,6 +7,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -18,11 +20,9 @@ func DeleteTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := tags.NewDeleteTagLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.DeleteTag(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -7,6 +7,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -18,11 +20,9 @@ func EditTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := tags.NewEditTagLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.EditTag(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -7,6 +7,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -16,13 +18,10 @@ func GetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
httpx.ErrorCtx(r.Context(), w, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
l := tags.NewGetTagLogic(r.Context(), svcCtx)
resp, err := l.GetTag(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -7,6 +7,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tags"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -18,11 +20,9 @@ func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := tags.NewSearchTagLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.SearchTag(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -36,20 +36,20 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR
var group []string
tagMap := map[string][]types.ArticleTagItem{}
for _, val := range tagList {
if m, ok := tagMap[val.Group]; ok {
if m, ok := tagMap[val.Category]; ok {
m = append(m, types.ArticleTagItem{
Id: val.Id,
Group: val.Group,
Group: val.Category,
Name: val.Name,
Image: val.Image.Url,
})
tagMap[val.Group] = m
tagMap[val.Category] = m
} else {
group = append(group, val.Group)
tagMap[val.Group] = []types.ArticleTagItem{
group = append(group, val.Category)
tagMap[val.Category] = []types.ArticleTagItem{
{
Id: val.Id,
Group: val.Group,
Group: val.Category,
Name: val.Name,
Image: val.Image.Url,
},
... ...
... ... @@ -32,14 +32,14 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
//检查重复
cnt, _, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, map[string]interface{}{
"name": req.Name,
"group": req.Group,
"category": req.Category,
"countOnly": true,
})
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
if cnt > 0 {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name))
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name))
}
//TODO 获取图片的尺寸大小
... ... @@ -56,7 +56,7 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
Height: 0,
},
Name: req.Name,
Group: req.Group,
Category: req.Category,
Remark: req.Remark,
}
... ...
... ... @@ -33,7 +33,7 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe
queryOptions := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("name", req.Name).
MustWithKV("group", req.Group).
MustWithKV("category", req.Category).
WithOffsetLimit(1, 1)
_, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
... ... @@ -42,7 +42,7 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe
}
if len(tagList) > 0 {
if tagList[0].Id != req.Id {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name))
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Category, req.Name))
}
}
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
... ... @@ -55,7 +55,7 @@ func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditRe
//TODO 获取图片的尺寸大小
oldTag.Group = req.Group
oldTag.Category = req.Category
oldTag.Image.Url = req.Image
oldTag.Name = req.Name
oldTag.Remark = req.Remark
... ...
... ... @@ -38,7 +38,7 @@ func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetRespon
Id: oldTag.Id,
Image: oldTag.Image.Url,
Name: oldTag.Name,
Group: oldTag.Group,
Category: oldTag.Category,
Remark: oldTag.Remark,
}
return
... ...
... ... @@ -27,8 +27,8 @@ func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagLi
var conn = l.svcCtx.DefaultDBConn()
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
if len(req.Group) > 0 {
queryOptions = queryOptions.MustWithKV("group", req.Group)
if len(req.Category) > 0 {
queryOptions = queryOptions.MustWithKV("group", req.Category)
}
if len(req.TagName) > 0 {
queryOptions = queryOptions.MustWithKV("name", req.TagName)
... ... @@ -50,7 +50,7 @@ func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagLi
Id: tagList[i].Id,
Image: tagList[i].Image.Url,
Name: tagList[i].Name,
Group: tagList[i].Group,
Category: tagList[i].Category,
Remark: tagList[i].Remark,
CreatedAt: tagList[i].CreatedAt,
}
... ...
... ... @@ -209,10 +209,10 @@ type SimpleArticle struct {
}
type TagCreateRequest struct {
CompanyId int64 `json:"companyId"`
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
... ... @@ -222,10 +222,10 @@ type TagCreateResponse struct {
type TagEditRequest struct {
Id int64 `json:"id"`
CompanyId int64 `json:"-"`
CompanyId int64 `json:",optional"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类
Remark string `json:"remark,optional"` // 备注
}
... ... @@ -235,23 +235,23 @@ type TagEditResponse struct {
type TagGetRequest struct {
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
CompanyId int64 `path:",optional"`
}
type TagGetResponse struct {
Id int64 `json:"id"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类
Remark string `json:"remark"` // 备注
}
type TagListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"-"`
CompanyId int64 `json:",optional"`
TagName string `json:"tagName,optional"`
Group string `json:"group,optional"`
Category string `json:"category,optional"`
Remark string `json:"remark,optional"`
}
... ... @@ -264,14 +264,14 @@ type TagItem struct {
Id int64 `json:"id"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类
Remark string `json:"remark"` // 备注
CreatedAt int64 `json:"createdAt"`
}
type TagDeleteRequest struct {
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
CompanyId int64 `path:",optional"`
}
type TagDeleteResponse struct {
... ...
... ... @@ -20,9 +20,8 @@ type ArticleTag struct {
Version int
Image domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
Name string // 标签名称
Group string // 标签分类
Remark string // 备注
Other string // 其他内容
Category string // 标签分类
SortBy int64 // 顺序
}
... ...
... ... @@ -127,8 +127,8 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
if v, ok := queryOptions["name"]; ok {
tx = tx.Where("name like ?", v)
}
if v, ok := queryOptions["group"]; ok {
tx = tx.Where("group like ?", v)
if v, ok := queryOptions["category"]; ok {
tx = tx.Where("category like ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
... ...
... ... @@ -17,7 +17,7 @@ type ArticleTag struct {
Version int `json:"version,omitempty"`
Image Image `json:"image"` // 图片
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Category string `json:"category"` // 标签分类 [紧急重要]、[机会风险]
Remark string `json:"remark"` // 备注
SortBy int64 `json:"sortBy"` // 顺序
Other string `json:"other"` //
... ...