From 49c286771d093029c1ebdd97bea1c5dc5176993e Mon Sep 17 00:00:00 2001 From: ARYA SINGH Date: Wed, 9 Oct 2024 23:29:03 +0530 Subject: [PATCH] redis-phase2-success --- .github/workflows/main.yml | 10 +- README.md | 8 +- .../auth/presentation/auth/pages/signup.dart | 2 +- .../data/model/mood_data_model.dart | 26 +- .../repositories/meditaion_repo_impl.dart | 1 + .../sources/meditation_remote_source.dart | 24 +- .../meditation/domain/entities/mood_data.dart | 10 +- .../bloc/mood_data/mood_data_bloc.dart | 4 +- .../bloc/mood_data/mood_data_event.dart | 1 - .../presentation/pages/meditation_page.dart | 224 ++++++++++++------ .../music/data/sources/song_datasource.dart | 5 +- lib/main.dart | 62 +++-- pubspec.yaml | 2 +- 13 files changed, 226 insertions(+), 153 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd85829..6319a15 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -60,17 +60,17 @@ jobs: uses: ncipollo/release-action@v1 with: artifacts: "build/app/outputs/apk/release/*" - tag: v2.0.9.4 + tag: v2.1.0 token: ${{ secrets.TOKEN }} - name: "beta-v2.0.9.4" + name: "beta-v2.1.0" body: | - ## What's New in v2.0.9.4 + ## What's New in v2.1.0 - - Base Bug Fixes for Beta. + - **Redis connection fixes and data privacy improvised** - **Redis Cloud Implementation and Fetching in Beta Phase** - **Structure of Redis added to Clean Architecture - **Added Redis-base to support syncfusion** - **Fixed Performance and Responsiveness Issues by Improvised BLoC Structure. - **New Feature**: Implemented Syncfusion and Redis for low latency. - ### Known Issues are Resolved - Looking for vulnerabilities before Redis Full-Integration. + ### Known Issues are Resolved - Redis Full-Integration Phase 2 diff --git a/README.md b/README.md index 5e5d451..215d4bb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Build Status - Version + Version

@@ -17,16 +17,16 @@ **APP STATUS** : ALL CORE FUNCTIONALITIES WORKING (Deployed NodeJs & Postgresql on Render) -## What's New in v2.0.9.4 (Beta Trial Phase for Redis) (Use Stable Version for Best Experience) +## What's New in v2.1.0 (Beta Phase for Redis) (Use Stable Version for Best Experience) - - Base Bug Fixes for Beta. + - **Redis connection fixes and data privacy improvised** - **Redis Cloud Implementation and Fetching in Beta Phase** - **Structure of Redis added to Clean Architecture - **Added Redis-base to support syncfusion** - **Fixed Performance and Responsiveness Issues by Improvised BLoC Structure. - **New Feature**: Implemented Syncfusion and Redis for low latency. - ### Known Issues are Resolved - Looking for vulnerabilities before Redis Full-Integration. + ### Known Issues are Resolved - Redis Full-Integration Phase 2. [DEMO LINK OF WORKING](https://vimeo.com/1016496824?share=copy) diff --git a/lib/features/auth/presentation/auth/pages/signup.dart b/lib/features/auth/presentation/auth/pages/signup.dart index 45f038d..74cd3f9 100644 --- a/lib/features/auth/presentation/auth/pages/signup.dart +++ b/lib/features/auth/presentation/auth/pages/signup.dart @@ -89,7 +89,7 @@ class Signup extends StatelessWidget { final mm = Hive.box('lastlogin'); final first = Hive.box('firstime'); mm.put("google", "false"); - first.put('firsttime','true'); + first.put('firsttime', 'true'); Navigator.pushAndRemoveUntil( context, MaterialPageRoute( diff --git a/lib/features/meditation/data/model/mood_data_model.dart b/lib/features/meditation/data/model/mood_data_model.dart index 6f2fa03..05906d6 100644 --- a/lib/features/meditation/data/model/mood_data_model.dart +++ b/lib/features/meditation/data/model/mood_data_model.dart @@ -11,22 +11,20 @@ class MoodDataModel extends MoodData { required String relax, required String focus, }) : super( - happy: happy, - neutral: neutral, - sad: sad, - calm: calm, - relax: relax, - focus: focus - ); + happy: happy, + neutral: neutral, + sad: sad, + calm: calm, + relax: relax, + focus: focus); factory MoodDataModel.fromJson(Map json) { return MoodDataModel( - happy: json['happy'].toString(), - sad: json['sad'].toString(), - neutral: json['neutral'].toString(), - calm: json['calm'].toString(), - relax: json['relax'].toString(), - focus: json['focus'].toString() - ); + happy: json['happy'].toString(), + sad: json['sad'].toString(), + neutral: json['neutral'].toString(), + calm: json['calm'].toString(), + relax: json['relax'].toString(), + focus: json['focus'].toString()); } } diff --git a/lib/features/meditation/data/repositories/meditaion_repo_impl.dart b/lib/features/meditation/data/repositories/meditaion_repo_impl.dart index 147b7ac..c62cae9 100644 --- a/lib/features/meditation/data/repositories/meditaion_repo_impl.dart +++ b/lib/features/meditation/data/repositories/meditaion_repo_impl.dart @@ -18,6 +18,7 @@ class MeditationRepoImpl implements MeditationRepository { Future getMoodMessage(String mood) async { return await remoteDataSource.getMoodMessage(mood); } + @override Future getmoodData(String username) async { return await remoteDataSource.getmoodData(username); diff --git a/lib/features/meditation/data/sources/meditation_remote_source.dart b/lib/features/meditation/data/sources/meditation_remote_source.dart index b54faa9..a7f645d 100644 --- a/lib/features/meditation/data/sources/meditation_remote_source.dart +++ b/lib/features/meditation/data/sources/meditation_remote_source.dart @@ -16,9 +16,8 @@ class MeditationRemoteDataSourceImpl implements MeditaionRemoteDataSource { @override Future getDailyQuote() async { - final response = await client - .get(Uri.parse( - 'https://mindful-app-47s6.onrender.com/meditation/dailyQuotes')); + final response = await client.get(Uri.parse( + 'https://mindful-app-47s6.onrender.com/meditation/dailyQuotes')); if (response.statusCode == 200) { final jsonResponse = json.decode(response.body); @@ -31,9 +30,8 @@ class MeditationRemoteDataSourceImpl implements MeditaionRemoteDataSource { @override Future getMoodMessage(String mood) async { - final response = await client - .get(Uri.parse( - 'https://mindful-app-47s6.onrender.com/meditation/myMood/$mood')); + final response = await client.get(Uri.parse( + 'https://mindful-app-47s6.onrender.com/meditation/myMood/$mood')); if (response.statusCode == 200) { final jsonResponse = json.decode(response.body); @@ -44,19 +42,15 @@ class MeditationRemoteDataSourceImpl implements MeditaionRemoteDataSource { } @override - Future getmoodData(String username)async{ - final response = await client.get(Uri.parse( - 'https://mindful-app-47s6.onrender.com/user/$username' - )); + Future getmoodData(String username) async { + final response = await client + .get(Uri.parse('https://mindful-app-47s6.onrender.com/user/$username')); - if (response.statusCode==200){ + if (response.statusCode == 200) { final jsonResponse = json.decode(response.body); return MoodDataModel.fromJson(jsonResponse); - - } - else { + } else { throw Exception("Failed to get data"); - } } } diff --git a/lib/features/meditation/domain/entities/mood_data.dart b/lib/features/meditation/domain/entities/mood_data.dart index d2b75c6..122070a 100644 --- a/lib/features/meditation/domain/entities/mood_data.dart +++ b/lib/features/meditation/domain/entities/mood_data.dart @@ -6,7 +6,11 @@ class MoodData { final String relax; final String focus; - MoodData({required this.happy, required this.neutral, required this.sad, required this.calm, required this.relax, required this.focus}); - - + MoodData( + {required this.happy, + required this.neutral, + required this.sad, + required this.calm, + required this.relax, + required this.focus}); } diff --git a/lib/features/meditation/presentation/bloc/mood_data/mood_data_bloc.dart b/lib/features/meditation/presentation/bloc/mood_data/mood_data_bloc.dart index 2d50902..317128e 100644 --- a/lib/features/meditation/presentation/bloc/mood_data/mood_data_bloc.dart +++ b/lib/features/meditation/presentation/bloc/mood_data/mood_data_bloc.dart @@ -6,8 +6,7 @@ import 'package:mental_health/features/meditation/presentation/bloc/mood_data/mo class MoodDataBloc extends Bloc { final GetMoodData getmoodData; - MoodDataBloc({required this.getmoodData}) - : super(MoodDataInitial()) { + MoodDataBloc({required this.getmoodData}) : super(MoodDataInitial()) { on((event, emit) async { emit(MoodDataLoading()); try { @@ -17,6 +16,5 @@ class MoodDataBloc extends Bloc { emit(MoodDataError(message: e.toString())); } }); - } } diff --git a/lib/features/meditation/presentation/bloc/mood_data/mood_data_event.dart b/lib/features/meditation/presentation/bloc/mood_data/mood_data_event.dart index 1eb85b4..fa45848 100644 --- a/lib/features/meditation/presentation/bloc/mood_data/mood_data_event.dart +++ b/lib/features/meditation/presentation/bloc/mood_data/mood_data_event.dart @@ -5,4 +5,3 @@ class FetchMoodData extends MoodDataEvent { FetchMoodData(this.username); } - diff --git a/lib/features/meditation/presentation/pages/meditation_page.dart b/lib/features/meditation/presentation/pages/meditation_page.dart index 241d3c7..6f14bda 100644 --- a/lib/features/meditation/presentation/pages/meditation_page.dart +++ b/lib/features/meditation/presentation/pages/meditation_page.dart @@ -41,7 +41,6 @@ class _MeditationPageState extends State { @override void initState() { - _tooltipBehavior = TooltipBehavior(enable: true, format: 'point.x : point.y%'); __tooltipBehavior = _tooltipBehavior; @@ -192,7 +191,8 @@ class _MeditationPageState extends State { ); } - List> _getRadialBarCustomizedSeries() { + List> + _getRadialBarCustomizedSeries() { return >[ RadialBarSeries( animationDuration: 20, @@ -244,8 +244,6 @@ class _MeditationPageState extends State { List> _getDefaultColumn() { return >[ ColumnSeries( - - width: 0.8, spacing: 0.2, dataSource: __chartData, @@ -253,7 +251,6 @@ class _MeditationPageState extends State { xValueMapper: (ChartSampleData sales, _) => sales.x as String, yValueMapper: (ChartSampleData sales, _) => sales.y, name: 'Neutral'), - ColumnSeries( dataSource: __chartData, width: 0.8, @@ -262,7 +259,6 @@ class _MeditationPageState extends State { xValueMapper: (ChartSampleData sales, _) => sales.x as String, yValueMapper: (ChartSampleData sales, _) => sales.secondSeriesYValue, name: 'Happy'), - ColumnSeries( dataSource: __chartData, width: 0.8, @@ -288,7 +284,6 @@ class _MeditationPageState extends State { interval: 4, axisLine: AxisLine(width: 1), majorTickLines: MajorTickLines(size: 1)), - series: _getDefaultColumn(), legend: const Legend(isVisible: true), tooltipBehavior: __tooltipBehavior, @@ -722,11 +717,10 @@ class _MeditationPageState extends State { color: Colors.lightBlue.shade100.withOpacity(0.2), borderRadius: BorderRadius.circular(20), border: const Border( - bottom: BorderSide(color: Colors.black), - top: BorderSide(color: Colors.black), - left: BorderSide(color: Colors.black), - right: BorderSide(color: Colors.black) - )), + bottom: BorderSide(color: Colors.black), + top: BorderSide(color: Colors.black), + left: BorderSide(color: Colors.black), + right: BorderSide(color: Colors.black))), child: Column( children: [ const Padding( @@ -757,70 +751,147 @@ class _MeditationPageState extends State { textAlign: TextAlign.center, ), //graph - valobatained=='true'?const SizedBox(height:50,child: Text("No data",style: TextStyle(color: Colors.black),),):BlocBuilder(builder: (context,state){ - if (state is MoodDataLoaded){ - __chartData = [ - ChartSampleData(x: 'Mon', y: num.parse(state.moodDatainfo.happy), secondSeriesYValue: num.parse(state.moodDatainfo.neutral), thirdSeriesYValue: num.parse(state.moodDatainfo.calm)), - ChartSampleData(x: 'Tue', y: num.parse(state.moodDatainfo.happy), secondSeriesYValue: num.parse(state.moodDatainfo.neutral), thirdSeriesYValue: num.parse(state.moodDatainfo.calm)), - ChartSampleData(x: 'Wed', y: num.parse(state.moodDatainfo.happy), secondSeriesYValue: num.parse(state.moodDatainfo.neutral), thirdSeriesYValue: num.parse(state.moodDatainfo.calm)), - ChartSampleData(x: 'Thurs', y: num.parse(state.moodDatainfo.happy), secondSeriesYValue: num.parse(state.moodDatainfo.neutral), thirdSeriesYValue: num.parse(state.moodDatainfo.calm)), - ChartSampleData(x: 'Fri', y: num.parse(state.moodDatainfo.happy), secondSeriesYValue: num.parse(state.moodDatainfo.neutral), thirdSeriesYValue: num.parse(state.moodDatainfo.calm)), - ChartSampleData(x: 'Sat', y: num.parse(state.moodDatainfo.happy), secondSeriesYValue: num.parse(state.moodDatainfo.neutral), thirdSeriesYValue: num.parse(state.moodDatainfo.calm)), - ChartSampleData(x: 'Sun', y: num.parse(state.moodDatainfo.happy), secondSeriesYValue: num.parse(state.moodDatainfo.neutral), thirdSeriesYValue: num.parse(state.moodDatainfo.calm)), - - ]; - - num total = num.parse(state.moodDatainfo.happy)+num.parse(state.moodDatainfo.neutral)+num.parse(state.moodDatainfo.sad)+num.parse(state.moodDatainfo.calm)+num.parse(state.moodDatainfo.relax)+num.parse(state.moodDatainfo.focus); - dataSources = [ - ChartSampleData( - x: 'Happy', - y: num.parse(state.moodDatainfo.happy)/total, - text: '10%', - pointColor: const Color.fromRGBO(69, 186, 161, 1.0)), - ChartSampleData( - x: 'Neutral', - y: num.parse(state.moodDatainfo.neutral)/total, - text: '10%', - pointColor: const Color.fromRGBO(230, 135, 111, 1.0)), - ChartSampleData( - x: 'Sad', - y:num.parse(state.moodDatainfo.sad)/total, - text: '100%', - pointColor: const Color.fromRGBO(145, 132, 202, 1.0)), - ChartSampleData( - x: 'Calm', - y: num.parse(state.moodDatainfo.calm)/total, - text: '100%', - pointColor: const Color.fromRGBO(145, 132, 202, 1.0)), - ChartSampleData( - x: 'Relax', - y: num.parse(state.moodDatainfo.relax)/total, - text: '100%', - pointColor: const Color.fromRGBO(145, 132, 202, 1.0)), - ChartSampleData( - x: 'Focus', - y: num.parse(state.moodDatainfo.focus)/total, - text: '100%', - pointColor: const Color.fromRGBO(235, 96, 143, 1.0)) - ]; - try { - return _buildColumnChart(); - }catch(error){ - return const Text("ERROR LOADING"); - } - } - if (state is MoodDataLoading){ - return const Text("loading"); - } - - if (state is MoodDataError){ - print(state.message); - return const Text("No Data Found",textAlign:TextAlign.center,style: TextStyle(color: Colors.red,fontWeight: FontWeight.bold),); - } - return Container(); - - }) - + valobatained == 'true' + ? const SizedBox( + height: 50, + child: Text( + "No data", + style: TextStyle(color: Colors.red), + ), + ) + : BlocBuilder( + builder: (context, state) { + if (state is MoodDataLoaded) { + __chartData = [ + ChartSampleData( + x: 'Mon', + y: num.parse(state.moodDatainfo.happy), + secondSeriesYValue: + num.parse(state.moodDatainfo.neutral), + thirdSeriesYValue: + num.parse(state.moodDatainfo.calm)), + ChartSampleData( + x: 'Tue', + y: num.parse(state.moodDatainfo.happy), + secondSeriesYValue: + num.parse(state.moodDatainfo.neutral), + thirdSeriesYValue: + num.parse(state.moodDatainfo.calm)), + ChartSampleData( + x: 'Wed', + y: num.parse(state.moodDatainfo.happy), + secondSeriesYValue: + num.parse(state.moodDatainfo.neutral), + thirdSeriesYValue: + num.parse(state.moodDatainfo.calm)), + ChartSampleData( + x: 'Thurs', + y: num.parse(state.moodDatainfo.happy), + secondSeriesYValue: + num.parse(state.moodDatainfo.neutral), + thirdSeriesYValue: + num.parse(state.moodDatainfo.calm)), + ChartSampleData( + x: 'Fri', + y: num.parse(state.moodDatainfo.happy), + secondSeriesYValue: + num.parse(state.moodDatainfo.neutral), + thirdSeriesYValue: + num.parse(state.moodDatainfo.calm)), + ChartSampleData( + x: 'Sat', + y: num.parse(state.moodDatainfo.happy), + secondSeriesYValue: + num.parse(state.moodDatainfo.neutral), + thirdSeriesYValue: + num.parse(state.moodDatainfo.calm)), + ChartSampleData( + x: 'Sun', + y: num.parse(state.moodDatainfo.happy), + secondSeriesYValue: + num.parse(state.moodDatainfo.neutral), + thirdSeriesYValue: + num.parse(state.moodDatainfo.calm)), + ]; + + num total = num.parse(state.moodDatainfo.happy) + + num.parse(state.moodDatainfo.neutral) + + num.parse(state.moodDatainfo.sad) + + num.parse(state.moodDatainfo.calm) + + num.parse(state.moodDatainfo.relax) + + num.parse(state.moodDatainfo.focus); + dataSources = [ + ChartSampleData( + x: 'Happy', + y: num.parse(state.moodDatainfo.happy) / + total, + text: '10%', + pointColor: const Color.fromRGBO( + 69, 186, 161, 1.0)), + ChartSampleData( + x: 'Neutral', + y: num.parse(state.moodDatainfo.neutral) / + total, + text: '10%', + pointColor: const Color.fromRGBO( + 230, 135, 111, 1.0)), + ChartSampleData( + x: 'Sad', + y: num.parse(state.moodDatainfo.sad) / + total, + text: '100%', + pointColor: const Color.fromRGBO( + 145, 132, 202, 1.0)), + ChartSampleData( + x: 'Calm', + y: num.parse(state.moodDatainfo.calm) / + total, + text: '100%', + pointColor: const Color.fromRGBO( + 145, 132, 202, 1.0)), + ChartSampleData( + x: 'Relax', + y: num.parse(state.moodDatainfo.relax) / + total, + text: '100%', + pointColor: const Color.fromRGBO( + 145, 132, 202, 1.0)), + ChartSampleData( + x: 'Focus', + y: num.parse(state.moodDatainfo.focus) / + total, + text: '100%', + pointColor: + const Color.fromRGBO(235, 96, 143, 1.0)) + ]; + try { + return _buildColumnChart(); + } catch (error) { + return const Text("ERROR LOADING"); + } + } + if (state is MoodDataLoading) { + return const Text("loading"); + } + + if (state is MoodDataError) { + print(state.message); + return const Text( + "No Data Found", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.red, + fontWeight: FontWeight.bold), + ); + } + return const SizedBox( + height: 50, + child: Text( + "No data", + style: TextStyle(color: Colors.red), + ), + ); + }) ], ), ), @@ -872,7 +943,6 @@ class _MeditationPageState extends State { return Container(); }, ), - ], ), ), diff --git a/lib/features/music/data/sources/song_datasource.dart b/lib/features/music/data/sources/song_datasource.dart index c9b97da..34ad72d 100644 --- a/lib/features/music/data/sources/song_datasource.dart +++ b/lib/features/music/data/sources/song_datasource.dart @@ -16,9 +16,8 @@ class SongRemoteDataSourceImpl implements SongRemoteDataSource { @override Future> getAllSongs() async { - final response = - await client - .get(Uri.parse('https://mindful-app-47s6.onrender.com/songs/all')); + final response = await client + .get(Uri.parse('https://mindful-app-47s6.onrender.com/songs/all')); if (response.statusCode == 200) { List jsonResponse = json.decode(response.body); List finalRes = []; diff --git a/lib/main.dart b/lib/main.dart index 240817e..e85d102 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -57,23 +57,24 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { final mybox = Hive.box('lastlogin'); - final first= Hive.box('firstime'); + final first = Hive.box('firstime'); final idval; - first.put('firsttime','false'); + first.put('firsttime', 'false'); bool google = mybox.get('google').toString() == 'true'; - if (google==true) { - + if (google == true) { idval = "aryasingh8405@gmail.com-google"; //temp - }else{ + } else { idval = FirebaseAuth.instance.currentUser?.email.toString(); } return MultiBlocProvider( providers: [ BlocProvider(create: (_) => NavBloc()), BlocProvider(create: (context) => di.sl()..add(FetchSongs())), - BlocProvider(create: (context) => di.sl()..add(FetchDailyQuote())), + BlocProvider( + create: (context) => + di.sl()..add(FetchDailyQuote())), BlocProvider(create: (context) => di.sl()), - BlocProvider(create: (context) => di.sl()..add(FetchMoodData(idval.toString()))), + BlocProvider(create: (context) => di.sl()), ], child: MaterialApp( debugShowCheckedModeBanner: false, @@ -96,23 +97,28 @@ class inPage extends StatefulWidget { State createState() => _inPageState(); } - class _inPageState extends State { - Future signIn() async { final user = await GoogleSignInApi.login(); final myboxx = Hive.box('lastlogin'); final first = Hive.box('firstime'); if (user == null) { ScaffoldMessenger.of(context) - .showSnackBar(const SnackBar(content: Text("Faliure"))); + .showSnackBar(const SnackBar(content: Text("Failure"))); } else { myboxx.put('google', 'true'); - first.put("firsttime",'false'); + first.put("firsttime", 'false'); + String? value = GoogleSignInApi.details()?.email; + print(value); + try { + context.read().add(FetchMoodData("${value}-google")); + } catch (error) { + print(error); + } Navigator.pushAndRemoveUntil( context, MaterialPageRoute(builder: (BuildContext context) => HomePage()), - (route) => false); + (route) => false); } } @@ -126,24 +132,28 @@ class _inPageState extends State { @override Widget build(BuildContext context) { - - return const Scaffold( backgroundColor: Colors.black, body: Center( child: SizedBox( - height: 300, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - FaIcon(FontAwesomeIcons.google,color: Colors.red,size: 30,), - SizedBox(height: 20,), - Text( - "Signing In...", - style: TextStyle(fontSize: 18, color: Colors.white),) - ], - ) - ), + height: 300, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FaIcon( + FontAwesomeIcons.google, + color: Colors.red, + size: 30, + ), + SizedBox( + height: 20, + ), + Text( + "Signing In...", + style: TextStyle(fontSize: 18, color: Colors.white), + ) + ], + )), ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index 862b920..c1529bf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 2.0.9 +version: 2.1.0 environment: sdk: ^3.5.3