package dto import ( "with_you/internal/model" "strconv" ) // ==================== Notification 转换 ==================== // ConvertNotificationToResponse 将Notification转换为NotificationResponse func ConvertNotificationToResponse(notification *model.Notification) *NotificationResponse { if notification == nil { return nil } return &NotificationResponse{ ID: notification.ID, UserID: notification.UserID, Type: string(notification.Type), Title: notification.Title, Content: notification.Content, Data: notification.Data, IsRead: notification.IsRead, CreatedAt: FormatTime(notification.CreatedAt), } } // ConvertNotificationsToResponse 将Notification列表转换为响应列表 func ConvertNotificationsToResponse(notifications []*model.Notification) []*NotificationResponse { result := make([]*NotificationResponse, 0, len(notifications)) for _, n := range notifications { result = append(result, ConvertNotificationToResponse(n)) } return result } // SystemNotificationToResponse 将SystemNotification转换为SystemMessageResponse func SystemNotificationToResponse(n *model.SystemNotification) *SystemMessageResponse { if n == nil { return nil } resp := &SystemMessageResponse{ ID: strconv.FormatInt(n.ID, 10), SenderID: model.SystemSenderIDStr, // 系统发送者 ReceiverID: n.ReceiverID, Content: n.Content, Category: "notification", SystemType: string(n.Type), IsRead: n.IsRead, CreatedAt: n.CreatedAt, } if n.ExtraData != nil { resp.ExtraData = map[string]any{ "actor_id": n.ExtraData.ActorID, "actor_id_str": n.ExtraData.ActorIDStr, "actor_name": n.ExtraData.ActorName, "avatar_url": n.ExtraData.AvatarURL, "target_id": n.ExtraData.TargetID, "target_title": n.ExtraData.TargetTitle, "target_type": n.ExtraData.TargetType, "action_url": n.ExtraData.ActionURL, "action_time": n.ExtraData.ActionTime, "group_id": n.ExtraData.GroupID, "group_name": n.ExtraData.GroupName, "group_avatar": n.ExtraData.GroupAvatar, "group_description": n.ExtraData.GroupDescription, "flag": n.ExtraData.Flag, "request_type": n.ExtraData.RequestType, "request_status": n.ExtraData.RequestStatus, "reason": n.ExtraData.Reason, "target_user_id": n.ExtraData.TargetUserID, "target_user_name": n.ExtraData.TargetUserName, "target_user_avatar": n.ExtraData.TargetUserAvatar, } } return resp }