Files
b0esche_cloud/b0esche_cloud/lib/services/file_service.dart
2025-12-17 01:49:45 +01:00

73 lines
1.9 KiB
Dart

import '../models/file_item.dart';
import '../repositories/file_repository.dart';
class FileService {
final FileRepository _fileRepository;
FileService(this._fileRepository);
Future<List<FileItem>> getFiles(String orgId, String path) async {
if (path.isEmpty) {
throw Exception('Path cannot be empty');
}
return await _fileRepository.getFiles(orgId, path);
}
Future<FileItem?> getFile(String orgId, String path) async {
if (path.isEmpty) {
return null;
}
return await _fileRepository.getFile(orgId, path);
}
Future<void> uploadFile(String orgId, FileItem file) async {
if (file.name.isEmpty) {
throw Exception('File name cannot be empty');
}
await _fileRepository.uploadFile(orgId, file);
}
Future<void> deleteFile(String orgId, String path) async {
if (path.isEmpty) {
throw Exception('Path cannot be empty');
}
await _fileRepository.deleteFile(orgId, path);
}
Future<void> createFolder(
String orgId,
String parentPath,
String folderName,
) async {
if (folderName.isEmpty) {
throw Exception('Folder name cannot be empty');
}
await _fileRepository.createFolder(orgId, parentPath, folderName);
}
Future<void> moveFile(
String orgId,
String sourcePath,
String targetPath,
) async {
if (sourcePath.isEmpty || targetPath.isEmpty) {
throw Exception('Paths cannot be empty');
}
await _fileRepository.moveFile(orgId, sourcePath, targetPath);
}
Future<void> renameFile(String orgId, String path, String newName) async {
if (path.isEmpty || newName.isEmpty) {
throw Exception('Path and new name cannot be empty');
}
await _fileRepository.renameFile(orgId, path, newName);
}
Future<List<FileItem>> searchFiles(String orgId, String query) async {
if (query.isEmpty) {
return [];
}
return await _fileRepository.searchFiles(orgId, query);
}
}