Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astu.mobile.g1.biruk.change on autn repo impl #2293

Open
wants to merge 2 commits into
base: astu.mobile.g1.eyobe.rebase
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserCubit>().updateUser(userEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ abstract class RemoteDataSource {
Future<List<MessageModel>> getChatMessages(String chatId);

Stream<MessageModel> getMessages();
Future<void> updateAccessToken(String token);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MessageModel> _messageStreamController =
StreamController<MessageModel>.broadcast();

RemoteDataSourceImpl({required this.client, required this.accessToken}) {
RemoteDataSourceImpl(
{required this.client,
required this.accessToken,
required this.productLocalDataSource}) {
_initializeWebSocket();
}

@override
Future<void> updateAccessToken(String token) async {
accessToken = token;
}

@override
Future<List<ChatModel>> getAllChats() async {
final accessToken = productLocalDataSource.getToken();
try {
final response = await client.get(
Uri.parse(Urls.baseChat),
Expand All @@ -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<ChatModel> answer = [];
Expand All @@ -61,6 +62,7 @@ class RemoteDataSourceImpl extends RemoteDataSource {
@override
Future<ChatModel> getChatById(String chatId) async {
try {
final accessToken = productLocalDataSource.getToken();
final response = await http.get(
Uri.parse(Urls.getChatById(chatId)),
headers: {
Expand All @@ -82,6 +84,7 @@ class RemoteDataSourceImpl extends RemoteDataSource {
@override
Future<ChatModel> initiateChat(String recieverId) async {
try {
final accessToken = productLocalDataSource.getToken();
final response = await client.post(Uri.parse(Urls.baseChat),
headers: {
'Authorization': 'Bearer $accessToken',
Expand All @@ -101,6 +104,7 @@ class RemoteDataSourceImpl extends RemoteDataSource {

Future<List<MessageModel>> getChatMessages(String chatId) async {
try {
final accessToken = productLocalDataSource.getToken();
final response = await client.get(
Uri.parse(Urls.getChatMessages(chatId)),
headers: {
Expand Down Expand Up @@ -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',
<String, dynamic>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,4 @@ class ChatRepositoryImpl implements ChatRepository {
return Left(ServerFailure(error.toString()));
}
}

void updateAccessToken(String newToken) {
_remoteDataSource.updateAccessToken(newToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ProductRemoteDataSourceImpl extends ProductRemoteDataSource {

await productLocalDataSource.cacheProducts(products);
print(products);
return products;
return products.reversed.toList();
} else {
throw ServerException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Future<void> init() async {

sl.registerLazySingleton<RemoteDataSource>(() => RemoteDataSourceImpl(
client: sl(),
productLocalDataSource: sl(),
accessToken:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImVlQGdtYWlsLmNvbSIsInN1YiI6IjY2Y2M0NTNlZGFiNDNjMWEyZTk4MDMwYSIsImlhdCI6MTcyNDY2MzE4MywiZXhwIjoxNzI1MDk1MTgzfQ.fsrJ3pS6R_N4jzAnOZBBX6RzD7PcZoxOxnPzzYWskY0'));

Expand Down