Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
fix: change the DataState in usecase
Browse files Browse the repository at this point in the history
update the DataState class in usecase with the new changes, correct typo in product_bloc_test.dart

linked #16
  • Loading branch information
MeloLawson authored and MansourWolou committed Dec 24, 2023
1 parent 3e5f3e8 commit 4c63375
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class ProductRepositoryImpl implements ProductRepository {
// If the server did return a 200 OK response,
// then parse the JSON.
Product product = Product.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
return DataSuccess(product);
return Success(product);
} else {
List messages = ["Error"];
return DataFailed(messages);
return Error(messages);
}
}

Expand All @@ -31,13 +31,13 @@ class ProductRepositoryImpl implements ProductRepository {
if(response.statusCode == 200){
List body = json.decode(response.body);
List products = body.map((e) => Product.fromJson(e)).toList();
return DataSuccess(products);
return Success(products);
}else{
List messages = ["Error"];
return DataFailed(messages);
return Error(messages);
}
}catch(err){
return DataFailed([err.toString()]);
return Error([err.toString()]);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class GetAllProducts implements UseCase<List<Product>, void> {
Future<List<Product>> call({void params}) async {
DataState result = await productRepository.getAllProducts();
try {
if (result is DataSuccess) {
if (result is Success) {
//return product list
return result.data;
} else {
throw Exception("Didn't get products ; ${result.errorMessage}");
throw Exception("Didn't get products ; ${result.error.toString()}");
}
} catch (err) {
// return empty array
Expand Down
4 changes: 2 additions & 2 deletions terminal/lib/features/product/domain/usecase/get_product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class GetProduct implements UseCase<Product?, int> {
if(params != null){
DataState result = await productRepository.getProduct(params);
try {
if (result is DataSuccess) {
if (result is Success) {
//return product
return result.data;
} else {
throw Exception("This product is not found ; ${result.errorMessage}");
throw Exception("This product is not found ; ${result.error.toString()}");
}
} catch (err) {
// return null TODO à changer
Expand Down
3 changes: 2 additions & 1 deletion terminal/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:terminal/features/transaction/presentation/check_scan.dart';
import 'package:terminal/injection_container.dart';

import 'config/app_router.dart';

void main() async {
await initializeDependencies();
runApp( const MyApp());
Expand Down
Loading

0 comments on commit 4c63375

Please sign in to comment.