This commit performs a significant cleanup of the codebase by removing unused functions, methods, and entire files across various internal modules. This reduces technical debt and simplifies the project structure. Key changes include: - **cache**: Removed unused cache key generators and metrics snapshots. - **dto**: Removed redundant converter functions and segment creation helpers. - **middleware**: Deleted the unused `logger.go` middleware and simplified `ratelimit.go` and `casbin.go`. - **model**: Removed unused ID helpers, database closing functions, and batch decryption logic. - **pkg**: Cleaned up unused utility functions in `circuitbreaker`, `crypto`, `cursor`, `hook`, and `utils`. - **service**: Deleted `account_cleanup_service.go` and removed unused helper functions in `log_cleanup_service.go` and `sensitive_service.go`. - **repository**: Removed unused private loading methods in `comment_repo.go`.
78 lines
2.5 KiB
Go
78 lines
2.5 KiB
Go
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
|
|
}
|
|
|