-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
constructor and client functionality added
- Loading branch information
1 parent
13b5924
commit 637f691
Showing
21 changed files
with
4,061 additions
and
1 deletion.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
lib/src/client_proposal_management/data/chat_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// First, create a ChatController | ||
import 'dart:io'; | ||
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:home_front_pk/src/client_proposal_management/data/client_proposal_controller.dart'; | ||
import 'package:home_front_pk/src/client_proposal_management/data/client_proposal_repo.dart'; | ||
import 'package:home_front_pk/src/features/user_job_post/data/image_upload_repo.dart'; | ||
|
||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
class ChatController extends StateNotifier<AsyncValue<void>> { | ||
final ClientProposalRepository _repository; | ||
final StorageRepository _storageRepository; | ||
|
||
ChatController({ | ||
required ClientProposalRepository repository, | ||
required StorageRepository storageRepository, | ||
}) : _repository = repository, | ||
_storageRepository = storageRepository, | ||
super(const AsyncValue.data(null)); | ||
|
||
Future<String> uploadChatImage(String chatId, File file) async { | ||
try { | ||
state = const AsyncValue.loading(); | ||
final url = await _storageRepository.uploadChatImage(chatId, file); | ||
state = const AsyncValue.data(null); | ||
return url; | ||
} catch (e, st) { | ||
state = AsyncValue.error(e, st); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<void> sendMessage(String chatId, String content, String type) async { | ||
try { | ||
state = const AsyncValue.loading(); | ||
await _repository.sendMessage(chatId, content, type); | ||
state = const AsyncValue.data(null); | ||
} catch (e, st) { | ||
state = AsyncValue.error(e, st); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<String> createChatRoom(String jobId, String constructorId) async { | ||
try { | ||
state = const AsyncValue.loading(); | ||
final chatId = await _repository.createChatRoom(jobId, constructorId); | ||
state = const AsyncValue.data(null); | ||
return chatId; | ||
} catch (e, st) { | ||
state = AsyncValue.error(e, st); | ||
rethrow; | ||
} | ||
} | ||
} | ||
|
||
// Add providers | ||
final chatControllerProvider = | ||
StateNotifierProvider<ChatController, AsyncValue<void>>((ref) { | ||
final repository = ref.watch(clientProposalRepositoryProvider); | ||
final storageRepository = ref.watch(storageRepositoryProvider); | ||
return ChatController( | ||
repository: repository, | ||
storageRepository: storageRepository, | ||
); | ||
}); |
70 changes: 70 additions & 0 deletions
70
lib/src/client_proposal_management/data/client_proposal_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Providers | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:home_front_pk/src/client_proposal_management/data/client_proposal_repo.dart'; | ||
import 'package:home_front_pk/src/client_proposal_management/domain/client_proposal_model.dart'; | ||
import 'package:home_front_pk/src/features/user_job_post/data/image_upload_repo.dart'; | ||
|
||
final clientProposalRepositoryProviderWithStorage = | ||
Provider<ClientProposalRepository>((ref) { | ||
return ClientProposalRepository(); | ||
}); | ||
|
||
// Stream provider for job proposals | ||
final jobProposalsProvider = | ||
StreamProvider.family<List<ClientProposal>, String>((ref, jobId) { | ||
final repository = ref.watch(clientProposalRepositoryProviderWithStorage); | ||
return repository.getJobProposals(jobId); | ||
}); | ||
|
||
// Stream provider for all proposals across all jobs | ||
final allJobProposalsProvider = | ||
StreamProvider<Map<String, List<ClientProposal>>>((ref) { | ||
final repository = ref.watch(clientProposalRepositoryProvider); | ||
return repository.getAllJobProposals(); | ||
}); | ||
|
||
// Controller | ||
class ClientProposalController extends StateNotifier<AsyncValue<void>> { | ||
final ClientProposalRepository _repository; | ||
|
||
ClientProposalController(this._repository) | ||
: super(const AsyncValue.data(null)); | ||
|
||
Future<void> acceptProposal(String jobId, String proposalId) async { | ||
state = const AsyncValue.loading(); | ||
try { | ||
await _repository.acceptProposal(jobId, proposalId); | ||
state = const AsyncValue.data(null); | ||
} catch (e, st) { | ||
state = AsyncValue.error(e, st); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<void> rejectProposal(String proposalId, {String? reason}) async { | ||
state = const AsyncValue.loading(); | ||
try { | ||
await _repository.rejectProposal(proposalId, reason: reason); | ||
state = const AsyncValue.data(null); | ||
} catch (e, st) { | ||
state = AsyncValue.error(e, st); | ||
rethrow; | ||
} | ||
} | ||
} | ||
|
||
final storageRepositoryProvider = Provider<StorageRepository>((ref) { | ||
return StorageRepository(); | ||
}); | ||
|
||
final clientProposalRepositoryProvider = | ||
Provider<ClientProposalRepository>((ref) { | ||
final storageRepo = ref.watch(storageRepositoryProvider); | ||
return ClientProposalRepository(); | ||
}); | ||
|
||
final clientProposalControllerProvider = | ||
StateNotifierProvider<ClientProposalController, AsyncValue<void>>((ref) { | ||
final repository = ref.watch(clientProposalRepositoryProvider); | ||
return ClientProposalController(repository); | ||
}); |
Oops, something went wrong.