Line data Source code
1 : import 'package:app_pym/domain/entities/app_pym/post.dart';
2 : import 'package:app_pym/domain/repositories/app_pym/post_repository.dart';
3 : import 'package:injectable/injectable.dart';
4 :
5 : import '../../../core/usecases/usecase.dart';
6 :
7 : @prod
8 : @lazySingleton
9 : class GetPosts extends Usecase<Future<List<Post>>, NoParams> {
10 : final PostRepository repository;
11 :
12 1 : const GetPosts(this.repository);
13 :
14 : @override
15 1 : Future<List<Post>> call(NoParams _) async {
16 3 : final posts = await repository.fetchAll();
17 1 : posts.sort((a, b) => -a.published.compareTo(b.published));
18 : return posts;
19 : }
20 : }
|