|
|
|
@ -7,7 +7,8 @@ import 'package:firebase_storage/firebase_storage.dart';
|
|
|
|
|
import '../main.dart';
|
|
|
|
|
|
|
|
|
|
class PostService {
|
|
|
|
|
createPost(String? description, String idMusic, File? image, Tuple2<String, String>? location) async {
|
|
|
|
|
createPost(String? description, String idMusic, File? image,
|
|
|
|
|
Tuple2<String, String>? location) async {
|
|
|
|
|
var id = MyApp.userViewModel.userCurrent.id;
|
|
|
|
|
final post = <String, dynamic>{
|
|
|
|
|
"user_id": id,
|
|
|
|
@ -41,11 +42,14 @@ class PostService {
|
|
|
|
|
|
|
|
|
|
deletePost() {}
|
|
|
|
|
|
|
|
|
|
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts({int limit = 10, int offset = 0}) async {
|
|
|
|
|
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts(
|
|
|
|
|
{int limit = 10, int offset = 0}) async {
|
|
|
|
|
DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24));
|
|
|
|
|
Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo);
|
|
|
|
|
Timestamp twentyFourHoursAgoTimestamp =
|
|
|
|
|
Timestamp.fromDate(twentyFourHoursAgo);
|
|
|
|
|
|
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore.instance
|
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore
|
|
|
|
|
.instance
|
|
|
|
|
.collection("posts")
|
|
|
|
|
.where("date", isGreaterThan: twentyFourHoursAgoTimestamp)
|
|
|
|
|
.limit(limit)
|
|
|
|
@ -63,7 +67,8 @@ class PostService {
|
|
|
|
|
return Timestamp.fromDate(twentyFourHoursAgo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPostsFriends({int limit = 10, int offset = 0}) async {
|
|
|
|
|
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPostsFriends(
|
|
|
|
|
{int limit = 10, int offset = 0}) async {
|
|
|
|
|
var timestamp = _getTwentyFourHoursAgoTimestamp();
|
|
|
|
|
var response = await FirebaseFirestore.instance
|
|
|
|
|
.collection("posts")
|
|
|
|
@ -79,12 +84,17 @@ class PostService {
|
|
|
|
|
Future<bool> getAvailable(String idUser) async {
|
|
|
|
|
DateTime today = DateTime.now();
|
|
|
|
|
|
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response =
|
|
|
|
|
await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get();
|
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore
|
|
|
|
|
.instance
|
|
|
|
|
.collection("posts")
|
|
|
|
|
.where("user_id", isEqualTo: idUser)
|
|
|
|
|
.get();
|
|
|
|
|
|
|
|
|
|
bool isTodayAvailable = response.docs.any((doc) {
|
|
|
|
|
DateTime date = doc["date"].toDate(); // Assuming the field name is "date"
|
|
|
|
|
return date.day == today.day && date.month == today.month && date.year == today.year;
|
|
|
|
|
return date.day == today.day &&
|
|
|
|
|
date.month == today.month &&
|
|
|
|
|
date.year == today.year;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return !isTodayAvailable;
|
|
|
|
@ -95,11 +105,15 @@ class PostService {
|
|
|
|
|
|
|
|
|
|
DateTime sevenDaysAgo = DateTime.now().subtract(Duration(days: 6));
|
|
|
|
|
|
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response =
|
|
|
|
|
await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: id).get();
|
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore
|
|
|
|
|
.instance
|
|
|
|
|
.collection("posts")
|
|
|
|
|
.where("user_id", isEqualTo: id)
|
|
|
|
|
.get();
|
|
|
|
|
|
|
|
|
|
List<Map<String, dynamic>?> postList =
|
|
|
|
|
response.docs.map((DocumentSnapshot<Map<String, dynamic>> doc) => doc.data()).toList();
|
|
|
|
|
List<Map<String, dynamic>?> postList = response.docs
|
|
|
|
|
.map((DocumentSnapshot<Map<String, dynamic>> doc) => doc.data())
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 7; i++) {
|
|
|
|
|
DateTime date = sevenDaysAgo.add(Duration(days: i));
|
|
|
|
|