作者 tangxvhui

文章标签的编辑

... ... @@ -15,7 +15,7 @@ type (
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
Remark string `json:"remark,optional"` // 备注
}
TagCreateResponse {
... ... @@ -27,11 +27,11 @@ type (
type (
TagEditRequest {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
CompanyId int64 `json:"-"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
Remark string `json:"remark,optional"` // 备注
}
TagEditResponse {
... ... @@ -43,6 +43,7 @@ type (
type (
TagGetRequest {
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
TagGetResponse {
Id int64 `json:"id"`
... ... @@ -58,9 +59,13 @@ type (
TagListRequest {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"-"`
TagName string `json:"tagName,optional"`
Group string `json:"group,optional"`
Remark string `json:"remark,optional"`
}
TagListResponse {
Total int `json:"total"`
Total int64 `json:"total"`
List []TagItem `json:"list"`
}
TagItem {
... ... @@ -77,6 +82,7 @@ type (
type (
TagDeleteRequest {
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
TagDeleteResponse {
Id int64 `json:"id"`
... ... @@ -92,13 +98,20 @@ 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 (TagDeleteRequest) returns (TagDeleteResponse)
delete /article_tag/:id (TagDeleteRequest) returns (TagDeleteResponse)
@doc "后台搜索标签"
@handler SearchTag
post/article_tag/search (TagListRequest) returns (TagListResponse)
}
\ No newline at end of file
... ...
... ... @@ -78,6 +78,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article_tag",
Handler: tags.DeleteTagHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_tag/search",
Handler: tags.SearchTagHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
... ...
package tags
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"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"
)
func SearchTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TagListRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := tags.NewSearchTagLogic(r.Context(), svcCtx)
resp, err := l.SearchTag(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"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/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -25,6 +26,7 @@ func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateT
}
}
// 创建标签
func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.TagCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
//检查重复
... ... @@ -39,5 +41,29 @@ func (l *CreateTagLogic) CreateTag(req *types.TagCreateRequest) (resp *types.Tag
if cnt > 0 {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name))
}
//TODO 获取图片的尺寸大小
newTag := &domain.ArticleTag{
Id: 0,
CompanyId: req.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
DeletedAt: 0,
Version: 0,
Image: domain.Image{
Url: req.Image,
Width: 0,
Height: 0,
},
Name: req.Name,
Group: req.Group,
Remark: req.Remark,
}
newTag, err = l.svcCtx.ArticleTagRepository.Insert(l.ctx, conn, newTag)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
resp = &types.TagCreateResponse{Id: newTag.Id}
return
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"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/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -24,7 +25,18 @@ func NewDeleteTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteT
}
func (l *DeleteTagLogic) DeleteTag(req *types.TagDeleteRequest) (resp *types.TagDeleteResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("不存在待修改的标签", err)
}
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("删除标签失败")
}
_, err = l.svcCtx.ArticleTagRepository.Delete(l.ctx, conn, oldTag)
if err != nil {
return nil, xerr.NewErrMsg("删除标签失败")
}
resp = &types.TagDeleteResponse{Id: oldTag.Id}
return
}
... ...
... ... @@ -2,9 +2,12 @@ package tags
import (
"context"
"fmt"
"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/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -23,8 +26,44 @@ func NewEditTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditTagLo
}
}
// 编辑标签
func (l *EditTagLogic) EditTag(req *types.TagEditRequest) (resp *types.TagEditResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
//检查重复
queryOptions := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("name", req.Name).
MustWithKV("group", req.Group).
WithOffsetLimit(1, 1)
_, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("修改标签失败", err)
}
if len(tagList) > 0 {
if tagList[0].Id != req.Id {
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在标签 分类[%s]名称[%s]", req.Group, req.Name))
}
}
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("不存在待修改的标签", err)
}
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("修改标签失败")
}
//TODO 获取图片的尺寸大小
oldTag.Group = req.Group
oldTag.Image.Url = req.Image
oldTag.Name = req.Name
oldTag.Remark = req.Remark
oldTag, err = l.svcCtx.ArticleTagRepository.Update(l.ctx, conn, oldTag)
if err != nil {
return nil, xerr.NewErrMsgErr("添加标签失败", err)
}
resp = &types.TagEditResponse{Id: oldTag.Id}
return
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"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/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -23,8 +24,22 @@ func NewGetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTagLogi
}
}
// 获取详情
func (l *GetTagLogic) GetTag(req *types.TagGetRequest) (resp *types.TagGetResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
oldTag, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("不存在的标签", err)
}
if oldTag.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取标签失败")
}
resp = &types.TagGetResponse{
Id: oldTag.Id,
Image: oldTag.Image.Url,
Name: oldTag.Name,
Group: oldTag.Group,
Remark: oldTag.Remark,
}
return
}
... ...
package tags
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"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/cmd/discuss/interanl/pkg/domain"
)
type SearchTagLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchTagLogic {
return &SearchTagLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchTagLogic) SearchTag(req *types.TagListRequest) (resp *types.TagListResponse, err error) {
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.TagName) > 0 {
queryOptions = queryOptions.MustWithKV("name", req.TagName)
}
if len(req.Remark) > 0 {
queryOptions = queryOptions.MustWithKV("remark", "%"+req.Remark+"%")
}
cnt, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return &types.TagListResponse{}, nil
}
resp = &types.TagListResponse{
Total: cnt,
List: make([]types.TagItem, len(tagList)),
}
for i := range tagList {
resp.List[i] = types.TagItem{
Id: tagList[i].Id,
Image: tagList[i].Image.Url,
Name: tagList[i].Name,
Group: tagList[i].Group,
Remark: tagList[i].Remark,
CreatedAt: tagList[i].CreatedAt,
}
}
return
}
... ...
... ... @@ -69,7 +69,7 @@ type TagCreateRequest struct {
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
Remark string `json:"remark,optional"` // 备注
}
type TagCreateResponse struct {
... ... @@ -78,11 +78,11 @@ type TagCreateResponse struct {
type TagEditRequest struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
CompanyId int64 `json:"-"`
Image string `json:"image"`
Name string `json:"name"` // 标签名称
Group string `json:"group"` // 标签分类
Remark string `json:"remark"` // 备注
Remark string `json:"remark,optional"` // 备注
}
type TagEditResponse struct {
... ... @@ -91,6 +91,7 @@ type TagEditResponse struct {
type TagGetRequest struct {
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
type TagGetResponse struct {
... ... @@ -104,10 +105,14 @@ type TagGetResponse struct {
type TagListRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:"-"`
TagName string `json:"tagName,optional"`
Group string `json:"group,optional"`
Remark string `json:"remark,optional"`
}
type TagListResponse struct {
Total int `json:"total"`
Total int64 `json:"total"`
List []TagItem `json:"list"`
}
... ... @@ -122,12 +127,15 @@ type TagItem struct {
type TagDeleteRequest struct {
Id int64 `path:"id"`
CompanyId int64 `path:"-"`
}
type TagDeleteResponse struct {
Id int64 `json:"id"`
}
type MiniUserLoginRequest struct {
LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login
WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码
... ...