mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-08 02:03:42 +08:00
refactor: V3 版本重构已基本完成
This commit is contained in:
35
api/go/service/chat_role_service.go
Normal file
35
api/go/service/chat_role_service.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"chatplus/store/model"
|
||||
"chatplus/store/vo"
|
||||
"chatplus/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ChatRoleService struct {
|
||||
DB *gorm.DB
|
||||
Model interface{}
|
||||
}
|
||||
|
||||
func NewChatRoleService(db *gorm.DB) *ChatRoleService {
|
||||
return &ChatRoleService{DB: db, Model: &model.ChatRole{}}
|
||||
}
|
||||
|
||||
func (s *ChatRoleService) Create(value interface{}) error {
|
||||
r, ok := value.(vo.ChatRole)
|
||||
|
||||
if ok {
|
||||
var role model.ChatRole
|
||||
err := utils.CopyObject(r, &role)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result := s.DB.Create(&role)
|
||||
return result.Error
|
||||
} else {
|
||||
result := s.DB.Create(value)
|
||||
return result.Error
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user