Skip to content

Commit f32a832

Browse files
authored
Add rename model directory to entity to avoid name misunderstanding (#13829)
### What problem does this PR solve? Model-> entity ### Type of change - [x] Refactoring Signed-off-by: Jin Hai <haijin.chn@gmail.com>
1 parent 308b3a1 commit f32a832

72 files changed

Lines changed: 736 additions & 730 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/admin/service.go

Lines changed: 50 additions & 49 deletions
Large diffs are not rendered by default.

internal/dao/api_token.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package dao
1818

1919
import (
20-
"ragflow/internal/model"
20+
"ragflow/internal/entity"
2121
)
2222

2323
// APITokenDAO API token data access object
@@ -29,26 +29,26 @@ func NewAPITokenDAO() *APITokenDAO {
2929
}
3030

3131
// Create creates a new API token
32-
func (dao *APITokenDAO) Create(apiToken *model.APIToken) error {
32+
func (dao *APITokenDAO) Create(apiToken *entity.APIToken) error {
3333
return DB.Create(apiToken).Error
3434
}
3535

3636
// GetByTenantID gets API tokens by tenant ID
37-
func (dao *APITokenDAO) GetByTenantID(tenantID string) ([]*model.APIToken, error) {
38-
var tokens []*model.APIToken
37+
func (dao *APITokenDAO) GetByTenantID(tenantID string) ([]*entity.APIToken, error) {
38+
var tokens []*entity.APIToken
3939
err := DB.Where("tenant_id = ?", tenantID).Find(&tokens).Error
4040
return tokens, err
4141
}
4242

4343
// DeleteByTenantID deletes all API tokens by tenant ID (hard delete)
4444
func (dao *APITokenDAO) DeleteByTenantID(tenantID string) (int64, error) {
45-
result := DB.Unscoped().Where("tenant_id = ?", tenantID).Delete(&model.APIToken{})
45+
result := DB.Unscoped().Where("tenant_id = ?", tenantID).Delete(&entity.APIToken{})
4646
return result.RowsAffected, result.Error
4747
}
4848

4949
// GetByToken gets API token by access key
50-
func (dao *APITokenDAO) GetUserByAPIToken(token string) (*model.APIToken, error) {
51-
var apiToken model.APIToken
50+
func (dao *APITokenDAO) GetUserByAPIToken(token string) (*entity.APIToken, error) {
51+
var apiToken entity.APIToken
5252
err := DB.Where("token = ?", token).First(&apiToken).Error
5353
if err != nil {
5454
return nil, err
@@ -61,13 +61,13 @@ func (dao *APITokenDAO) DeleteByDialogIDs(dialogIDs []string) (int64, error) {
6161
if len(dialogIDs) == 0 {
6262
return 0, nil
6363
}
64-
result := DB.Unscoped().Where("dialog_id IN ?", dialogIDs).Delete(&model.APIToken{})
64+
result := DB.Unscoped().Where("dialog_id IN ?", dialogIDs).Delete(&entity.APIToken{})
6565
return result.RowsAffected, result.Error
6666
}
6767

6868
// DeleteByTenantIDAndToken deletes a specific API token by tenant ID and token value
6969
func (dao *APITokenDAO) DeleteByTenantIDAndToken(tenantID, token string) (int64, error) {
70-
result := DB.Unscoped().Where("tenant_id = ? AND token = ?", tenantID, token).Delete(&model.APIToken{})
70+
result := DB.Unscoped().Where("tenant_id = ? AND token = ?", tenantID, token).Delete(&entity.APIToken{})
7171
return result.RowsAffected, result.Error
7272
}
7373

@@ -84,6 +84,6 @@ func (dao *API4ConversationDAO) DeleteByDialogIDs(dialogIDs []string) (int64, er
8484
if len(dialogIDs) == 0 {
8585
return 0, nil
8686
}
87-
result := DB.Unscoped().Where("dialog_id IN ?", dialogIDs).Delete(&model.API4Conversation{})
87+
result := DB.Unscoped().Where("dialog_id IN ?", dialogIDs).Delete(&entity.API4Conversation{})
8888
return result.RowsAffected, result.Error
8989
}

internal/dao/chat.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ package dao
1818

1919
import (
2020
"fmt"
21+
"ragflow/internal/entity"
2122
"strings"
22-
23-
"ragflow/internal/model"
2423
)
2524

2625
// ChatDAO chat data access object
@@ -32,10 +31,10 @@ func NewChatDAO() *ChatDAO {
3231
}
3332

3433
// ListByTenantID list chats by tenant ID
35-
func (dao *ChatDAO) ListByTenantID(tenantID string, status string) ([]*model.Chat, error) {
36-
var chats []*model.Chat
34+
func (dao *ChatDAO) ListByTenantID(tenantID string, status string) ([]*entity.Chat, error) {
35+
var chats []*entity.Chat
3736

38-
query := DB.Model(&model.Chat{}).
37+
query := DB.Model(&entity.Chat{}).
3938
Where("tenant_id = ?", tenantID)
4039

4140
if status != "" {
@@ -51,12 +50,12 @@ func (dao *ChatDAO) ListByTenantID(tenantID string, status string) ([]*model.Cha
5150
}
5251

5352
// ListByTenantIDs list chats by tenant IDs with pagination and filtering
54-
func (dao *ChatDAO) ListByTenantIDs(tenantIDs []string, userID string, page, pageSize int, orderby string, desc bool, keywords string) ([]*model.Chat, int64, error) {
55-
var chats []*model.Chat
53+
func (dao *ChatDAO) ListByTenantIDs(tenantIDs []string, userID string, page, pageSize int, orderby string, desc bool, keywords string) ([]*entity.Chat, int64, error) {
54+
var chats []*entity.Chat
5655
var total int64
5756

5857
// Build query with join to user table for nickname and avatar
59-
query := DB.Model(&model.Chat{}).
58+
query := DB.Model(&entity.Chat{}).
6059
Select(`
6160
dialog.*,
6261
user.nickname,
@@ -103,11 +102,11 @@ func (dao *ChatDAO) ListByTenantIDs(tenantIDs []string, userID string, page, pag
103102
}
104103

105104
// ListByOwnerIDs list chats by owner IDs with filtering (manual pagination)
106-
func (dao *ChatDAO) ListByOwnerIDs(ownerIDs []string, userID string, orderby string, desc bool, keywords string) ([]*model.Chat, int64, error) {
107-
var chats []*model.Chat
105+
func (dao *ChatDAO) ListByOwnerIDs(ownerIDs []string, userID string, orderby string, desc bool, keywords string) ([]*entity.Chat, int64, error) {
106+
var chats []*entity.Chat
108107

109108
// Build query with join to user table
110-
query := DB.Model(&model.Chat{}).
109+
query := DB.Model(&entity.Chat{}).
111110
Select(`
112111
dialog.*,
113112
user.nickname,
@@ -142,8 +141,8 @@ func (dao *ChatDAO) ListByOwnerIDs(ownerIDs []string, userID string, orderby str
142141
}
143142

144143
// GetByID gets chat by ID
145-
func (dao *ChatDAO) GetByID(id string) (*model.Chat, error) {
146-
var chat model.Chat
144+
func (dao *ChatDAO) GetByID(id string) (*entity.Chat, error) {
145+
var chat entity.Chat
147146
err := DB.Where("id = ?", id).First(&chat).Error
148147
if err != nil {
149148
return nil, err
@@ -152,8 +151,8 @@ func (dao *ChatDAO) GetByID(id string) (*model.Chat, error) {
152151
}
153152

154153
// GetByIDAndStatus gets chat by ID and status
155-
func (dao *ChatDAO) GetByIDAndStatus(id string, status string) (*model.Chat, error) {
156-
var chat model.Chat
154+
func (dao *ChatDAO) GetByIDAndStatus(id string, status string) (*entity.Chat, error) {
155+
var chat entity.Chat
157156
err := DB.Where("id = ? AND status = ?", id, status).First(&chat).Error
158157
if err != nil {
159158
return nil, err
@@ -164,20 +163,20 @@ func (dao *ChatDAO) GetByIDAndStatus(id string, status string) (*model.Chat, err
164163
// GetExistingNames gets existing dialog names for a tenant
165164
func (dao *ChatDAO) GetExistingNames(tenantID string, status string) ([]string, error) {
166165
var names []string
167-
err := DB.Model(&model.Chat{}).
166+
err := DB.Model(&entity.Chat{}).
168167
Where("tenant_id = ? AND status = ?", tenantID, status).
169168
Pluck("name", &names).Error
170169
return names, err
171170
}
172171

173172
// Create creates a new chat/dialog
174-
func (dao *ChatDAO) Create(chat *model.Chat) error {
173+
func (dao *ChatDAO) Create(chat *entity.Chat) error {
175174
return DB.Create(chat).Error
176175
}
177176

178177
// UpdateByID updates a chat by ID
179178
func (dao *ChatDAO) UpdateByID(id string, updates map[string]interface{}) error {
180-
return DB.Model(&model.Chat{}).Where("id = ?", id).Updates(updates).Error
179+
return DB.Model(&entity.Chat{}).Where("id = ?", id).Updates(updates).Error
181180
}
182181

183182
// UpdateManyByID updates multiple chats by ID (batch update)
@@ -207,7 +206,7 @@ func (dao *ChatDAO) UpdateManyByID(updates []map[string]interface{}) error {
207206
}
208207
}
209208

210-
if err := tx.Model(&model.Chat{}).Where("id = ?", id).Updates(updatesWithoutID).Error; err != nil {
209+
if err := tx.Model(&entity.Chat{}).Where("id = ?", id).Updates(updatesWithoutID).Error; err != nil {
211210
tx.Rollback()
212211
return err
213212
}
@@ -218,14 +217,14 @@ func (dao *ChatDAO) UpdateManyByID(updates []map[string]interface{}) error {
218217

219218
// DeleteByTenantID deletes all chats by tenant ID (hard delete)
220219
func (dao *ChatDAO) DeleteByTenantID(tenantID string) (int64, error) {
221-
result := DB.Unscoped().Where("tenant_id = ?", tenantID).Delete(&model.Chat{})
220+
result := DB.Unscoped().Where("tenant_id = ?", tenantID).Delete(&entity.Chat{})
222221
return result.RowsAffected, result.Error
223222
}
224223

225224
// GetAllDialogIDsByTenantID gets all dialog IDs by tenant ID
226225
func (dao *ChatDAO) GetAllDialogIDsByTenantID(tenantID string) ([]string, error) {
227226
var dialogIDs []string
228-
err := DB.Model(&model.Chat{}).
227+
err := DB.Model(&entity.Chat{}).
229228
Where("tenant_id = ?", tenantID).
230229
Pluck("id", &dialogIDs).Error
231230
return dialogIDs, err

internal/dao/chat_session.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package dao
1818

1919
import (
20-
"ragflow/internal/model"
20+
"ragflow/internal/entity"
2121
)
2222

2323
// ChatSessionDAO chat session data access object
@@ -29,8 +29,8 @@ func NewChatSessionDAO() *ChatSessionDAO {
2929
}
3030

3131
// GetByID gets chat session by ID
32-
func (dao *ChatSessionDAO) GetByID(id string) (*model.ChatSession, error) {
33-
var conv model.ChatSession
32+
func (dao *ChatSessionDAO) GetByID(id string) (*entity.ChatSession, error) {
33+
var conv entity.ChatSession
3434
err := DB.Where("id = ?", id).First(&conv).Error
3535
if err != nil {
3636
return nil, err
@@ -39,23 +39,23 @@ func (dao *ChatSessionDAO) GetByID(id string) (*model.ChatSession, error) {
3939
}
4040

4141
// Create creates a new chat session
42-
func (dao *ChatSessionDAO) Create(conv *model.ChatSession) error {
42+
func (dao *ChatSessionDAO) Create(conv *entity.ChatSession) error {
4343
return DB.Create(conv).Error
4444
}
4545

4646
// UpdateByID updates a chat session by ID
4747
func (dao *ChatSessionDAO) UpdateByID(id string, updates map[string]interface{}) error {
48-
return DB.Model(&model.ChatSession{}).Where("id = ?", id).Updates(updates).Error
48+
return DB.Model(&entity.ChatSession{}).Where("id = ?", id).Updates(updates).Error
4949
}
5050

5151
// DeleteByID deletes a chat session by ID (hard delete)
5252
func (dao *ChatSessionDAO) DeleteByID(id string) error {
53-
return DB.Where("id = ?", id).Delete(&model.ChatSession{}).Error
53+
return DB.Where("id = ?", id).Delete(&entity.ChatSession{}).Error
5454
}
5555

5656
// ListByDialogID lists chat sessions by dialog ID
57-
func (dao *ChatSessionDAO) ListByDialogID(dialogID string) ([]*model.ChatSession, error) {
58-
var convs []*model.ChatSession
57+
func (dao *ChatSessionDAO) ListByDialogID(dialogID string) ([]*entity.ChatSession, error) {
58+
var convs []*entity.ChatSession
5959
err := DB.Where("dialog_id = ?", dialogID).
6060
Order("create_time DESC").
6161
Find(&convs).Error
@@ -65,7 +65,7 @@ func (dao *ChatSessionDAO) ListByDialogID(dialogID string) ([]*model.ChatSession
6565
// CheckDialogExists checks if a dialog exists with given tenant_id and dialog_id
6666
func (dao *ChatSessionDAO) CheckDialogExists(tenantID, dialogID string) (bool, error) {
6767
var count int64
68-
err := DB.Model(&model.Chat{}).
68+
err := DB.Model(&entity.Chat{}).
6969
Where("tenant_id = ? AND id = ? AND status = ?", tenantID, dialogID, "1").
7070
Count(&count).Error
7171
if err != nil {
@@ -75,8 +75,8 @@ func (dao *ChatSessionDAO) CheckDialogExists(tenantID, dialogID string) (bool, e
7575
}
7676

7777
// GetDialogByID gets dialog by ID
78-
func (dao *ChatSessionDAO) GetDialogByID(dialogID string) (*model.Chat, error) {
79-
var dialog model.Chat
78+
func (dao *ChatSessionDAO) GetDialogByID(dialogID string) (*entity.Chat, error) {
79+
var dialog entity.Chat
8080
err := DB.Where("id = ? AND status = ?", dialogID, "1").First(&dialog).Error
8181
if err != nil {
8282
return nil, err
@@ -89,6 +89,6 @@ func (dao *ChatSessionDAO) DeleteByDialogIDs(dialogIDs []string) (int64, error)
8989
if len(dialogIDs) == 0 {
9090
return 0, nil
9191
}
92-
result := DB.Unscoped().Where("dialog_id IN ?", dialogIDs).Delete(&model.ChatSession{})
92+
result := DB.Unscoped().Where("dialog_id IN ?", dialogIDs).Delete(&entity.ChatSession{})
9393
return result.RowsAffected, result.Error
9494
}

internal/dao/connector.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package dao
1818

1919
import (
20-
"ragflow/internal/model"
20+
"ragflow/internal/entity"
2121
)
2222

2323
// ConnectorDAO connector data access object
@@ -41,7 +41,7 @@ type ConnectorListItem struct {
4141
func (dao *ConnectorDAO) ListByTenantID(tenantID string) ([]*ConnectorListItem, error) {
4242
var connectors []*ConnectorListItem
4343

44-
err := DB.Model(&model.Connector{}).
44+
err := DB.Model(&entity.Connector{}).
4545
Select("id", "name", "source", "status").
4646
Where("tenant_id = ?", tenantID).
4747
Find(&connectors).Error
@@ -54,8 +54,8 @@ func (dao *ConnectorDAO) ListByTenantID(tenantID string) ([]*ConnectorListItem,
5454
}
5555

5656
// GetByID get connector by ID
57-
func (dao *ConnectorDAO) GetByID(id string) (*model.Connector, error) {
58-
var connector model.Connector
57+
func (dao *ConnectorDAO) GetByID(id string) (*entity.Connector, error) {
58+
var connector entity.Connector
5959
err := DB.Where("id = ?", id).First(&connector).Error
6060
if err != nil {
6161
return nil, err
@@ -64,16 +64,16 @@ func (dao *ConnectorDAO) GetByID(id string) (*model.Connector, error) {
6464
}
6565

6666
// Create create a new connector
67-
func (dao *ConnectorDAO) Create(connector *model.Connector) error {
67+
func (dao *ConnectorDAO) Create(connector *entity.Connector) error {
6868
return DB.Create(connector).Error
6969
}
7070

7171
// UpdateByID update connector by ID
7272
func (dao *ConnectorDAO) UpdateByID(id string, updates map[string]interface{}) error {
73-
return DB.Model(&model.Connector{}).Where("id = ?", id).Updates(updates).Error
73+
return DB.Model(&entity.Connector{}).Where("id = ?", id).Updates(updates).Error
7474
}
7575

7676
// DeleteByID delete connector by ID
7777
func (dao *ConnectorDAO) DeleteByID(id string) error {
78-
return DB.Where("id = ?", id).Delete(&model.Connector{}).Error
78+
return DB.Where("id = ?", id).Delete(&entity.Connector{}).Error
7979
}

0 commit comments

Comments
 (0)