.
This commit is contained in:
67
internal/api/backup_api.go
Normal file
67
internal/api/backup_api.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ssq-desk/internal/service"
|
||||
)
|
||||
|
||||
// BackupAPI 数据备份 API
|
||||
type BackupAPI struct {
|
||||
backupService *service.BackupService
|
||||
}
|
||||
|
||||
// NewBackupAPI 创建数据备份 API
|
||||
func NewBackupAPI() *BackupAPI {
|
||||
return &BackupAPI{
|
||||
backupService: service.NewBackupService(),
|
||||
}
|
||||
}
|
||||
|
||||
// Backup 备份数据
|
||||
func (api *BackupAPI) Backup() (map[string]interface{}, error) {
|
||||
result, err := api.backupService.Backup()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"backup_path": result.BackupPath,
|
||||
"file_name": result.FileName,
|
||||
"file_size": result.FileSize,
|
||||
"created_at": result.CreatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Restore 恢复数据
|
||||
func (api *BackupAPI) Restore(backupPath string) (map[string]interface{}, error) {
|
||||
if err := api.backupService.Restore(backupPath); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"success": true,
|
||||
"message": "数据恢复成功",
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListBackups 列出所有备份
|
||||
func (api *BackupAPI) ListBackups() (map[string]interface{}, error) {
|
||||
backups, err := api.backupService.ListBackups()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
backupList := make([]map[string]interface{}, len(backups))
|
||||
for i, backup := range backups {
|
||||
backupList[i] = map[string]interface{}{
|
||||
"backup_path": backup.BackupPath,
|
||||
"file_name": backup.FileName,
|
||||
"file_size": backup.FileSize,
|
||||
"created_at": backup.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"backups": backupList,
|
||||
"count": len(backupList),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user