[Synchronize Contact] Store contact and fetches contact #890
Open
Description
Desc
- If contact does not exist on the server, store it in local database (Hive)
- Create
ContactsCollectionBox
String get _contactsBoxName => 'contacts_box';
late CollectionBox<Map> contactsCollectionBox;
- Create
ContactHiveDatasource
abstract class ContactHiveDatasource {
Future<void> storeContactHive(
String clientName,
Contact contact,
);
}
- Create
ContactHiveRepository
abstract class ContactHiveRepository {
Future<void> storeContactHive(
String clientName,
Contact contact,
);
}
- Create
ContactHiveRepositoryImpl
andContactHiveDatasourceImpl
- Create
storeContactHive
method to save contact in hive
Future<void> storeContactHive(String clientName, Contact contact) async {
final hiveCollectionToMDatabase =
await getIt.getAsync<HiveCollectionToMDatabase>();
return hiveCollectionToMDatabase.contactsCollectionBox.put(
clientName,
contact toJson(),
);
}
- Get contact from local database
- Create
getContactHive
method inContactHiveDatasource
andContactHiveRepository
abstract class ContactHiveDatasource {
Future<List<Contact>> getContactHive(String clientName);
}
abstract class ContactHiveRepository {
Future<List<Contact>> getContactHive(String clientName);
}
- Create
getContactHive
method to get all contact from hive
Future<Contact> getContactHive(String clientName) async {
final hiveCollectionToMDatabase =
await getIt.getAsync<HiveCollectionToMDatabase>();
return hiveCollectionToMDatabase.contactsCollectionBox.getAll(clientName);
}
DoD
- Store contact to database
- Get contact to database