nc-photos/lib/entity/share.dart

76 lines
1.9 KiB
Dart
Raw Normal View History

2021-08-07 22:34:44 +02:00
import 'package:equatable/equatable.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/file.dart';
class Share with EquatableMixin {
Share({
required this.id,
2021-08-13 12:42:31 +02:00
required this.path,
2021-08-07 22:34:44 +02:00
required this.shareType,
required this.shareWith,
required this.shareWithDisplayName,
});
@override
toString() {
return "$runtimeType {"
"id: $id, "
2021-08-13 12:42:31 +02:00
"path: $path, "
2021-08-07 22:34:44 +02:00
"shareType: $shareType, "
"shareWith: $shareWith, "
"shareWithDisplayName: $shareWithDisplayName, "
"}";
}
@override
get props => [
id,
2021-08-13 12:42:31 +02:00
path,
2021-08-07 22:34:44 +02:00
shareType,
shareWith,
shareWithDisplayName,
];
final String id;
2021-08-13 12:42:31 +02:00
final String path;
2021-08-07 22:34:44 +02:00
final int shareType;
final String shareWith;
final String shareWithDisplayName;
}
class ShareRepo {
ShareRepo(this.dataSrc);
/// See [ShareDataSource.list]
Future<List<Share>> list(Account account, File file) =>
this.dataSrc.list(account, file);
2021-08-13 12:42:31 +02:00
/// See [ShareDataSource.listDir]
Future<List<Share>> listDir(Account account, File dir) =>
this.dataSrc.listDir(account, dir);
2021-08-07 22:34:44 +02:00
/// See [ShareDataSource.create]
Future<Share> create(Account account, File file, String shareWith) =>
this.dataSrc.create(account, file, shareWith);
/// See [ShareDataSource.delete]
Future<void> delete(Account account, Share share) =>
this.dataSrc.delete(account, share);
final ShareDataSource dataSrc;
}
abstract class ShareDataSource {
/// List all shares from a given file
Future<List<Share>> list(Account account, File file);
2021-08-13 12:42:31 +02:00
/// List all shares from a given directory
Future<List<Share>> listDir(Account account, File dir);
2021-08-07 22:34:44 +02:00
/// Share a file/folder with a user
Future<Share> create(Account account, File file, String shareWith);
/// Remove the given share
Future<void> delete(Account account, Share share);
}