From 26504f374e7f2d0ac7720da6a246988bb42cd411 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 17:40:55 +0100 Subject: [PATCH 1/6] trying different flutter version for pipeline --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 562ecfe..a81e822 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: cirrusci/flutter:latest +image: cirrusci/flutter:3.3.5 stages: - analyze From a042933a2dcbc1974107d119767fa215eabab7ea Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 19:04:03 +0100 Subject: [PATCH 2/6] add http package --- android/app/src/main/AndroidManifest.xml | 2 ++ pubspec.lock | 2 +- pubspec.yaml | 9 +++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index bae31ce..c5439ff 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,7 @@ + + Date: Thu, 2 Mar 2023 19:04:40 +0100 Subject: [PATCH 3/6] add workout get db function --- lib/mock/db_mock.dart | 7 ++++++- lib/models/workout.dart | 10 ++++++++-- lib/services/database_service.dart | 9 +++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/mock/db_mock.dart b/lib/mock/db_mock.dart index 313cece..dac8c9f 100644 --- a/lib/mock/db_mock.dart +++ b/lib/mock/db_mock.dart @@ -17,7 +17,7 @@ class DatabaseMock implements DatabaseService { final List _moodRecords = []; final List _sleepRecords = []; final List _relapseRecords = []; - final List _workoutRecords = []; + final List _workoutRecords = []; @override Future addMood(Mood mood) { @@ -60,4 +60,9 @@ class DatabaseMock implements DatabaseService { Future> getRelapseRecords() { return Future.value(_relapseRecords); } + + @override + Future> getWorkoutRecords() { + return Future.value(_workoutRecords); + } } diff --git a/lib/models/workout.dart b/lib/models/workout.dart index 0bba86a..67dd828 100644 --- a/lib/models/workout.dart +++ b/lib/models/workout.dart @@ -7,10 +7,16 @@ class Workout implements DatabaseRecord { Workout(this._motivationBefore, this._motivationAfter, this._workoutDate); + @override + factory Workout.fromDatabase(Map map) { + return Workout(map['motivationBefore'], map['motivationAfter'], + DateTime.parse(map['workoutDate'])); + } + @override factory Workout.fromMap(Map map) { - return Workout(map['_workoutDuration'], map['_motivationBefore'], - map['_motivationAfter']); + return Workout( + map['motivationBefore'], map['motivationAfter'], map['workoutDate']); } @override diff --git a/lib/services/database_service.dart b/lib/services/database_service.dart index 3996883..acc3ca0 100644 --- a/lib/services/database_service.dart +++ b/lib/services/database_service.dart @@ -63,6 +63,15 @@ class DatabaseService { return relapseList; } + Future> getWorkoutRecords() async { + Database db = await instance.database; + var workoutRecords = await db.query('workout'); + List workoutList = workoutRecords.isNotEmpty + ? workoutRecords.map((e) => Workout.fromDatabase(e)).toList() + : []; + return workoutList; + } + Future addMood(Mood mood) async { Database db = await instance.database; return await db.insert('mood', mood.toMap()); From 0e070d73a2a7a6f0f133e67b2c963c740b7fa5bf Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 19:41:13 +0100 Subject: [PATCH 4/6] sending data of records to api --- lib/pages/scanner_page.dart | 13 +++------- lib/services/export_service.dart | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 lib/services/export_service.dart diff --git a/lib/pages/scanner_page.dart b/lib/pages/scanner_page.dart index de394f9..d809ff9 100644 --- a/lib/pages/scanner_page.dart +++ b/lib/pages/scanner_page.dart @@ -1,25 +1,18 @@ import 'package:awesome_dialog/awesome_dialog.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:smoke_cess_app/models/mood.dart'; -import 'package:smoke_cess_app/models/relapse.dart'; +import 'package:smoke_cess_app/services/export_service.dart'; import 'package:smoke_cess_app/services/settings_service.dart'; import 'package:smoke_cess_app/services/notification_service.dart'; import 'package:smoke_cess_app/widgets/scanner.dart'; -import '../models/sleep.dart'; import '../providers/settings_provider.dart'; -import '../globals.dart' as globals; class ScannerPage extends StatelessWidget { const ScannerPage({super.key}); void export() async { - List moods = await globals.databaseService.getMoodRecords(); - List sleeps = await globals.databaseService.getSleepRecords(); - List relapses = await globals.databaseService.getRelapseRecords(); - moods; - sleeps; - relapses; + ExportService exportService = ExportService(); + exportService.exportData(); } void loadJSON(BuildContext context) async { diff --git a/lib/services/export_service.dart b/lib/services/export_service.dart new file mode 100644 index 0000000..12afa12 --- /dev/null +++ b/lib/services/export_service.dart @@ -0,0 +1,43 @@ +import 'dart:convert'; + +import 'package:http/http.dart' as http; +import 'package:smoke_cess_app/models/mood.dart'; +import 'package:smoke_cess_app/models/relapse.dart'; +import 'package:smoke_cess_app/models/sleep.dart'; +import 'package:smoke_cess_app/models/workout.dart'; +import 'package:smoke_cess_app/services/database_service.dart'; +import '../globals.dart' as globals; + +class ExportService { + Uri url = Uri.parse('http://localhost:3000/data'); + final DatabaseService _databaseService = globals.databaseService; + + Future>> _loadRecords() async { + List moodRecords = await _databaseService.getMoodRecords(); + List sleepRecords = await _databaseService.getSleepRecords(); + List relapseRecords = await _databaseService.getRelapseRecords(); + List workoutRecords = await _databaseService.getWorkoutRecords(); + return { + 'Stimmung': + moodRecords.map((Mood mood) => jsonEncode(mood.toMap())).toList(), + 'Schlaf': + sleepRecords.map((Sleep sleep) => jsonEncode(sleep.toMap())).toList(), + 'Rückfall': relapseRecords + .map((Relapse relapse) => jsonEncode(relapse.toMap())) + .toList(), + 'Workout': workoutRecords + .map((Workout workout) => jsonEncode(workout.toMap())) + .toList() + }; + } + + void exportData() async { + Map> body = await _loadRecords(); + final response = await http.post(url, + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: jsonEncode(body)); + print(response.statusCode); + } +} From 0e49b9cd32a808942328a72f39a4c0120cbbc8c3 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 19:43:05 +0100 Subject: [PATCH 5/6] make date field of workout json encodable --- lib/models/workout.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/workout.dart b/lib/models/workout.dart index 67dd828..671dfc8 100644 --- a/lib/models/workout.dart +++ b/lib/models/workout.dart @@ -28,7 +28,7 @@ class Workout implements DatabaseRecord { return { 'motivationBefore': _motivationBefore, 'motivationAfter': _motivationAfter, - 'workoutDate': _workoutDate, + 'workoutDate': _workoutDate.toIso8601String(), }; } } From 7bc9d4f35d08076036826f26c62d7bdf19b20f4a Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 19:47:28 +0100 Subject: [PATCH 6/6] add minimal errorcheck --- lib/mock/db_mock.dart | 1 - lib/services/export_service.dart | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/mock/db_mock.dart b/lib/mock/db_mock.dart index dac8c9f..4e5d0e6 100644 --- a/lib/mock/db_mock.dart +++ b/lib/mock/db_mock.dart @@ -1,4 +1,3 @@ -import 'package:smoke_cess_app/interface/db_record.dart'; import 'package:smoke_cess_app/models/mood.dart'; import 'package:smoke_cess_app/models/relapse.dart'; import 'package:smoke_cess_app/models/sleep.dart'; diff --git a/lib/services/export_service.dart b/lib/services/export_service.dart index 12afa12..9758270 100644 --- a/lib/services/export_service.dart +++ b/lib/services/export_service.dart @@ -31,13 +31,13 @@ class ExportService { }; } - void exportData() async { + Future exportData() async { Map> body = await _loadRecords(); final response = await http.post(url, headers: { 'Content-Type': 'application/json; charset=UTF-8', }, body: jsonEncode(body)); - print(response.statusCode); + return response.statusCode >= 400 ? 0 : 1; } }