Untitled
unknown
dart
a year ago
11 kB
2
Indexable
Never
import 'dart:io'; import 'package:dartz/dartz.dart'; import 'package:numa/data_layer/data/remote_data_source.dart'; import 'package:numa/data_layer/models/album_models/search_param.dart'; import 'package:numa/data_layer/models/comments_model.dart'; import 'package:numa/data_layer/models/my_profile_model/my_like_response.dart'; import 'package:numa/data_layer/models/set_data/set_comment_body.dart'; import 'package:numa/data_layer/models/wishlist_param.dart'; import 'package:numa/data_layer/repositories/exceptions.dart'; import 'package:numa/domain/entities/banner_guest_entity.dart'; import 'package:numa/domain/entities/blogs_entity.dart'; import 'package:numa/domain/entities/catalog_series_entity.dart'; import 'package:numa/domain/entities/collectors_entity.dart'; import 'package:numa/domain/entities/countries_entity.dart'; import 'package:numa/domain/entities/delete_wishlist_entity.dart'; import 'package:numa/domain/entities/guest_home_grid_model.dart'; import 'package:numa/domain/entities/my_collection_entity.dart'; import 'package:numa/domain/entities/notification_entity.dart'; import 'package:numa/domain/entities/recommended_entity.dart'; import 'package:numa/domain/entities/series_data_entity.dart'; import 'package:numa/domain/entities/series_entity.dart'; import 'package:numa/data_layer/repositories/failure.dart'; import 'package:numa/domain/entities/sku_entity.dart'; import 'package:numa/domain/entities/wish_entity.dart'; import 'package:numa/domain/i_repositories/i_numa_repository.dart'; import '../../domain/entities/search_entity.dart'; import '../models/set_data/create_comment_body.dart'; import '../models/comments_model.dart' as singleComment; class NumaRepositoryImpl implements INumaRepository { NumaRepositoryImpl({required this.remoteDataSource}); final RemoteDataSource remoteDataSource; @override Future<Either<Failure, SeriesEntity>> excecutGetSeries() async { try { final result = await remoteDataSource.mySeries(); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, SeriesDataEntity>> excecutGetSeriesData(int id) async { try { final result = await remoteDataSource.mySeriesData(id); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, NotificationEntity>> excecutGetNotifications() async { try { final result = await remoteDataSource.myNotifications(); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, MyCollectionEntity>> excecutMyCollection() async { try { final result = await remoteDataSource.myCollection(); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, CollectorsEntity>> excecutMyCollectors( int? pageIndex, int? itemCount) async { try { final result = await remoteDataSource.myCollectors(pageIndex, itemCount); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, RecommendedEntity>> excecutRecommended( int? pageIndex, int? itemCount) async { try { final result = await remoteDataSource.recommended(pageIndex, itemCount); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, BlogsEntity>> excecutBlogs( int? pageIndex, int? itemCount) async { try { final result = await remoteDataSource.blogsArticles(pageIndex, itemCount); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, CountriesEntity>> excecutCountries() async { try { final result = await remoteDataSource.getCountries(); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, CatalogSeriesEntity>> excecutCatalogSeries( String? countryCode) async { try { final result = await remoteDataSource.getCountriesSeries(countryCode); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, SKUEntity>> excecutSKU( int? id, String? countryCode) async { try { final result = await remoteDataSource.getSKU(id, countryCode); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, GuestGridCountEntity>> executeGuestGridCount() async { try { final result = await remoteDataSource.getGuestHomeGrid(); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? '', ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, BannerGuestEntity>> executeGuestBanner() async { try { final result = await remoteDataSource.getBannerGuest(); return Right(result.toEntity()); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? '', ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, WishEntity>> excecutAddToWishlist( AddWishlistParam param) async { try { final result = await remoteDataSource.addWishlist(param); return Right(result.toEntity()); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? '', ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, DeleteWishlistEntity>> excecutDeleteFromWishlist( int id) async { try { final result = await remoteDataSource.deleteWishlist(id); return Right(result.toEntity()); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? '', ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, SearchEntity>> excecutSearch(SearchParam param) async { try { final result = await remoteDataSource.search(param); return Right( result.toEntity(), ); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, MyLikesResponse>> executeLikesUnLike( String itemId, String action) async { try { final response = await remoteDataSource.executeLikesUnLike(itemId, action); return Right(response); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, CommentsResponse>> executeGetComments( SetCommentBody setCommentBody) async { try { final response = await remoteDataSource.executeGetComments(setCommentBody); return Right(response); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } @override Future<Either<Failure, singleComment.Data>> executecreateComments( CreateCommentBody createCommentBody) async { try { final response = await remoteDataSource.executecreateComments(createCommentBody); return Right(response); } on ServerException catch (e) { return Left( ServerFailure( e.message ?? "", ), ); } on SocketException { return const Left( ConnectionFailure( 'Failed to connect to the network', ), ); } } }