From b29850917846be083ae7f4b407a044ccfd16ade5 Mon Sep 17 00:00:00 2001 From: mark-cachy Date: Wed, 27 May 2026 19:38:59 +0200 Subject: [PATCH] a --- .../attachments/data/attachments_repository.dart | 13 ++++++------- lib/features/notes/ui/dashboard_notes_widget.dart | 6 +++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/features/attachments/data/attachments_repository.dart b/lib/features/attachments/data/attachments_repository.dart index 8c205cd..3b99f05 100644 --- a/lib/features/attachments/data/attachments_repository.dart +++ b/lib/features/attachments/data/attachments_repository.dart @@ -15,7 +15,6 @@ enum Bucket { class AttachmentsRepository { final _supabase = Supabase.instance.client; - static const String _tableName = Tables.attachments; /// Scarica i byte di un file direttamente da Supabase Storage Future downloadAttachmentBytes({ @@ -56,7 +55,7 @@ class AttachmentsRepository { final columnName = _getColumnNameForParent(parentType); return _supabase - .from(_tableName) + .from(Tables.attachments) .stream(primaryKey: ['id']) .eq(columnName, parentId) .map( @@ -141,7 +140,7 @@ class AttachmentsRepository { insertData[columnName] = parentId; // 6. Salviamo su Postgres - await _supabase.from(_tableName).insert(insertData); + await _supabase.from(Tables.attachments).insert(insertData); } catch (e) { throw Exception("Errore caricamento: $e"); } @@ -179,12 +178,12 @@ class AttachmentsRepository { // A. Ci sono ancora altre entità che usano questo file! // Scolleghiamolo SOLO dal contesto attuale mettendo a NULL la sua colonna await _supabase - .from(_tableName) + .from(Tables.attachments) .update({currentContextType.dbColumn: null}) .eq('id', file.id!); } else { // B. Nessuno usa più questo file! ELIMINAZIONE FISICA TOTALE. - await _supabase.from(_tableName).delete().eq('id', file.id!); + await _supabase.from(Tables.attachments).delete().eq('id', file.id!); if (file.storagePath != null) { await _supabase.storage.from(bucket.value).remove([ @@ -202,7 +201,7 @@ class AttachmentsRepository { Future renameAttachment(String fileId, String newName) async { try { await _supabase - .from(_tableName) + .from(Tables.attachments) .update({'name': newName}) .eq('id', fileId); } catch (e) { @@ -219,7 +218,7 @@ class AttachmentsRepository { try { // Facciamo un semplice UPDATE aggiungendo l'ID nella colonna giusta await _supabase - .from(_tableName) + .from(Tables.attachments) .update({targetType.dbColumn: targetId}) .eq('id', fileId); } catch (e) { diff --git a/lib/features/notes/ui/dashboard_notes_widget.dart b/lib/features/notes/ui/dashboard_notes_widget.dart index d707c66..788b592 100644 --- a/lib/features/notes/ui/dashboard_notes_widget.dart +++ b/lib/features/notes/ui/dashboard_notes_widget.dart @@ -105,7 +105,11 @@ class DashboardNotesWidget extends StatelessWidget { return GestureDetector( onTap: () { // Vai al form di dettaglio passando l'ID o l'oggetto - context.push('/notes/edit/${note.id}'); + context.pushNamed( + Routes.noteForm, + pathParameters: {'id': note.id!}, + extra: note, + ); }, child: Container( width: 140,