-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a use case for fetching a list of all available categories …
…and cetegory detail
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
lib/src/category/domain/repository/category_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:hadeeth/core/error/failures.dart'; | ||
import 'package:hadeeth/src/category/domain/entities/category.dart'; | ||
import 'package:hadeeth/src/category/domain/entities/category_detail.dart'; | ||
|
||
abstract class CategoryRepository { | ||
Future<Either<Failure, List<Category>>> getAllCategories( | ||
{required String lang}); | ||
Future<Either<Failure, CategoryDetail>> getCategoryDetail( | ||
{required String lang, | ||
required String categoryId, | ||
required String page, | ||
required String perPage}); | ||
} |
13 changes: 13 additions & 0 deletions
13
lib/src/category/domain/usecases/all_categories_usecase.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:hadeeth/core/error/failures.dart'; | ||
import 'package:hadeeth/src/category/domain/entities/category.dart'; | ||
import 'package:hadeeth/src/category/domain/repository/category_repository.dart'; | ||
|
||
class AllCategoriesUsecase { | ||
final CategoryRepository categoryRepo; | ||
const AllCategoriesUsecase({required this.categoryRepo}); | ||
Future<Either<Failure, List<Category>>> getAllCategories( | ||
{String lang = 'ar'}) async { | ||
return await categoryRepo.getAllCategories(lang: lang); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
lib/src/category/domain/usecases/category_detail_usecase.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:hadeeth/core/error/failures.dart'; | ||
import 'package:hadeeth/src/category/domain/entities/category_detail.dart'; | ||
import 'package:hadeeth/src/category/domain/repository/category_repository.dart'; | ||
|
||
class CategoryDetailUsecase { | ||
final CategoryRepository categoryRepo; | ||
const CategoryDetailUsecase({required this.categoryRepo}); | ||
Future<Either<Failure, CategoryDetail>> getCategoryDetail( | ||
{required String categoryId, | ||
String lang = 'ar', | ||
String page = '1', | ||
String perPage = '20'}) async { | ||
return await categoryRepo.getCategoryDetail( | ||
lang: lang, categoryId: categoryId, page: page, perPage: perPage); | ||
} | ||
} |