createRoute method

Future<String> createRoute(
  1. String userId,
  2. String name,
  3. dynamic routeData, {
  4. bool isPublic = false,
  5. List<String> sharedWith = const [],
  6. List<String> tags = const [],
})

//////////// //////////// Creates a new route in Firestore

Implementation

// II.B - CRUD Operations
///////////////
/// Creates a new route in Firestore
Future<String> createRoute(
  String userId,
  String name,
  dynamic routeData,
  {
    bool isPublic = false,
    List<String> sharedWith = const [],
    List<String> tags = const [],
  }
) async {
  try {
    // Create the route object
    final route = RaliRoute(
      name: name,
      createdBy: userId,
      routeData: routeData,
      isPublic: isPublic,
      sharedWith: sharedWith,
      createdAt: Timestamp.now(),
      tags: tags,
    );

    // Add to Firestore
    final docRef = await _firestore.collection(_collectionPath).add(route.toMap());

    return docRef.id;
  } catch (e) {
    print('Error creating route: $e');
    rethrow;
  }
}