@@ -3,19 +3,24 @@ package data
33import (
44 cv1 "common/api/common/v1"
55 v1 "common/api/content/v1"
6+ notifyv1 "common/api/notify/v1"
67 "common/pkg/constant"
7- "common/pkg/util/base"
8- "common/pkg/util/collections/set"
8+ "common/pkg/cutil/base"
9+ "common/pkg/cutil/collections/set"
10+ commonModel "common/pkg/model"
11+ "common/pkg/util"
912 "content/internal/biz/model"
1013 "content/internal/biz/repo"
1114 "content/internal/data/ent/gen"
1215 "content/internal/data/ent/gen/article"
1316 "content/internal/data/ent/gen/articlepostscript"
1417 "content/internal/data/ent/gen/tag"
1518 "context"
19+ "encoding/json"
1620 "time"
1721
1822 "entgo.io/ent/dialect/sql"
23+ "github.com/google/uuid"
1924)
2025
2126type ArticleRepo struct {
@@ -182,6 +187,11 @@ func (r *ArticleRepo) UpdateStat(ctx context.Context, tx *gen.Client, articleId
182187}
183188
184189func (r * ArticleRepo ) Publish (ctx context.Context , tx * gen.Client , articleId int64 ) error {
190+ user , ok := util .GetContextValue [* commonModel.User ](ctx , constant .CtxUserInfo )
191+ if ! ok {
192+ return cv1 .ErrorUnauthorized ("user not login" )
193+ }
194+
185195 first , err := r .GetOne (ctx , tx , & repo.ArticleGetReq {ArticleId : base .Ptr (articleId )})
186196 if err != nil {
187197 return err
@@ -196,22 +206,25 @@ func (r *ArticleRepo) Publish(ctx context.Context, tx *gen.Client, articleId int
196206 return err
197207 }
198208
199- return nil
209+ // return nil
200210
201- //// Todo 广播添加文章事件
202- //publish := &v1.ArticleEventPublish{}
203- //err = copier.Copy(&publish, first)
204- //if err != nil {
205- // return err
206- //}
207- //marshal, err := json.Marshal(publish)
208- //if err != nil {
209- // return err
210- //}
211- //err = r.rabbitmq.Publish(constant.ExchangeContent.String(), constant.RoutingKeyArticleCreate.String(), marshal)
212- //if err != nil {
213- // return err
214- //}
211+ // Todo 广播添加文章事件
212+ publish := & commonModel.Notification {
213+ UUID : uuid .New ().String (),
214+ Type : base .Ptr (notifyv1 .NotificationType_NotificationTypeArticlePublish ),
215+ SenderId : user .ID ,
216+ Channels : []* notifyv1.NotificationChannel {base .Ptr (notifyv1 .NotificationChannel_NotificationChannelWebSite )},
217+ Meta : map [string ]any {"user" : commonModel.User {Name : user .Name }, "article" : first },
218+ Status : notifyv1 .NotificationStatus_NotificationStatusNormal ,
219+ }
220+ marshal , err := json .Marshal (publish )
221+ if err != nil {
222+ return err
223+ }
224+ err = r .rabbitmq .Publish (constant .ExchangeContent .String (), constant .RoutingKeyContentArticlePublish .String (), marshal )
225+ if err != nil {
226+ return err
227+ }
215228 //// Todo 广播@用户通知
216229 //atUserNames := first.ParseContent()
217230 //
@@ -221,8 +234,8 @@ func (r *ArticleRepo) Publish(ctx context.Context, tx *gen.Client, articleId int
221234 // return err
222235 //}
223236 //_ = atUserList
224- //
225- // return nil
237+
238+ return nil
226239}
227240
228241func (r * ArticleRepo ) Delete (ctx context.Context , tx * gen.Client , articleId int64 ) error {
0 commit comments