-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.dart
39 lines (33 loc) · 1005 Bytes
/
database.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:digibook2/models/user.dart';
class OurDatabase{
Future<String> createUser(OurUser user) async{
String retVal="error";
try{
await FirebaseFirestore.instance.collection('users').document(user.uid).set(
{
'fullName': user.fullName,
'email': user.email,
'accountCreated': Timestamp.now(),
});
retVal="success";
}catch(e){
print(e);
}
return retVal;
}
Future<OurUser> getUserInfo(String uid) async{
OurUser retVal=OurUser();
try{
DocumentSnapshot _docSnapshot=await FirebaseFirestore.instance.collection('users').document(uid).get();
final data=_docSnapshot.data();
retVal.uid=uid;
retVal.fullName=data["fullName"];
retVal.email=data["email"];
retVal.accountCreated=data["accountCreated"];
}catch(e){
print(e);
}
return retVal;
}
}