Changed id to be optional on [EventModel], [TaskModel] and [UserModel]
This commit is contained in:
parent
c95939f5df
commit
5c46398be1
1 changed files with 17 additions and 61 deletions
|
|
@ -40,71 +40,13 @@ class FirestoreProvider {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return Observable(mappedStream);
|
return Observable(mappedStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------Task related operations----------------------------
|
//-------------------------Task related operations----------------------------
|
||||||
|
|
||||||
/// Adds a task to firestore.
|
/// Returns a stream of [List<Task>]
|
||||||
Future<void> addTask(TaskModel task) async {
|
|
||||||
try {
|
|
||||||
final dataMap = task.toFirestoreMap();
|
|
||||||
await firestore.collection('tasks').add(dataMap);
|
|
||||||
} catch (e) {
|
|
||||||
print('Error adding task to firestore: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a Stream of a single task from an id.
|
|
||||||
Observable<TaskModel> getTask(String id) {
|
|
||||||
final mappedStream =
|
|
||||||
firestore.collection('tasks').document(id).snapshots().map(
|
|
||||||
(DocumentSnapshot snapshot) {
|
|
||||||
return TaskModel.fromFirestore(
|
|
||||||
snapshot.data,
|
|
||||||
id: snapshot.documentID,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return Observable(mappedStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes a task from firestore.
|
|
||||||
Future<void> deleteTask(String id) async {
|
|
||||||
try {
|
|
||||||
final documentReference = firestore.collection('tasks').document(id);
|
|
||||||
await documentReference.delete();
|
|
||||||
} catch (e) {
|
|
||||||
print('Error deleting task from firestore: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates a task in firestore.
|
|
||||||
///
|
|
||||||
/// Only the [text], [priority] and [done] attributes can be update.
|
|
||||||
/// Provide at least one of these values.
|
|
||||||
Future<void> updateTask(
|
|
||||||
String id, {
|
|
||||||
String text,
|
|
||||||
int priority,
|
|
||||||
bool done,
|
|
||||||
}) async {
|
|
||||||
final newData = <String, dynamic>{
|
|
||||||
'text': text,
|
|
||||||
'priority': priority,
|
|
||||||
'done': done,
|
|
||||||
};
|
|
||||||
newData.removeWhere((key, value) => value == null);
|
|
||||||
try {
|
|
||||||
final documentReference = firestore.collection('tasks').document(id);
|
|
||||||
await documentReference.setData(newData, merge: true);
|
|
||||||
} catch (e) {
|
|
||||||
print('Error updating task in firestore: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a stream of [List<Task>] that correspond to a particular user.
|
|
||||||
///
|
///
|
||||||
/// The [event] parameter is used to query tasks that are part of a certain
|
/// The [event] parameter is used to query tasks that are part of a certain
|
||||||
/// event.
|
/// event.
|
||||||
|
|
@ -134,9 +76,23 @@ class FirestoreProvider {
|
||||||
return Observable(mappedStream);
|
return Observable(mappedStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Observable<TaskModel> getTask(String id) {
|
||||||
|
final mappedStream =
|
||||||
|
firestore.collection('tasks').document(id).snapshots().map(
|
||||||
|
(DocumentSnapshot snapshot) {
|
||||||
|
return TaskModel.fromFirestore(
|
||||||
|
snapshot.data,
|
||||||
|
id: snapshot.documentID,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return Observable(mappedStream);
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------Event related operations-----------------------------
|
//-----------------------Event related operations-----------------------------
|
||||||
|
|
||||||
// TODO: Change the Events collction name to 'events' in forestore.
|
// TODO: Change the Events collction name to 'events'
|
||||||
Observable<List<EventModel>> getUserEvents(String userDocumentId) {
|
Observable<List<EventModel>> getUserEvents(String userDocumentId) {
|
||||||
final mappedStream = firestore
|
final mappedStream = firestore
|
||||||
.collection('users')
|
.collection('users')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue