listMedia method

Future<List<CloudMediaItem>> listMedia({
  1. CloudMediaType? type,
  2. int limit = 50,
  3. int offset = 0,
  4. DateTime? startDate,
  5. DateTime? endDate,
  6. String? searchQuery,
})

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', isEqualTo: null)
      .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();
}