From 66aaa9b1529035c4ff5a45bd6f965b72aef541c7 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 24 Feb 2023 11:06:49 +0800 Subject: [PATCH] config path --- .../msgtransfer/persistent_msg_handler.go | 2 +- pkg/common/db/controller/chatlog.go | 35 ++++--------------- pkg/common/db/relation/chat_log_model.go | 2 +- 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/internal/msgtransfer/persistent_msg_handler.go b/internal/msgtransfer/persistent_msg_handler.go index 65634ba7e..1578f05ba 100644 --- a/internal/msgtransfer/persistent_msg_handler.go +++ b/internal/msgtransfer/persistent_msg_handler.go @@ -21,7 +21,7 @@ import ( type PersistentConsumerHandler struct { persistentConsumerGroup *kfk.MConsumerGroup - chatLogInterface controller.ChatLogInterface + chatLogInterface controller.ChatLogDatabase } func (pc *PersistentConsumerHandler) Init() { diff --git a/pkg/common/db/controller/chatlog.go b/pkg/common/db/controller/chatlog.go index 50ae13771..3771e78b0 100644 --- a/pkg/common/db/controller/chatlog.go +++ b/pkg/common/db/controller/chatlog.go @@ -1,50 +1,27 @@ package controller import ( - "OpenIM/pkg/common/db/relation" relationTb "OpenIM/pkg/common/db/table/relation" pbMsg "OpenIM/pkg/proto/msg" - "gorm.io/gorm" ) -type ChatLogInterface interface { +type ChatLogDatabase interface { CreateChatLog(msg pbMsg.MsgDataToMQ) error GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relationTb.ChatLogModel, error) } -func NewChatLogController(db *gorm.DB) ChatLogInterface { - return &ChatLogController{database: NewChatLogDataBase(db)} -} - -type ChatLogController struct { - database ChatLogDataBaseInterface -} - -func (c *ChatLogController) CreateChatLog(msg pbMsg.MsgDataToMQ) error { - return c.database.CreateChatLog(msg) -} - -func (c *ChatLogController) GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relationTb.ChatLogModel, error) { - return c.database.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList) -} - -type ChatLogDataBaseInterface interface { - CreateChatLog(msg pbMsg.MsgDataToMQ) error - GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relationTb.ChatLogModel, error) +func NewChatLogDatabase(chatLogModelInterface relationTb.ChatLogModelInterface) ChatLogDatabase { + return &ChatLogDataBase{chatLogModel: chatLogModelInterface} } type ChatLogDataBase struct { - chatLogDB relationTb.ChatLogModelInterface -} - -func NewChatLogDataBase(db *gorm.DB) ChatLogDataBaseInterface { - return &ChatLogDataBase{chatLogDB: relation.NewChatLog(db)} + chatLogModel relationTb.ChatLogModelInterface } func (c *ChatLogDataBase) CreateChatLog(msg pbMsg.MsgDataToMQ) error { - return c.chatLogDB.Create(msg) + return c.chatLogModel.Create(msg) } func (c *ChatLogDataBase) GetChatLog(chatLog *relationTb.ChatLogModel, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relationTb.ChatLogModel, error) { - return c.chatLogDB.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList) + return c.chatLogModel.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList) } diff --git a/pkg/common/db/relation/chat_log_model.go b/pkg/common/db/relation/chat_log_model.go index 17c85bbdf..69c0558ec 100644 --- a/pkg/common/db/relation/chat_log_model.go +++ b/pkg/common/db/relation/chat_log_model.go @@ -17,7 +17,7 @@ type ChatLogGorm struct { DB *gorm.DB } -func NewChatLog(db *gorm.DB) *ChatLogGorm { +func NewChatLogGorm(db *gorm.DB) *ChatLogGorm { return &ChatLogGorm{DB: db} }