diff --git a/.github/workflows/continuousDeployment.yml b/.github/workflows/continuousDeployment.yml index 7d22d4c..0a293d5 100644 --- a/.github/workflows/continuousDeployment.yml +++ b/.github/workflows/continuousDeployment.yml @@ -20,7 +20,7 @@ jobs: - name: Setup Flutter uses: subosito/flutter-action@v1 with: - flutter-version: "3.0.5" + flutter-version: "3.3.0" - name: Pub Get Packages run: flutter pub get diff --git a/.vscode/launch.json b/.vscode/launch.json index e5efc2b..020326a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -41,6 +41,13 @@ "request": "launch", "flutterMode": "debug", "program": "lib/scripts/test_email.dart" + }, + { + "name": "App run", + "type": "dart", + "request": "launch", + "flutterMode": "debug", + "program": "lib/scripts/app_run.dart" } ] } diff --git a/lib/api/firebase_user.dart b/lib/api/firebase_user.dart index 69703f6..e469140 100644 --- a/lib/api/firebase_user.dart +++ b/lib/api/firebase_user.dart @@ -35,7 +35,7 @@ class FirebaseUser extends FirebaseAPI implements IUser { } @override - void updateUser(User user) { + Future updateUser(User user) async { collectionReference .doc(user.uid) .update(user.toFirestore()) @@ -88,4 +88,11 @@ class FirebaseUser extends FirebaseAPI implements IUser { return dietitians.isNotEmpty ? dietitians.first : null; } + + @override + Future addClient(String userId, String dietitianId) async { + final dietitian = await readUser(dietitianId); + dietitian.addUser(userId); + await updateUser(dietitian); + } } diff --git a/lib/api/iuser.dart b/lib/api/iuser.dart index 8825124..03b0aed 100644 --- a/lib/api/iuser.dart +++ b/lib/api/iuser.dart @@ -3,7 +3,8 @@ import 'package:pdg_app/model/user.dart'; abstract class IUser { Future createUser(User user); Future readUser(String userid); - void updateUser(User user); + Future updateUser(User user); + Future addClient(String userId, String dietitianId); void deleteUser(String userid); Future> getDietitianClient(String dietitianId); Future readDietitianOfClient(String clientId); diff --git a/lib/model/meal.dart b/lib/model/meal.dart index bf4ffa7..ee70a9b 100644 --- a/lib/model/meal.dart +++ b/lib/model/meal.dart @@ -14,6 +14,7 @@ class Meal implements IModel { String? setting; String? comment; String owner; + String? photoUrl; Meal( {String? uid, @@ -25,6 +26,7 @@ class Meal implements IModel { required this.hunger, this.setting, this.comment, + this.photoUrl, required this.owner}) : uid = uid ?? const Uuid().v1(); @@ -44,6 +46,7 @@ class Meal implements IModel { setting: data?['setting'], comment: data?['comment'], owner: data?['owner'], + photoUrl: data?['photoUrl'], ); } @@ -60,6 +63,7 @@ class Meal implements IModel { 'setting': setting, 'comment': comment, 'owner': owner, + 'photoUrl': photoUrl, }; } diff --git a/lib/model/user.dart b/lib/model/user.dart index f69c9d4..b062ebd 100644 --- a/lib/model/user.dart +++ b/lib/model/user.dart @@ -66,4 +66,11 @@ class User implements IModel { void setFirstName(String name) { firstName = name; } + + void addUser(String userId) { + if (clientList == null) { + throw Exception("Client list is null"); + } + clientList!.add(userId); + } } diff --git a/lib/scripts/app_run.dart b/lib/scripts/app_run.dart new file mode 100644 index 0000000..71cb52d --- /dev/null +++ b/lib/scripts/app_run.dart @@ -0,0 +1,24 @@ +import 'dart:developer'; + +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:flutter/material.dart'; +import 'package:pdg_app/api/firebase_user.dart'; +import 'package:pdg_app/api/iuser.dart'; +import 'package:pdg_app/firebase_options.dart'; + +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); + runApp(const MaterialApp()); + + IUser userApi = FirebaseUser(FirebaseFirestore.instance); + + await userApi.addClient("coco", "PSCOEhz98TORfOb9BizGfjUA8hc2"); + final coco = await userApi.readUser("PSCOEhz98TORfOb9BizGfjUA8hc2"); + log(coco.clientList.toString()); + log("programme terminé"); +} diff --git a/pubspec.lock b/pubspec.lock index dc3567f..e7fb5ba 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -666,7 +666,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" path_drawing: dependency: transitive description: diff --git a/test/user_test.dart b/test/user_test.dart index 954ef30..2240213 100644 --- a/test/user_test.dart +++ b/test/user_test.dart @@ -38,7 +38,7 @@ User d1 = User( lastName: 'Emery', birthDate: DateTime.now(), avs: '', - clientList: [c2.uid, c3.uid, c4.uid], + clientList: [c2.uid, c3.uid], phoneNumber: '', email: 'claire.emery@gmail.com'); User d2 = User( @@ -125,7 +125,7 @@ void main() { }); test("getDietitianClients", () async { - List coco = [c2, c3, c4]; + List coco = [c2, c3]; final clients = await userApi.getDietitianClient(d1.uid); expect(clients.elementAt(0).toString(), coco.elementAt(0).toString()); }); @@ -134,4 +134,10 @@ void main() { final User? dietCopy = await userApi.readDietitianOfClient(c3.uid); expect(d1.toString(), dietCopy.toString()); }); + + test("Add Client to dietitian", () async { + await userApi.addClient("banane", d1.uid); + final User diet = await userApi.readUser(d1.uid); + expect(diet.clientList, [c2.uid, c3.uid, "banane"]); + }); }