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 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 @@ + + map) { - return Workout(map['_workoutDuration'], map['_motivationBefore'], - map['_motivationAfter']); + return Workout(map['motivationBefore'], map['motivationAfter'], + DateTime.parse(map['workoutDate'])); + } + + @override + factory Workout.fromMap(Map map) { + return Workout( + map['motivationBefore'], map['motivationAfter'], map['workoutDate']); } @override @@ -24,7 +30,7 @@ class Workout implements DatabaseRecord { return { 'motivationBefore': _motivationBefore, 'motivationAfter': _motivationAfter, - 'workoutDate': _workoutDate, + 'workoutDate': _workoutDate.toIso8601String(), }; } } 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..9758270 --- /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() + }; + } + + Future exportData() async { + Map> body = await _loadRecords(); + final response = await http.post(url, + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: jsonEncode(body)); + return response.statusCode >= 400 ? 0 : 1; + } +} diff --git a/pubspec.lock b/pubspec.lock index 08b0b74..98b299a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -192,7 +192,7 @@ packages: source: hosted version: "2.2.0" http: - dependency: transitive + dependency: "direct main" description: name: http url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index 5c61553..473cf66 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,15 +36,16 @@ dependencies: path_provider: ^2.0.12 provider: ^6.0.5 awesome_dialog: ^3.0.2 - - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 timezone: ^0.9.0 shared_preferences: ^2.0.17 audioplayers: ^3.0.1 mobile_scanner: ^3.0.0 flutter_local_notifications: ^13.0.0 + http: ^0.13.5 + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: