a
This commit is contained in:
@@ -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<Uint8List> 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<void> 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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user