mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 23:06:21 +01:00
36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
import 'package:logging/logging.dart';
|
|
import 'package:nc_photos/account.dart';
|
|
import 'package:nc_photos/entity/album.dart';
|
|
import 'package:nc_photos/entity/album/item.dart';
|
|
import 'package:nc_photos/entity/album/provider.dart';
|
|
import 'package:nc_photos/iterable_extension.dart';
|
|
import 'package:nc_photos/use_case/update_album.dart';
|
|
|
|
class RemoveFromAlbum {
|
|
RemoveFromAlbum(this.albumRepo);
|
|
|
|
/// Remove a list of AlbumItems from [album]
|
|
///
|
|
/// The items are compared with [identical], so it must come from [album] for
|
|
/// it to work
|
|
Future<Album> call(
|
|
Account account, Album album, List<AlbumItem> items) async {
|
|
_log.info("[call] Remove ${items.length} items from album '${album.name}'");
|
|
assert(album.provider is AlbumStaticProvider);
|
|
final provider = album.provider as AlbumStaticProvider;
|
|
final newItems = provider.items
|
|
.where((element) => !items.containsIdentical(element))
|
|
.toList();
|
|
var newAlbum = album.copyWith(
|
|
provider: AlbumStaticProvider.of(album).copyWith(
|
|
items: newItems,
|
|
),
|
|
);
|
|
await UpdateAlbum(albumRepo)(account, newAlbum);
|
|
return newAlbum;
|
|
}
|
|
|
|
final AlbumRepo albumRepo;
|
|
|
|
static final _log = Logger("use_case.remove_from_album.RemoveFromAlbum");
|
|
}
|