add notifications api call
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:patient_manager/mih_objects/app_user.dart';
|
import 'package:patient_manager/mih_objects/app_user.dart';
|
||||||
import 'package:patient_manager/mih_objects/business.dart';
|
import 'package:patient_manager/mih_objects/business.dart';
|
||||||
import 'package:patient_manager/mih_objects/business_user.dart';
|
import 'package:patient_manager/mih_objects/business_user.dart';
|
||||||
|
import 'package:patient_manager/mih_objects/notification.dart';
|
||||||
import 'package:patient_manager/mih_objects/patients.dart';
|
import 'package:patient_manager/mih_objects/patients.dart';
|
||||||
|
|
||||||
class BusinessArguments {
|
class BusinessArguments {
|
||||||
@@ -22,12 +23,14 @@ class HomeArguments {
|
|||||||
final AppUser signedInUser;
|
final AppUser signedInUser;
|
||||||
final BusinessUser? businessUser;
|
final BusinessUser? businessUser;
|
||||||
final Business? business;
|
final Business? business;
|
||||||
|
final List<MIHNotification> notifi;
|
||||||
final String profilePicUrl;
|
final String profilePicUrl;
|
||||||
|
|
||||||
HomeArguments(
|
HomeArguments(
|
||||||
this.signedInUser,
|
this.signedInUser,
|
||||||
this.businessUser,
|
this.businessUser,
|
||||||
this.business,
|
this.business,
|
||||||
|
this.notifi,
|
||||||
this.profilePicUrl,
|
this.profilePicUrl,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
43
Frontend/patient_manager/lib/mih_objects/notification.dart
Normal file
43
Frontend/patient_manager/lib/mih_objects/notification.dart
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
class MIHNotification {
|
||||||
|
final int idnotifications;
|
||||||
|
final String app_id;
|
||||||
|
final String notification_message;
|
||||||
|
final String notification_read;
|
||||||
|
final String action_path;
|
||||||
|
final String insert_date;
|
||||||
|
final String notification_type;
|
||||||
|
|
||||||
|
const MIHNotification({
|
||||||
|
required this.idnotifications,
|
||||||
|
required this.app_id,
|
||||||
|
required this.notification_message,
|
||||||
|
required this.notification_read,
|
||||||
|
required this.action_path,
|
||||||
|
required this.insert_date,
|
||||||
|
required this.notification_type,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory MIHNotification.fromJson(Map<String, dynamic> json) {
|
||||||
|
return switch (json) {
|
||||||
|
{
|
||||||
|
"idnotifications": int idnotifications,
|
||||||
|
"app_id": String app_id,
|
||||||
|
"notification_message": String notification_message,
|
||||||
|
"notification_read": String notification_read,
|
||||||
|
"action_path": String action_path,
|
||||||
|
"insert_date": String insert_date,
|
||||||
|
"notification_type": String notification_type,
|
||||||
|
} =>
|
||||||
|
MIHNotification(
|
||||||
|
idnotifications: idnotifications,
|
||||||
|
app_id: app_id,
|
||||||
|
notification_message: notification_message,
|
||||||
|
notification_read: notification_read,
|
||||||
|
action_path: action_path,
|
||||||
|
insert_date: insert_date,
|
||||||
|
notification_type: notification_type,
|
||||||
|
),
|
||||||
|
_ => throw const FormatException('Failed to load Notifications.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,11 +21,13 @@ import 'package:patient_manager/mih_objects/app_user.dart';
|
|||||||
import 'package:patient_manager/mih_objects/arguments.dart';
|
import 'package:patient_manager/mih_objects/arguments.dart';
|
||||||
import 'package:patient_manager/mih_objects/business.dart';
|
import 'package:patient_manager/mih_objects/business.dart';
|
||||||
import 'package:patient_manager/mih_objects/business_user.dart';
|
import 'package:patient_manager/mih_objects/business_user.dart';
|
||||||
|
import 'package:patient_manager/mih_objects/notification.dart';
|
||||||
|
|
||||||
class MIHHome extends StatefulWidget {
|
class MIHHome extends StatefulWidget {
|
||||||
final AppUser signedInUser;
|
final AppUser signedInUser;
|
||||||
final BusinessUser? businessUser;
|
final BusinessUser? businessUser;
|
||||||
final Business? business;
|
final Business? business;
|
||||||
|
final List<MIHNotification> notifications;
|
||||||
final ImageProvider<Object>? propicFile;
|
final ImageProvider<Object>? propicFile;
|
||||||
final bool isUserNew;
|
final bool isUserNew;
|
||||||
final bool isBusinessUser;
|
final bool isBusinessUser;
|
||||||
@@ -36,6 +38,7 @@ class MIHHome extends StatefulWidget {
|
|||||||
required this.signedInUser,
|
required this.signedInUser,
|
||||||
required this.businessUser,
|
required this.businessUser,
|
||||||
required this.business,
|
required this.business,
|
||||||
|
required this.notifications,
|
||||||
required this.propicFile,
|
required this.propicFile,
|
||||||
required this.isUserNew,
|
required this.isUserNew,
|
||||||
required this.isBusinessUser,
|
required this.isBusinessUser,
|
||||||
@@ -631,7 +634,7 @@ class _MIHHomeState extends State<MIHHome> {
|
|||||||
MIHNotificationDrawer getSecondaryActionDrawer() {
|
MIHNotificationDrawer getSecondaryActionDrawer() {
|
||||||
return MIHNotificationDrawer(
|
return MIHNotificationDrawer(
|
||||||
signedInUser: widget.signedInUser,
|
signedInUser: widget.signedInUser,
|
||||||
propicFile: widget.propicFile,
|
notifications: widget.notifications,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import 'package:patient_manager/mih_objects/app_user.dart';
|
|||||||
import 'package:patient_manager/mih_objects/arguments.dart';
|
import 'package:patient_manager/mih_objects/arguments.dart';
|
||||||
import 'package:patient_manager/mih_objects/business.dart';
|
import 'package:patient_manager/mih_objects/business.dart';
|
||||||
import 'package:patient_manager/mih_objects/business_user.dart';
|
import 'package:patient_manager/mih_objects/business_user.dart';
|
||||||
|
import 'package:patient_manager/mih_objects/notification.dart';
|
||||||
import 'package:patient_manager/mih_packages/mih_home/mih_home.dart';
|
import 'package:patient_manager/mih_packages/mih_home/mih_home.dart';
|
||||||
import 'package:supertokens_flutter/supertokens.dart';
|
import 'package:supertokens_flutter/supertokens.dart';
|
||||||
import 'package:supertokens_flutter/http.dart' as http;
|
import 'package:supertokens_flutter/http.dart' as http;
|
||||||
@@ -26,6 +27,7 @@ class MIHProfileGetter extends StatefulWidget {
|
|||||||
|
|
||||||
class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
||||||
String useremail = "";
|
String useremail = "";
|
||||||
|
int amount = 10;
|
||||||
final baseAPI = AppEnviroment.baseApiUrl;
|
final baseAPI = AppEnviroment.baseApiUrl;
|
||||||
late Future<HomeArguments> profile;
|
late Future<HomeArguments> profile;
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
|||||||
AppUser userData;
|
AppUser userData;
|
||||||
Business? busData;
|
Business? busData;
|
||||||
BusinessUser? bUserData;
|
BusinessUser? bUserData;
|
||||||
|
List<MIHNotification> notifi;
|
||||||
String userPic;
|
String userPic;
|
||||||
|
|
||||||
// Get Userdata
|
// Get Userdata
|
||||||
@@ -53,8 +56,9 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get BusinessUserdata
|
// Get BusinessUserdata
|
||||||
var responseBUser =
|
var responseBUser = await http.get(
|
||||||
await http.get(Uri.parse("$baseAPI/business-user/$uid"));
|
Uri.parse("$baseAPI/business-user/$uid"),
|
||||||
|
);
|
||||||
if (responseBUser.statusCode == 200) {
|
if (responseBUser.statusCode == 200) {
|
||||||
String body = responseBUser.body;
|
String body = responseBUser.body;
|
||||||
var decodedData = jsonDecode(body);
|
var decodedData = jsonDecode(body);
|
||||||
@@ -99,8 +103,26 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
|||||||
// "Error: GetUserData status code ${response.statusCode}");
|
// "Error: GetUserData status code ${response.statusCode}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get Notifications
|
||||||
|
var responseNotification =
|
||||||
|
await http.get(Uri.parse("$baseAPI/notifications/$uid?amount=$amount"));
|
||||||
|
if (responseNotification.statusCode == 200) {
|
||||||
|
String body = responseNotification.body;
|
||||||
|
// var decodedData = jsonDecode(body);
|
||||||
|
// MIHNotification notifications = MIHNotification.fromJson(decodedData);
|
||||||
|
|
||||||
|
Iterable l = jsonDecode(body);
|
||||||
|
//print("Here2");
|
||||||
|
List<MIHNotification> notifications = List<MIHNotification>.from(
|
||||||
|
l.map((model) => MIHNotification.fromJson(model)));
|
||||||
|
notifi = notifications;
|
||||||
|
} else {
|
||||||
|
notifi = [];
|
||||||
|
}
|
||||||
|
|
||||||
//print(userPic);
|
//print(userPic);
|
||||||
return HomeArguments(userData, bUserData, busData, userPic);
|
return HomeArguments(userData, bUserData, busData, notifi, userPic);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageProvider<Object>? isPictureAvailable(String url) {
|
ImageProvider<Object>? isPictureAvailable(String url) {
|
||||||
@@ -169,6 +191,7 @@ class _MIHProfileGetterState extends State<MIHProfileGetter> {
|
|||||||
signedInUser: snapshot.requireData.signedInUser,
|
signedInUser: snapshot.requireData.signedInUser,
|
||||||
businessUser: snapshot.data!.businessUser,
|
businessUser: snapshot.data!.businessUser,
|
||||||
business: snapshot.data!.business,
|
business: snapshot.data!.business,
|
||||||
|
notifications: snapshot.data!.notifi,
|
||||||
propicFile: isPictureAvailable(snapshot.data!.profilePicUrl),
|
propicFile: isPictureAvailable(snapshot.data!.profilePicUrl),
|
||||||
isUserNew: isUserNew(snapshot.requireData.signedInUser),
|
isUserNew: isUserNew(snapshot.requireData.signedInUser),
|
||||||
isBusinessUser: isBusinessUser(snapshot.requireData.signedInUser),
|
isBusinessUser: isBusinessUser(snapshot.requireData.signedInUser),
|
||||||
|
|||||||
Reference in New Issue
Block a user