This commit is contained in:
2025-10-28 00:09:46 +07:00
parent 9ebe7c2919
commit de49f564b1
110 changed files with 15392 additions and 3996 deletions

View File

@@ -0,0 +1,39 @@
import 'package:dartz/dartz.dart';
import '../../../../core/errors/exceptions.dart';
import '../../../../core/errors/failures.dart';
import '../../domain/entities/warehouse_entity.dart';
import '../../domain/repositories/warehouse_repository.dart';
import '../datasources/warehouse_remote_datasource.dart';
/// Implementation of WarehouseRepository
/// Coordinates between data sources and domain layer
/// Converts exceptions to failures for proper error handling
class WarehouseRepositoryImpl implements WarehouseRepository {
final WarehouseRemoteDataSource remoteDataSource;
WarehouseRepositoryImpl(this.remoteDataSource);
@override
Future<Either<Failure, List<WarehouseEntity>>> getWarehouses() async {
try {
// Fetch warehouses from remote data source
final warehouses = await remoteDataSource.getWarehouses();
// Convert models to entities
final entities = warehouses
.map((model) => model.toEntity())
.toList();
return Right(entities);
} on ServerException catch (e) {
// Convert server exceptions to server failures
return Left(ServerFailure(e.message));
} on NetworkException catch (e) {
// Convert network exceptions to network failures
return Left(NetworkFailure(e.message));
} catch (e) {
// Handle any unexpected errors
return Left(ServerFailure('Unexpected error: ${e.toString()}'));
}
}
}