|
|
@ -2,14 +2,14 @@ import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
import 'package:firebase_storage/firebase_storage.dart';
|
|
|
|
import 'package:firebase_storage/firebase_storage.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../main.dart';
|
|
|
|
import '../main.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class PostService {
|
|
|
|
class PostService {
|
|
|
|
createPost(String? description, String idMusic, File? image,
|
|
|
|
createPost(String? description, String idMusic, File? image, Tuple2<String, String>? location) async {
|
|
|
|
Tuple2<String, String>? location) async {
|
|
|
|
|
|
|
|
var id = MyApp.userViewModel.userCurrent.id;
|
|
|
|
var id = MyApp.userViewModel.userCurrent.id;
|
|
|
|
final post = <String, dynamic>{
|
|
|
|
final post = <String, dynamic>{
|
|
|
|
"user_id": id,
|
|
|
|
"user_id": id,
|
|
|
@ -45,14 +45,11 @@ class PostService {
|
|
|
|
|
|
|
|
|
|
|
|
getPostsById(String id) {}
|
|
|
|
getPostsById(String id) {}
|
|
|
|
|
|
|
|
|
|
|
|
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts(
|
|
|
|
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>> getPopularPosts({int limit = 10, int offset = 0}) async {
|
|
|
|
{int limit = 10, int offset = 0}) async {
|
|
|
|
|
|
|
|
DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24));
|
|
|
|
DateTime twentyFourHoursAgo = DateTime.now().subtract(Duration(hours: 24));
|
|
|
|
Timestamp twentyFourHoursAgoTimestamp =
|
|
|
|
Timestamp twentyFourHoursAgoTimestamp = Timestamp.fromDate(twentyFourHoursAgo);
|
|
|
|
Timestamp.fromDate(twentyFourHoursAgo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore.instance
|
|
|
|
.instance
|
|
|
|
|
|
|
|
.collection("posts")
|
|
|
|
.collection("posts")
|
|
|
|
.where("date", isGreaterThan: twentyFourHoursAgoTimestamp)
|
|
|
|
.where("date", isGreaterThan: twentyFourHoursAgoTimestamp)
|
|
|
|
.limit(limit)
|
|
|
|
.limit(limit)
|
|
|
@ -67,16 +64,16 @@ class PostService {
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool> getAvailable(String idUser) async {
|
|
|
|
Future<bool> getAvailable(String idUser) async {
|
|
|
|
DateTime today = DateTime.now();
|
|
|
|
DateTime today = DateTime.now();
|
|
|
|
today = DateTime(today.year, today.month, today.day);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore
|
|
|
|
QuerySnapshot<Map<String, dynamic>> response =
|
|
|
|
.instance
|
|
|
|
await FirebaseFirestore.instance.collection("posts").where("user_id", isEqualTo: idUser).get();
|
|
|
|
.collection("posts")
|
|
|
|
|
|
|
|
.where("user_id", isEqualTo: idUser)
|
|
|
|
// Utiliser any() pour vérifier s'il y a au moins un document avec la date d'aujourd'hui
|
|
|
|
.where("date", isGreaterThanOrEqualTo: today)
|
|
|
|
bool isTodayAvailable = response.docs.any((doc) {
|
|
|
|
.where("date", isLessThan: today.add(Duration(days: 1)))
|
|
|
|
DateTime date = doc["date"].toDate(); // Assuming the field name is "date"
|
|
|
|
.get();
|
|
|
|
return date.day == today.day && date.month == today.month && date.year == today.year;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return response.docs.isNotEmpty;
|
|
|
|
return !isTodayAvailable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|