You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
justMusic/Sources/justMUSIC/lib/services/CommentService.dart

23 lines
693 B

import 'package:cloud_firestore/cloud_firestore.dart';
import '../main.dart';
class CommentService {
createComment(String text, String idPost) async {
var id = MyApp.userViewModel.userCurrent.id;
final comment = <String, dynamic>{"user_id": id, "text": text, "date": DateTime.now(), "post_id": idPost};
await MyApp.db.collection("comments").add(comment);
}
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getCommentsByPostId(String id) async {
var response = await FirebaseFirestore.instance
.collection("comments")
.where("post_id", isEqualTo: id)
.orderBy("date", descending: true)
.get();
return response.docs;
}
}