mini_create_article_logic.go
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package article
import (
"context"
"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/samber/lo"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniCreateArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCreateArticleLogic {
return &MiniCreateArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查发布人
author, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(req.AuthorId))
if err != nil {
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
}
//TODO 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
images = append(images, domain.Image{
Url: val,
Width: 0,
Height: 0,
})
}
//检查文章可被哪些人查看
whoRead := []int64{}
if len(req.WhoRead) > 0 {
whoRead = lo.Uniq(req.WhoRead)
var u *domain.User
for _, val := range whoRead {
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, val)
if err != nil {
return nil, xerr.NewErrMsgErr("文章可查看人设置错误", err)
}
if u.CompanyId != author.CompanyId {
return nil, xerr.NewErrMsg("文章可查看人设置错误")
}
}
}
//检查文章可被哪些人评论
whoReview := []int64{}
if len(req.WhoReview) > 0 && len(whoRead) > 0 {
whoReview = lo.Uniq(req.WhoReview)
// 检查 whoRead 是否 完全包含 whoReview
ok := lo.Every(whoRead, whoReview)
if !ok {
return nil, xerr.NewErrMsg("文章可评论人设置错误")
}
}
if len(whoRead) > 0 && len(whoReview) == 0 {
//有指定可查看人 ,但未指定可评论人
return nil, xerr.NewErrMsg("文章可评论人设置错误")
}
// if len(whoRead) == 0 && len(whoReview) > 0 {
// 未指定可查看人(全员可看),有指定可评论人 ,忽略判断
// }
// if len(whoRead) == 0 && len(whoReview) == 0 {
// 未指定可查看人(全员可看),未指定可评论人 ,忽略判断
// }
return
}