let AI comment everything because well... yeah...

This commit is contained in:
Nico
2025-06-06 21:00:32 +02:00
parent 9c84d0c375
commit cc110ac104
44 changed files with 1230 additions and 646 deletions

View File

@@ -1,40 +1,60 @@
// * Shared method for saving main entries to the database
// * Handles both place and excursion entries
// * Supports:
// * - Creating new entries
// * - Converting templates to entries
// * - Updating existing entries
// * - Marking entries as sent to server
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 saving main entries to the database
class SaveMainEntryMethod {
/// Save or update a main entry in the database
/// @param entryData Map containing the entry data
/// @param isTemplate Whether this is being converted from a template
/// @param dbType The type of database (place/excursion)
/// @param sent Whether the entry has been sent to the server
/// @return ID of the saved entry
static Future<int> saveEntry({
required Map<String, String> entryData,
required bool isTemplate,
required DatabasesEnum dbType,
bool sent = false,
}) async {
// Select appropriate database helper
IDb? placeDB;
if (dbType == DatabasesEnum.place) {
placeDB = PlaceDBHelper();
placeDB = PlaceDBHelper();
} else if (dbType == DatabasesEnum.excursion) {
placeDB = ExcursionDBHelper();
placeDB = ExcursionDBHelper();
}
// If converting from template, delete the template first
if (isTemplate) await placeDB!.deleteTemplateById(entryData["ID"]!);
// Handle new entry creation vs update
int entryId;
if (entryData["ID"] == "" || isTemplate) {
// Create new entry
entryData.remove("ID");
entryId = await placeDB!.addMainEntry(entryData);
// Commented out template deletion by CID
// await placeDB.deleteTemplateById(entryData["CID"]!);
} else {
// Update existing entry
entryId = await placeDB!.updateMainEntry(entryData);
}
// Update sent status if entry was sent to server
if (sent == true) {
placeDB.updateSent(entryId); // Update 'Sent' using the correct ID
placeDB.updateSent(entryId);
}
return entryId;
}
}