feat: 重构前后端架构,添加Go后端和Python Agent服务
- 新增 Go 语言后端服务(server/),包含用户认证、Agent管理、数据库连接等API - 新增 Python Agent 服务(agent/),实现Agent核心逻辑和工具集 - 前端从原生HTML迁移到Vue.js框架(web/src/) - 添加 Docker Compose 支持(docker-compose.yml) - 添加项目架构文档(docs/ARCHITECTURE.md) - 添加环境变量示例(.env.example)和本地启动脚本(start-local.ps1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
47
server/internal/repository/database_repo.go
Normal file
47
server/internal/repository/database_repo.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"x-agents/server/internal/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DatabaseRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewDatabaseRepository(db *gorm.DB) *DatabaseRepository {
|
||||
return &DatabaseRepository{db: db}
|
||||
}
|
||||
|
||||
// Create 创建数据库信息
|
||||
func (r *DatabaseRepository) Create(info *model.DatabaseInfo) error {
|
||||
return r.db.Create(info).Error
|
||||
}
|
||||
|
||||
// FindByID 根据ID查询
|
||||
func (r *DatabaseRepository) FindByID(id string) (*model.DatabaseInfo, error) {
|
||||
var info model.DatabaseInfo
|
||||
err := r.db.First(&info, "id = ?", id).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// FindAll 查询所有
|
||||
func (r *DatabaseRepository) FindAll() ([]model.DatabaseInfo, error) {
|
||||
var list []model.DatabaseInfo
|
||||
err := r.db.Order("created_at DESC").Find(&list).Error
|
||||
return list, err
|
||||
}
|
||||
|
||||
// Update 更新
|
||||
func (r *DatabaseRepository) Update(id string, info *model.DatabaseInfo) error {
|
||||
return r.db.Model(&model.DatabaseInfo{}).Where("id = ?", id).Updates(info).Error
|
||||
}
|
||||
|
||||
// Delete 删除
|
||||
func (r *DatabaseRepository) Delete(id string) error {
|
||||
return r.db.Delete(&model.DatabaseInfo{}, "id = ?", id).Error
|
||||
}
|
||||
Reference in New Issue
Block a user