fix user counter and optimise profile picture getting
This commit is contained in:
parent
62eafaf766
commit
1438dd6b5a
8 changed files with 39 additions and 85 deletions
|
|
@ -8,15 +8,7 @@ minioSecret = os.getenv("MINIO_SECRET_KEY")
|
|||
minioEndpoint = os.getenv("MINIO_ENDPOINT", "mih-minio:9000")
|
||||
minioSecure = os.getenv("MINIO_SECURE", "False") in ("True")
|
||||
|
||||
def minioConnect(env):
|
||||
if(env == "Dev"):
|
||||
return Minio(
|
||||
endpoint=minioEndpoint,
|
||||
access_key=minioAccess,
|
||||
secret_key=minioSecret,
|
||||
secure=minioSecure,
|
||||
)
|
||||
else:
|
||||
def minioConnect():
|
||||
return Minio(
|
||||
endpoint=minioEndpoint,
|
||||
access_key=minioAccess,
|
||||
|
|
|
|||
|
|
@ -108,11 +108,11 @@ class claimStatementUploud(BaseModel):
|
|||
logo_path: str
|
||||
sig_path: str
|
||||
|
||||
@router.get("/v2/minio/pull/file/{env}/{app_id}/{folder}/{file_name}", tags=["Minio"])
|
||||
async def pullFileFromMinioV2(app_id: str, folder: str, file_name: str, env: str):
|
||||
@router.get("/v2/minio/pull/file/{app_id}/{folder}/{file_name}", tags=["Minio"])
|
||||
async def pullFileFromMinioV2(app_id: str, folder: str, file_name: str,):
|
||||
object_path = f"{app_id}/{folder}/{file_name}"
|
||||
try:
|
||||
client = Minio_Storage.minioConnection.minioConnect(env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
|
||||
response = client.get_object(bucket_name="mih", object_name=object_path)
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ async def pull_File_from_user(app_id: str, folder: str, file_name: str, env: str
|
|||
# print(f"env: {env}")
|
||||
# uploudFile(app_id, file.filename, extension[1], content)
|
||||
|
||||
client = Minio_Storage.minioConnection.minioConnect(env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
# buckets = client.list_buckets()
|
||||
# print("Connected to MinIO successfully!")
|
||||
# print("Available buckets:", [bucket.name for bucket in buckets])
|
||||
|
|
@ -188,7 +188,7 @@ async def delete_File_of_user(requestItem: minioDeleteRequest, session: SessionC
|
|||
path = requestItem.file_path
|
||||
try:
|
||||
# uploudFile(app_id, file.filename, extension[1], content)
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
|
||||
minioError = client.remove_object(
|
||||
bucket_name="mih",
|
||||
|
|
@ -222,7 +222,7 @@ async def upload_perscription_to_user(requestItem: claimStatementUploud, session
|
|||
return {"message": "Successfully Generated File"}
|
||||
|
||||
def uploudFile(app_id, env, folder, fileName, extension, content):
|
||||
client = Minio_Storage.minioConnection.minioConnect(env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
if not found:
|
||||
client.make_bucket(bucket_name="mih")
|
||||
|
|
@ -238,7 +238,7 @@ def uploudFile(app_id, env, folder, fileName, extension, content):
|
|||
content_type=f"application/{extension}")
|
||||
|
||||
def uploudMedCert(requestItem: medCertUploud):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
generateMedCertPDF(requestItem)
|
||||
today = datetime.today().strftime('%Y-%m-%d')
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
|
|
@ -250,7 +250,7 @@ def uploudMedCert(requestItem: medCertUploud):
|
|||
client.fput_object("mih", fileName, "temp-med-cert.pdf")
|
||||
|
||||
def generateMedCertPDF(requestItem: medCertUploud):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
new_logo_path = requestItem.logo_path.replace(" ","-")
|
||||
new_sig_path = requestItem.sig_path.replace(" ","-")
|
||||
minioLogo = client.get_object("mih", new_logo_path).read()
|
||||
|
|
@ -315,7 +315,7 @@ def generateMedCertPDF(requestItem: medCertUploud):
|
|||
myCanvas.save()
|
||||
|
||||
def uploudPerscription(requestItem: perscriptionList):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
generatePerscriptionPDF(requestItem)
|
||||
today = datetime.today().strftime('%Y-%m-%d')
|
||||
found = client.bucket_exists(bucket_name="mih")
|
||||
|
|
@ -327,7 +327,7 @@ def uploudPerscription(requestItem: perscriptionList):
|
|||
client.fput_object("mih", fileName, "temp-perscription.pdf")
|
||||
|
||||
def generatePerscriptionPDF(requestItem: perscriptionList):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
new_logo_path = requestItem.logo_path.replace(" ","-")
|
||||
new_sig_path = requestItem.sig_path.replace(" ","-")
|
||||
minioLogo = client.get_object("mih", new_logo_path).read()
|
||||
|
|
@ -417,7 +417,7 @@ def generatePerscriptionPDF(requestItem: perscriptionList):
|
|||
|
||||
def uploudClaimStatement(requestItem: claimStatementUploud):
|
||||
try:
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
print("connected")
|
||||
except Exception:
|
||||
print("error")
|
||||
|
|
@ -433,7 +433,7 @@ def uploudClaimStatement(requestItem: claimStatementUploud):
|
|||
client.fput_object("mih", fileName, "temp-claim-statement.pdf")
|
||||
|
||||
def generateClaimStatementPDF(requestItem: claimStatementUploud):
|
||||
client = Minio_Storage.minioConnection.minioConnect(requestItem.env)
|
||||
client = Minio_Storage.minioConnection.minioConnect()
|
||||
# print("buckets: " + client.list_buckets)
|
||||
new_logo_path = requestItem.logo_path.replace(" ","-")
|
||||
new_sig_path = requestItem.sig_path.replace(" ","-")
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue