package cache import ( "carrot_bbs/internal/model" "carrot_bbs/internal/repository" ) // ConversationRepositoryAdapter 适配 MessageRepository 到 ConversationRepository 接口 type ConversationRepositoryAdapter struct { repo *repository.MessageRepository } // NewConversationRepositoryAdapter 创建适配器 func NewConversationRepositoryAdapter(repo *repository.MessageRepository) ConversationRepository { return &ConversationRepositoryAdapter{repo: repo} } // GetConversationByID 实现 ConversationRepository 接口 func (a *ConversationRepositoryAdapter) GetConversationByID(convID string) (*model.Conversation, error) { return a.repo.GetConversation(convID) } // GetConversationsByUserID 实现 ConversationRepository 接口 func (a *ConversationRepositoryAdapter) GetConversationsByUserID(userID string, page, pageSize int) ([]*model.Conversation, int64, error) { return a.repo.GetConversations(userID, page, pageSize) } // GetParticipant 实现 ConversationRepository 接口 func (a *ConversationRepositoryAdapter) GetParticipant(convID, userID string) (*model.ConversationParticipant, error) { return a.repo.GetParticipant(convID, userID) } // GetParticipants 实现 ConversationRepository 接口 func (a *ConversationRepositoryAdapter) GetParticipants(convID string) ([]*model.ConversationParticipant, error) { return a.repo.GetConversationParticipants(convID) } // GetUnreadCount 实现 ConversationRepository 接口 func (a *ConversationRepositoryAdapter) GetUnreadCount(userID, convID string) (int64, error) { return a.repo.GetUnreadCount(convID, userID) } // MessageRepositoryAdapter 适配 MessageRepository 到 MessageRepository 接口 type MessageRepositoryAdapter struct { repo *repository.MessageRepository } // NewMessageRepositoryAdapter 创建适配器 func NewMessageRepositoryAdapter(repo *repository.MessageRepository) MessageRepository { return &MessageRepositoryAdapter{repo: repo} } // GetMessages 实现 MessageRepository 接口 func (a *MessageRepositoryAdapter) GetMessages(convID string, page, pageSize int) ([]*model.Message, int64, error) { return a.repo.GetMessages(convID, page, pageSize) } // GetMessagesAfterSeq 实现 MessageRepository 接口 func (a *MessageRepositoryAdapter) GetMessagesAfterSeq(convID string, afterSeq int64, limit int) ([]*model.Message, error) { return a.repo.GetMessagesAfterSeq(convID, afterSeq, limit) } // GetMessagesBeforeSeq 实现 MessageRepository 接口 func (a *MessageRepositoryAdapter) GetMessagesBeforeSeq(convID string, beforeSeq int64, limit int) ([]*model.Message, error) { return a.repo.GetMessagesBeforeSeq(convID, beforeSeq, limit) } // CreateMessage 实现 MessageRepository 接口 func (a *MessageRepositoryAdapter) CreateMessage(msg *model.Message) error { return a.repo.CreateMessage(msg) } // UpdateConversationLastSeq 实现 MessageRepository 接口 func (a *MessageRepositoryAdapter) UpdateConversationLastSeq(convID string, seq int64) error { return a.repo.UpdateConversationLastSeq(convID, seq) }