add favourites tool
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/arguments.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/loyalty_card.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// import '../mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
@@ -40,7 +41,6 @@ class MIHMzansiWalletApis {
|
||||
// print("Code: ${response.statusCode}");
|
||||
// errorCode = response.statusCode.toString();
|
||||
// errorBody = response.body;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
//print("Here1");
|
||||
Iterable l = jsonDecode(response.body);
|
||||
@@ -55,6 +55,36 @@ class MIHMzansiWalletApis {
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is used to fetch a list of loyalty cards for a user.
|
||||
///
|
||||
/// Patameters: app_id .
|
||||
///
|
||||
/// Returns List<PatientQueue>.
|
||||
static Future<List<MIHLoyaltyCard>> getFavouriteLoyaltyCards(
|
||||
String app_id,
|
||||
) async {
|
||||
//print("Patien manager page: $endpoint");
|
||||
final response = await http.get(Uri.parse(
|
||||
"${AppEnviroment.baseApiUrl}/mzasni-wallet/loyalty-cards/favourites/$app_id"));
|
||||
// print("Here");
|
||||
// print("Body: ${response.body}");
|
||||
// print("Code: ${response.statusCode}");
|
||||
// errorCode = response.statusCode.toString();
|
||||
// errorBody = response.body;
|
||||
if (response.statusCode == 200) {
|
||||
// print("Here1");
|
||||
Iterable l = jsonDecode(response.body);
|
||||
//print("Here2");
|
||||
List<MIHLoyaltyCard> patientQueue = List<MIHLoyaltyCard>.from(
|
||||
l.map((model) => MIHLoyaltyCard.fromJson(model)));
|
||||
//print("Here3");
|
||||
//print(patientQueue);
|
||||
return patientQueue;
|
||||
} else {
|
||||
throw Exception('failed to fatch loyalty cards');
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is used to Delete loyalty card from users mzansi wallet.
|
||||
///
|
||||
/// Patameters:-
|
||||
@@ -66,6 +96,7 @@ class MIHMzansiWalletApis {
|
||||
static Future<void> deleteLoyaltyCardAPICall(
|
||||
AppUser signedInUser,
|
||||
int idloyalty_cards,
|
||||
int navIndex,
|
||||
BuildContext context,
|
||||
) async {
|
||||
loadingPopUp(context);
|
||||
@@ -83,14 +114,16 @@ class MIHMzansiWalletApis {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed(
|
||||
'/mzansi-wallet',
|
||||
arguments: signedInUser,
|
||||
arguments: WalletArguments(signedInUser, navIndex),
|
||||
);
|
||||
String message =
|
||||
"The loyalty card has been deleted successfully. This means it will no longer be visible in your Mzansi Wallet.";
|
||||
successPopUp(message, context);
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
internetConnectionPopUp(context);
|
||||
}
|
||||
}
|
||||
@@ -110,6 +143,9 @@ class MIHMzansiWalletApis {
|
||||
String app_id,
|
||||
String shop_name,
|
||||
String card_number,
|
||||
String favourite,
|
||||
int priority_index,
|
||||
int navIndex,
|
||||
BuildContext context,
|
||||
) async {
|
||||
loadingPopUp(context);
|
||||
@@ -123,6 +159,8 @@ class MIHMzansiWalletApis {
|
||||
"app_id": app_id,
|
||||
"shop_name": shop_name,
|
||||
"card_number": card_number,
|
||||
"favourite": favourite,
|
||||
"priority_index": priority_index,
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 201) {
|
||||
@@ -133,7 +171,7 @@ class MIHMzansiWalletApis {
|
||||
Navigator.pop(context);
|
||||
Navigator.of(context).pushNamed(
|
||||
'/mzansi-wallet',
|
||||
arguments: signedInUser,
|
||||
arguments: WalletArguments(signedInUser, navIndex),
|
||||
);
|
||||
successPopUp(message, context);
|
||||
} else {
|
||||
@@ -142,6 +180,54 @@ class MIHMzansiWalletApis {
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is used to Update loyalty card from users mzansi wallet.
|
||||
///
|
||||
/// Patameters:-
|
||||
/// AppUser signedInUser,
|
||||
/// int idloyalty_cards,
|
||||
/// BuildContext context,
|
||||
///
|
||||
/// Returns VOID (TRIGGERS NOTIGICATIOPN ON SUCCESS)
|
||||
static Future<void> updateLoyaltyCardAPICall(
|
||||
AppUser signedInUser,
|
||||
int idloyalty_cards,
|
||||
String favourite,
|
||||
int priority_index,
|
||||
int navIndex,
|
||||
BuildContext context,
|
||||
) async {
|
||||
loadingPopUp(context);
|
||||
var response = await http.put(
|
||||
Uri.parse(
|
||||
"${AppEnviroment.baseApiUrl}/mzasni-wallet/loyalty-cards/update/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"idloyalty_cards": idloyalty_cards,
|
||||
"favourite": favourite,
|
||||
"priority_index": priority_index,
|
||||
}),
|
||||
);
|
||||
//print("Here4");
|
||||
//print(response.statusCode);
|
||||
if (response.statusCode == 200) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed(
|
||||
'/mzansi-wallet',
|
||||
arguments: WalletArguments(signedInUser, navIndex),
|
||||
);
|
||||
String message = "The loyalty card has been added to your favourites.";
|
||||
successPopUp(message, context);
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
internetConnectionPopUp(context);
|
||||
}
|
||||
}
|
||||
|
||||
//================== POP UPS ==========================================================================
|
||||
|
||||
static void internetConnectionPopUp(BuildContext context) {
|
||||
|
||||
Reference in New Issue
Block a user