44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
// * Shared methods for deleting templates from the database
|
|
// * Provides functionality for:
|
|
// * - Deleting all templates of a specific type
|
|
// * - Deleting a single template by ID
|
|
|
|
import 'package:fforte/enums/databases.dart';
|
|
import 'package:fforte/interfaces/i_db.dart';
|
|
import 'package:fforte/methods/excursion_db_helper.dart';
|
|
import 'package:fforte/methods/place_db_helper.dart';
|
|
|
|
/// Helper class for deleting templates from the database
|
|
class DeleteTemplates {
|
|
/// Delete a single template by ID
|
|
/// @param dbType The type of database (place/excursion)
|
|
/// @param id ID of the template to delete
|
|
static Future<void> deleteSingle(DatabasesEnum dbType, String id) async {
|
|
// Select appropriate database helper
|
|
IDb? db;
|
|
|
|
if (dbType == DatabasesEnum.place) {
|
|
db = PlaceDBHelper();
|
|
} else if (dbType == DatabasesEnum.excursion) {
|
|
db = ExcursionDBHelper();
|
|
}
|
|
|
|
await db!.deleteTemplateById(id);
|
|
}
|
|
|
|
/// Delete all templates of a specific type
|
|
/// @param dbType The type of database (place/excursion)
|
|
static Future<void> deleteAll(DatabasesEnum dbType) async {
|
|
// Select appropriate database helper
|
|
IDb? db;
|
|
|
|
if (dbType == DatabasesEnum.place) {
|
|
db = PlaceDBHelper();
|
|
} else if (dbType == DatabasesEnum.excursion) {
|
|
db = ExcursionDBHelper();
|
|
}
|
|
|
|
await db!.deleteAllMainEntries();
|
|
}
|
|
}
|