fix user counter and optimise profile picture getting

This commit is contained in:
Yasien Mac Mini 2026-07-02 11:01:59 +02:00
parent 62eafaf766
commit 1438dd6b5a
8 changed files with 39 additions and 85 deletions

View file

@ -39,7 +39,6 @@ void main() async {
await Hive.openBox<Business>('business_box');
await Hive.openBox<BusinessUser>('business_user_box');
await Hive.openBox<UserConsent>('user_consent_box');
await Hive.openBox<String>('image_urls_box');
await Hive.openBox<ProfileLink>('personal_profile_links_box');
await Hive.openBox<ProfileLink>('business_profile_links_box');
await Hive.openBox<BusinessEmployee>('business_employees_box');

View file

@ -39,7 +39,6 @@ void main() async {
await Hive.openBox<Business>('business_box');
await Hive.openBox<BusinessUser>('business_user_box');
await Hive.openBox<UserConsent>('user_consent_box');
await Hive.openBox<String>('image_urls_box');
await Hive.openBox<ProfileLink>('personal_profile_links_box');
await Hive.openBox<ProfileLink>('business_profile_links_box');
await Hive.openBox<BusinessEmployee>('business_employees_box');

View file

@ -7,7 +7,7 @@ class AboutMihHiveData {
final Box<int> _mihUserBusinessCountBox = Hive.box<int>('about_mih_box');
static const String kUserCountKey = 'current_user_count';
static const String kBusinessCountKey = 'current_user_count';
static const String kBusinessCountKey = 'current_business_count';
// Get Data from local storage
int? getcachedUserCount() => _mihUserBusinessCountBox.get(kUserCountKey);
@ -21,7 +21,7 @@ class AboutMihHiveData {
}
Future<void> cacheBusinessCount(int remoteBusinessCount) async {
await _mihUserBusinessCountBox.put(kUserCountKey, remoteBusinessCount);
await _mihUserBusinessCountBox.put(kBusinessCountKey, remoteBusinessCount);
KenLogger.success("MIH Business Count Cached");
}

View file

@ -8,7 +8,6 @@ import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_business_employee_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_my_business_user_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_profile_links_service.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_user_consent_services.dart';
@ -27,7 +26,6 @@ class MzansiProfileHiveData {
Hive.box<ProfileLink>('business_profile_links_box');
final Box<BusinessEmployee> _businessEmployeesBox =
Hive.box<BusinessEmployee>('business_Employees_box');
final Box<String> _resolvedUrlsBox = Hive.box<String>('image_urls_box');
static const String kUserKey = 'current_user';
static const String kBusinessKey = 'current_business';
@ -43,9 +41,6 @@ class MzansiProfileHiveData {
BusinessUser? getCachedBusinessUser() =>
_businessUserBox.get(kBusinessUserKey);
UserConsent? getCachedConsent() => _userConsentBox.get(kConsentKey);
String? getCachedUserPicUrl() => _resolvedUrlsBox.get(kUserPicUrlKey);
String? getCachedBusinessPicUrl() => _resolvedUrlsBox.get(kBusinessPicUrlKey);
String? getCachedSignatureUrl() => _resolvedUrlsBox.get(kSignatureUrlKey);
List<ProfileLink> getCachedPersonalProfileLinks() {
final links = _personalProfileLinksBox.values.toList();
@ -68,11 +63,6 @@ class MzansiProfileHiveData {
// Caching Data to local storage
Future<void> cacheUserData(AppUser remoteUser) async {
await _userBox.put(kUserKey, remoteUser);
if (remoteUser.pro_pic_path.isNotEmpty) {
String userPicUrl =
await MihFileApi.getMinioFileUrl(remoteUser.pro_pic_path);
await _resolvedUrlsBox.put(kUserPicUrlKey, userPicUrl);
}
KenLogger.success("User Profile Cached");
}
@ -83,26 +73,11 @@ class MzansiProfileHiveData {
Future<void> cacheBusinessData(Business remoteBusiness) async {
await _businessBox.put(kBusinessKey, remoteBusiness);
if (remoteBusiness.logo_path.isNotEmpty) {
String logoUrl =
await MihFileApi.getMinioFileUrl(remoteBusiness.logo_path);
await _resolvedUrlsBox.put(kBusinessPicUrlKey, logoUrl);
}
BusinessUser? remoteBizUser =
await MihMyBusinessUserServices().getBusinessUserV2();
if (remoteBizUser != null) {
cacheBusinessUserData(remoteBizUser);
}
KenLogger.success("Busines Profile Cached");
}
Future<void> cacheBusinessUserData(BusinessUser remoteBizUser) async {
await _businessUserBox.put(kBusinessUserKey, remoteBizUser);
if (remoteBizUser.sig_path.isNotEmpty) {
String signatureUrl =
await MihFileApi.getMinioFileUrl(remoteBizUser.sig_path);
await _resolvedUrlsBox.put(kSignatureUrlKey, signatureUrl);
}
KenLogger.success("Busines User Profile Cached");
}
@ -146,8 +121,13 @@ class MzansiProfileHiveData {
Business? remoteBusiness =
await MihBusinessDetailsServices().getBusinessDetailsByUserV2();
if (remoteBusiness != null) {
cacheBusinessData(remoteBusiness);
await cacheBusinessData(remoteBusiness);
BusinessUser? remoteBizUser =
await MihMyBusinessUserServices().getBusinessUserV2();
if (remoteBizUser != null) {
cacheBusinessUserData(remoteBizUser);
}
final remoteBusinessEmployeeList = await MihBusinessEmployeeServices()
.fetchEmployeesV2(remoteBusiness.business_id);
cacheBusinessEmployeesData(remoteBusinessEmployeeList);

View file

@ -8,6 +8,7 @@ import 'package:mzansi_innovation_hub/mih_objects/business_employee.dart';
import 'package:mzansi_innovation_hub/mih_objects/business_user.dart';
import 'package:mzansi_innovation_hub/mih_objects/profile_link.dart';
import 'package:mzansi_innovation_hub/mih_objects/user_consent.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
class MzansiProfileProvider extends ChangeNotifier {
final MzansiProfileHiveData _hiveData;
@ -46,20 +47,21 @@ class MzansiProfileProvider extends ChangeNotifier {
userConsent = _hiveData.getCachedConsent();
business = _hiveData.getCachedBusiness();
businessUser = _hiveData.getCachedBusinessUser();
String? cachedUserUrl = _hiveData.getCachedUserPicUrl();
if (cachedUserUrl != null && cachedUserUrl.isNotEmpty) {
userProfilePicUrl = cachedUserUrl;
userProfilePicture = CachedNetworkImageProvider(cachedUserUrl);
if (user != null && user!.pro_pic_path.isNotEmpty) {
KenLogger.success("proPicPath: ${user!.pro_pic_path}| THis is it");
userProfilePicUrl = MihFileApi.getMinioFileUrlV2(user!.pro_pic_path);
userProfilePicture = CachedNetworkImageProvider(userProfilePicUrl!);
}
String? cachedBizUrl = _hiveData.getCachedBusinessPicUrl();
if (cachedBizUrl != null && cachedBizUrl.isNotEmpty) {
businessProfilePicUrl = cachedBizUrl;
businessProfilePicture = CachedNetworkImageProvider(cachedBizUrl);
if (business != null && business!.logo_path.isNotEmpty) {
businessProfilePicUrl = MihFileApi.getMinioFileUrlV2(business!.logo_path);
businessProfilePicture =
CachedNetworkImageProvider(businessProfilePicUrl!);
}
String? cachedSigUrl = _hiveData.getCachedSignatureUrl();
if (cachedSigUrl != null && cachedSigUrl.isNotEmpty) {
businessUserSignatureUrl = cachedSigUrl;
businessUserSignature = CachedNetworkImageProvider(cachedSigUrl);
if (businessUser != null && businessUser!.sig_path.isNotEmpty) {
businessUserSignatureUrl =
MihFileApi.getMinioFileUrlV2(businessUser!.sig_path);
businessUserSignature =
CachedNetworkImageProvider(businessUserSignatureUrl!);
}
employeeList = _hiveData.getCachedBusinessEmployees();

View file

@ -39,29 +39,11 @@ class MihFileApi {
return fileUrl;
}
static Future<String> getMinioFileUrlV2(
static String getMinioFileUrlV2(
String filePath,
) async {
String fileUrl = "";
try {
var url =
"${AppEnviroment.baseApiUrl}/minio/pull/file/${AppEnviroment.getEnv()}/$filePath";
var response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
var decodedData = jsonDecode(response.body);
fileUrl = decodedData['minioURL'];
} else {}
} catch (e) {
KenLogger.error("Error getting url");
} finally {}
if (AppEnviroment.getEnv() == "Dev" && kIsWeb) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
} else if (AppEnviroment.getEnv() == "Dev" && Platform.isIOS) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
} else if (AppEnviroment.getEnv() == "Dev" && Platform.isLinux) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
}
return fileUrl;
) {
if (filePath.isEmpty) return "";
return "${AppEnviroment.baseApiUrl}/v2/minio/pull/file/$filePath";
}
static Future<int> uploadFile(