NEW: MIH Home & Mzansi Profile Provider Setup pt 1
This commit is contained in:
parent
553d22dd6b
commit
d51603ff5d
28 changed files with 2687 additions and 2515 deletions
|
|
@ -1,31 +1,39 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/user_consent.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
|
||||
class MihUserConsentServices {
|
||||
Future<UserConsent?> getUserConsentStatus() async {
|
||||
Future<void> getUserConsentStatus(
|
||||
BuildContext context,
|
||||
) async {
|
||||
var app_id = await SuperTokens.getUserId();
|
||||
final response = await http.get(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/user-consent/user/$app_id"));
|
||||
if (response.statusCode == 200) {
|
||||
Map<String, dynamic> userMap = jsonDecode(response.body);
|
||||
UserConsent userConsent = UserConsent.fromJson(userMap);
|
||||
return userConsent;
|
||||
} else {
|
||||
return null;
|
||||
context.read<MzansiProfileProvider>().setUserConsent(userConsent);
|
||||
// return userConsent;
|
||||
}
|
||||
// else {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
||||
Future<int> insertUserConsentStatus(
|
||||
String app_id,
|
||||
String latestPrivacyPolicyDate,
|
||||
String latestTermOfServiceDate,
|
||||
MzansiProfileProvider provider,
|
||||
BuildContext context,
|
||||
) async {
|
||||
UserConsent userConsent = UserConsent(
|
||||
app_id: app_id,
|
||||
app_id: provider.user!.app_id,
|
||||
privacy_policy_accepted: DateTime.parse(latestPrivacyPolicyDate),
|
||||
terms_of_services_accepted: DateTime.parse(latestTermOfServiceDate),
|
||||
);
|
||||
|
|
@ -34,16 +42,18 @@ class MihUserConsentServices {
|
|||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode(userConsent.toJson()),
|
||||
);
|
||||
provider.setUserConsent(userConsent);
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
Future<int> updateUserConsentStatus(
|
||||
String app_id,
|
||||
String latestPrivacyPolicyDate,
|
||||
String latestTermOfServiceDate,
|
||||
MzansiProfileProvider provider,
|
||||
BuildContext context,
|
||||
) async {
|
||||
UserConsent userConsent = UserConsent(
|
||||
app_id: app_id,
|
||||
app_id: provider.user!.app_id,
|
||||
privacy_policy_accepted: DateTime.parse(latestPrivacyPolicyDate),
|
||||
terms_of_services_accepted: DateTime.parse(latestTermOfServiceDate),
|
||||
);
|
||||
|
|
@ -52,6 +62,7 @@ class MihUserConsentServices {
|
|||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode(userConsent.toJson()),
|
||||
);
|
||||
provider.setUserConsent(userConsent);
|
||||
return response.statusCode;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue