diff --git a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/auth/data/repositories/auth_repository_impl.dart b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/auth/data/repositories/auth_repository_impl.dart index 59bf19979..16f9a5be7 100644 --- a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/auth/data/repositories/auth_repository_impl.dart +++ b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/auth/data/repositories/auth_repository_impl.dart @@ -34,7 +34,6 @@ class AuthRepositoryImp implements AuthRepository { if (isConnected) { try { final userModel = await authRemoteDataSource.getUser(); - final toke = authLocalDataSource.getToken(); final userEntity = UserEntity.fromModel(userModel); sl().updateUser(userEntity); diff --git a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/data_source/remote_data_source/remote_data_source.dart b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/data_source/remote_data_source/remote_data_source.dart index 8d0708bc0..48c923868 100644 --- a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/data_source/remote_data_source/remote_data_source.dart +++ b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/data_source/remote_data_source/remote_data_source.dart @@ -26,5 +26,4 @@ abstract class RemoteDataSource { Future> getChatMessages(String chatId); Stream getMessages(); - Future updateAccessToken(String token); } diff --git a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/data_source/remote_data_source/remote_data_source_impl.dart b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/data_source/remote_data_source/remote_data_source_impl.dart index 028c92b0c..9c4802680 100644 --- a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/data_source/remote_data_source/remote_data_source_impl.dart +++ b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/data_source/remote_data_source/remote_data_source_impl.dart @@ -8,29 +8,30 @@ import 'package:socket_io_client/socket_io_client.dart' as IO; import '../../../../../core/constants/constants.dart'; import '../../../../../core/error/exception.dart'; +import '../../../../product/data/data_sources/local_data_source.dart'; import '../../model/chat_model.dart'; import '../../model/message_model.dart'; import 'remote_data_source.dart'; class RemoteDataSourceImpl extends RemoteDataSource { final http.Client client; - String accessToken; + final String accessToken; + final ProductLocalDataSource productLocalDataSource; late IO.Socket socket; final StreamController _messageStreamController = StreamController.broadcast(); - RemoteDataSourceImpl({required this.client, required this.accessToken}) { + RemoteDataSourceImpl( + {required this.client, + required this.accessToken, + required this.productLocalDataSource}) { _initializeWebSocket(); } - @override - Future updateAccessToken(String token) async { - accessToken = token; - } - @override Future> getAllChats() async { + final accessToken = productLocalDataSource.getToken(); try { final response = await client.get( Uri.parse(Urls.baseChat), @@ -39,7 +40,7 @@ class RemoteDataSourceImpl extends RemoteDataSource { 'Content-Type': 'application/json', }, ); - print(response.statusCode); + print(response.statusCode); if (response.statusCode == 200) { final result = json.decode(response.body)['data']; final List answer = []; @@ -61,6 +62,7 @@ class RemoteDataSourceImpl extends RemoteDataSource { @override Future getChatById(String chatId) async { try { + final accessToken = productLocalDataSource.getToken(); final response = await http.get( Uri.parse(Urls.getChatById(chatId)), headers: { @@ -82,6 +84,7 @@ class RemoteDataSourceImpl extends RemoteDataSource { @override Future initiateChat(String recieverId) async { try { + final accessToken = productLocalDataSource.getToken(); final response = await client.post(Uri.parse(Urls.baseChat), headers: { 'Authorization': 'Bearer $accessToken', @@ -101,6 +104,7 @@ class RemoteDataSourceImpl extends RemoteDataSource { Future> getChatMessages(String chatId) async { try { + final accessToken = productLocalDataSource.getToken(); final response = await client.get( Uri.parse(Urls.getChatMessages(chatId)), headers: { @@ -144,6 +148,7 @@ class RemoteDataSourceImpl extends RemoteDataSource { } void _initializeWebSocket() { + final accessToken = productLocalDataSource.getToken(); socket = IO.io( 'https://g5-flutter-learning-path-be.onrender.com', { diff --git a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/repository/chat_repository_impl.dart b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/repository/chat_repository_impl.dart index 240fc983b..dfcc355bc 100644 --- a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/repository/chat_repository_impl.dart +++ b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/chat/data/repository/chat_repository_impl.dart @@ -94,8 +94,4 @@ class ChatRepositoryImpl implements ChatRepository { return Left(ServerFailure(error.toString())); } } - - void updateAccessToken(String newToken) { - _remoteDataSource.updateAccessToken(newToken); - } } diff --git a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/product/data/data_sources/remote_data_source.dart b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/product/data/data_sources/remote_data_source.dart index fd41d4500..d0b60fad7 100644 --- a/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/product/data/data_sources/remote_data_source.dart +++ b/mobile/ASTU-mobile-group-1/Ecommerce/lib/features/product/data/data_sources/remote_data_source.dart @@ -54,7 +54,7 @@ class ProductRemoteDataSourceImpl extends ProductRemoteDataSource { await productLocalDataSource.cacheProducts(products); print(products); - return products; + return products.reversed.toList(); } else { throw ServerException(); } diff --git a/mobile/ASTU-mobile-group-1/Ecommerce/lib/injection_container.dart b/mobile/ASTU-mobile-group-1/Ecommerce/lib/injection_container.dart index 39c694528..cb2e368e9 100644 --- a/mobile/ASTU-mobile-group-1/Ecommerce/lib/injection_container.dart +++ b/mobile/ASTU-mobile-group-1/Ecommerce/lib/injection_container.dart @@ -66,6 +66,7 @@ Future init() async { sl.registerLazySingleton(() => RemoteDataSourceImpl( client: sl(), + productLocalDataSource: sl(), accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImVlQGdtYWlsLmNvbSIsInN1YiI6IjY2Y2M0NTNlZGFiNDNjMWEyZTk4MDMwYSIsImlhdCI6MTcyNDY2MzE4MywiZXhwIjoxNzI1MDk1MTgzfQ.fsrJ3pS6R_N4jzAnOZBBX6RzD7PcZoxOxnPzzYWskY0'));