listMedia method
List media for the current user with optional filters.
Supports filtering by type, startDate, endDate, and pagination
via limit and offset.
Implementation
Future<List<CloudMediaItem>> listMedia({
CloudMediaType? type,
int limit = 50,
int offset = 0,
DateTime? startDate,
DateTime? endDate,
String? searchQuery,
}) async {
Query query = _firestore
.collection(FirestorePaths.userMedia(_uid))
.where('deletedAt', isNull: true)
.orderBy('createdAt', descending: true)
.limit(limit);
if (type != null) {
query = query.where('type', isEqualTo: type.string);
}
if (startDate != null) {
query = query.where('createdAt',
isGreaterThanOrEqualTo: Timestamp.fromDate(startDate));
}
if (endDate != null) {
query = query.where('createdAt',
isLessThanOrEqualTo: Timestamp.fromDate(endDate));
}
final snap = await query.get();
return snap.docs.map(CloudMediaItem.fromFirestore).toList();
}