Merge branch 'feat/1.1.0/report' of github.com:answerdev/answer into feat/1.1.0/report

This commit is contained in:
aichy126 2023-05-26 11:10:00 +08:00
commit 4d1326f0df
1 changed files with 9 additions and 15 deletions

View File

@ -114,11 +114,11 @@ func (ns *NotificationCommon) AddNotification(ctx context.Context, msg *schema.N
if msg.Type == schema.NotificationTypeAchievement { if msg.Type == schema.NotificationTypeAchievement {
notificationInfo, exist, err := ns.notificationRepo.GetByUserIdObjectIdTypeId(ctx, req.ReceiverUserID, req.ObjectInfo.ObjectID, req.Type) notificationInfo, exist, err := ns.notificationRepo.GetByUserIdObjectIdTypeId(ctx, req.ReceiverUserID, req.ObjectInfo.ObjectID, req.Type)
if err != nil { if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack() return fmt.Errorf("get by user id object id type id error: %w", err)
} }
rank, err := ns.activityRepo.GetUserIDObjectIDActivitySum(ctx, req.ReceiverUserID, req.ObjectInfo.ObjectID) rank, err := ns.activityRepo.GetUserIDObjectIDActivitySum(ctx, req.ReceiverUserID, req.ObjectInfo.ObjectID)
if err != nil { if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack() return fmt.Errorf("get user id object id activity sum error: %w", err)
} }
req.Rank = rank req.Rank = rank
if exist { if exist {
@ -126,17 +126,14 @@ func (ns *NotificationCommon) AddNotification(ctx context.Context, msg *schema.N
updateContent := &schema.NotificationContent{} updateContent := &schema.NotificationContent{}
err := json.Unmarshal([]byte(notificationInfo.Content), updateContent) err := json.Unmarshal([]byte(notificationInfo.Content), updateContent)
if err != nil { if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack() return fmt.Errorf("unmarshal notification content error: %w", err)
} }
updateContent.Rank = rank updateContent.Rank = rank
content, err := json.Marshal(updateContent) content, _ := json.Marshal(updateContent)
if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
}
notificationInfo.Content = string(content) notificationInfo.Content = string(content)
err = ns.notificationRepo.UpdateNotificationContent(ctx, notificationInfo) err = ns.notificationRepo.UpdateNotificationContent(ctx, notificationInfo)
if err != nil { if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack() return fmt.Errorf("update notification content error: %w", err)
} }
return nil return nil
} }
@ -154,16 +151,13 @@ func (ns *NotificationCommon) AddNotification(ctx context.Context, msg *schema.N
userBasicInfo, exist, err := ns.userCommon.GetUserBasicInfoByID(ctx, req.TriggerUserID) userBasicInfo, exist, err := ns.userCommon.GetUserBasicInfoByID(ctx, req.TriggerUserID)
if err != nil { if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack() return fmt.Errorf("get user basic info error: %w", err)
} }
if !exist { if !exist {
return errors.InternalServer(reason.UserNotFound).WithError(err).WithStack() return fmt.Errorf("user not exist: %s", req.TriggerUserID)
} }
req.UserInfo = userBasicInfo req.UserInfo = userBasicInfo
content, err := json.Marshal(req) content, _ := json.Marshal(req)
if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
}
_, ok := constant.NotificationMsgTypeMapping[req.NotificationAction] _, ok := constant.NotificationMsgTypeMapping[req.NotificationAction]
if ok { if ok {
info.MsgType = constant.NotificationMsgTypeMapping[req.NotificationAction] info.MsgType = constant.NotificationMsgTypeMapping[req.NotificationAction]
@ -171,7 +165,7 @@ func (ns *NotificationCommon) AddNotification(ctx context.Context, msg *schema.N
info.Content = string(content) info.Content = string(content)
err = ns.notificationRepo.AddNotification(ctx, info) err = ns.notificationRepo.AddNotification(ctx, info)
if err != nil { if err != nil {
return errors.InternalServer(reason.UnknownError).WithError(err).WithStack() return fmt.Errorf("add notification error: %w", err)
} }
err = ns.addRedDot(ctx, info.UserID, info.Type) err = ns.addRedDot(ctx, info.UserID, info.Type)
if err != nil { if err != nil {