Skip to content

Commit

Permalink
Merge pull request #170 from PDG-NUTRI/162-add-client-to-dietitian
Browse files Browse the repository at this point in the history
162 add client to dietitian
  • Loading branch information
Nelson-Jnrnd authored Sep 5, 2022
2 parents b269b47 + 853d248 commit 523a955
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuousDeployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
9 changes: 8 additions & 1 deletion lib/api/firebase_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FirebaseUser extends FirebaseAPI implements IUser {
}

@override
void updateUser(User user) {
Future<void> updateUser(User user) async {
collectionReference
.doc(user.uid)
.update(user.toFirestore())
Expand Down Expand Up @@ -88,4 +88,11 @@ class FirebaseUser extends FirebaseAPI implements IUser {

return dietitians.isNotEmpty ? dietitians.first : null;
}

@override
Future<void> addClient(String userId, String dietitianId) async {
final dietitian = await readUser(dietitianId);
dietitian.addUser(userId);
await updateUser(dietitian);
}
}
3 changes: 2 additions & 1 deletion lib/api/iuser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'package:pdg_app/model/user.dart';
abstract class IUser {
Future<void> createUser(User user);
Future<User> readUser(String userid);
void updateUser(User user);
Future<void> updateUser(User user);
Future<void> addClient(String userId, String dietitianId);
void deleteUser(String userid);
Future<List<User>> getDietitianClient(String dietitianId);
Future<User?> readDietitianOfClient(String clientId);
Expand Down
4 changes: 4 additions & 0 deletions lib/model/meal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Meal implements IModel {
String? setting;
String? comment;
String owner;
String? photoUrl;

Meal(
{String? uid,
Expand All @@ -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();

Expand All @@ -44,6 +46,7 @@ class Meal implements IModel {
setting: data?['setting'],
comment: data?['comment'],
owner: data?['owner'],
photoUrl: data?['photoUrl'],
);
}

Expand All @@ -60,6 +63,7 @@ class Meal implements IModel {
'setting': setting,
'comment': comment,
'owner': owner,
'photoUrl': photoUrl,
};
}

Expand Down
7 changes: 7 additions & 0 deletions lib/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
24 changes: 24 additions & 0 deletions lib/scripts/app_run.dart
Original file line number Diff line number Diff line change
@@ -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é");
}
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions test/user_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]');
User d2 = User(
Expand Down Expand Up @@ -125,7 +125,7 @@ void main() {
});

test("getDietitianClients", () async {
List<User> coco = [c2, c3, c4];
List<User> coco = [c2, c3];
final clients = await userApi.getDietitianClient(d1.uid);
expect(clients.elementAt(0).toString(), coco.elementAt(0).toString());
});
Expand All @@ -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"]);
});
}

0 comments on commit 523a955

Please sign in to comment.