chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"academy/internal/types"
|
||||
"academy/internal/types/interfaces"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type storageBackendRepository struct{ db *gorm.DB }
|
||||
|
||||
func NewStorageBackendRepository(db *gorm.DB) interfaces.StorageBackendRepository {
|
||||
return &storageBackendRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *storageBackendRepository) Create(ctx context.Context, backend *types.StorageBackend) error {
|
||||
return r.db.WithContext(ctx).Create(backend).Error
|
||||
}
|
||||
|
||||
func (r *storageBackendRepository) GetByID(ctx context.Context, tenantID uint64, id string) (*types.StorageBackend, error) {
|
||||
var backend types.StorageBackend
|
||||
if err := r.db.WithContext(ctx).Where("tenant_id = ? AND id = ?", tenantID, id).First(&backend).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &backend, nil
|
||||
}
|
||||
|
||||
func (r *storageBackendRepository) List(ctx context.Context, tenantID uint64) ([]*types.StorageBackend, error) {
|
||||
var backends []*types.StorageBackend
|
||||
err := r.db.WithContext(ctx).Where("tenant_id = ?", tenantID).Order("created_at DESC").Find(&backends).Error
|
||||
return backends, err
|
||||
}
|
||||
|
||||
func (r *storageBackendRepository) Update(ctx context.Context, backend *types.StorageBackend) error {
|
||||
return r.db.WithContext(ctx).Model(&types.StorageBackend{}).
|
||||
Where("tenant_id = ? AND id = ?", backend.TenantID, backend.ID).
|
||||
Select("name", "config", "status", "updated_at").Updates(backend).Error
|
||||
}
|
||||
|
||||
func (r *storageBackendRepository) Delete(ctx context.Context, tenantID uint64, id string) error {
|
||||
return r.db.WithContext(ctx).Where("tenant_id = ? AND id = ?", tenantID, id).Delete(&types.StorageBackend{}).Error
|
||||
}
|
||||
|
||||
func (r *storageBackendRepository) FindLegacyAlias(ctx context.Context, tenantID uint64, provider string) (*types.StorageBackend, error) {
|
||||
var backend types.StorageBackend
|
||||
if err := r.db.WithContext(ctx).Where("tenant_id = ? AND provider = ? AND legacy_alias = ?", tenantID, provider, true).First(&backend).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &backend, nil
|
||||
}
|
||||
Reference in new issue
Block a user