Skip to content

Commit

Permalink
Implement a use case for fetching a list of all available categories …
Browse files Browse the repository at this point in the history
…and cetegory detail
  • Loading branch information
zaihcodes committed Dec 19, 2023
1 parent 5937bfe commit ff61c93
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/src/category/domain/repository/category_repository.dart
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 lib/src/category/domain/usecases/all_categories_usecase.dart
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 lib/src/category/domain/usecases/category_detail_usecase.dart
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);
}
}

0 comments on commit ff61c93

Please sign in to comment.