a
This commit is contained in:
@@ -15,7 +15,6 @@ enum Bucket {
|
|||||||
|
|
||||||
class AttachmentsRepository {
|
class AttachmentsRepository {
|
||||||
final _supabase = Supabase.instance.client;
|
final _supabase = Supabase.instance.client;
|
||||||
static const String _tableName = Tables.attachments;
|
|
||||||
|
|
||||||
/// Scarica i byte di un file direttamente da Supabase Storage
|
/// Scarica i byte di un file direttamente da Supabase Storage
|
||||||
Future<Uint8List> downloadAttachmentBytes({
|
Future<Uint8List> downloadAttachmentBytes({
|
||||||
@@ -56,7 +55,7 @@ class AttachmentsRepository {
|
|||||||
final columnName = _getColumnNameForParent(parentType);
|
final columnName = _getColumnNameForParent(parentType);
|
||||||
|
|
||||||
return _supabase
|
return _supabase
|
||||||
.from(_tableName)
|
.from(Tables.attachments)
|
||||||
.stream(primaryKey: ['id'])
|
.stream(primaryKey: ['id'])
|
||||||
.eq(columnName, parentId)
|
.eq(columnName, parentId)
|
||||||
.map(
|
.map(
|
||||||
@@ -141,7 +140,7 @@ class AttachmentsRepository {
|
|||||||
insertData[columnName] = parentId;
|
insertData[columnName] = parentId;
|
||||||
|
|
||||||
// 6. Salviamo su Postgres
|
// 6. Salviamo su Postgres
|
||||||
await _supabase.from(_tableName).insert(insertData);
|
await _supabase.from(Tables.attachments).insert(insertData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception("Errore caricamento: $e");
|
throw Exception("Errore caricamento: $e");
|
||||||
}
|
}
|
||||||
@@ -179,12 +178,12 @@ class AttachmentsRepository {
|
|||||||
// A. Ci sono ancora altre entità che usano questo file!
|
// A. Ci sono ancora altre entità che usano questo file!
|
||||||
// Scolleghiamolo SOLO dal contesto attuale mettendo a NULL la sua colonna
|
// Scolleghiamolo SOLO dal contesto attuale mettendo a NULL la sua colonna
|
||||||
await _supabase
|
await _supabase
|
||||||
.from(_tableName)
|
.from(Tables.attachments)
|
||||||
.update({currentContextType.dbColumn: null})
|
.update({currentContextType.dbColumn: null})
|
||||||
.eq('id', file.id!);
|
.eq('id', file.id!);
|
||||||
} else {
|
} else {
|
||||||
// B. Nessuno usa più questo file! ELIMINAZIONE FISICA TOTALE.
|
// 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) {
|
if (file.storagePath != null) {
|
||||||
await _supabase.storage.from(bucket.value).remove([
|
await _supabase.storage.from(bucket.value).remove([
|
||||||
@@ -202,7 +201,7 @@ class AttachmentsRepository {
|
|||||||
Future<void> renameAttachment(String fileId, String newName) async {
|
Future<void> renameAttachment(String fileId, String newName) async {
|
||||||
try {
|
try {
|
||||||
await _supabase
|
await _supabase
|
||||||
.from(_tableName)
|
.from(Tables.attachments)
|
||||||
.update({'name': newName})
|
.update({'name': newName})
|
||||||
.eq('id', fileId);
|
.eq('id', fileId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -219,7 +218,7 @@ class AttachmentsRepository {
|
|||||||
try {
|
try {
|
||||||
// Facciamo un semplice UPDATE aggiungendo l'ID nella colonna giusta
|
// Facciamo un semplice UPDATE aggiungendo l'ID nella colonna giusta
|
||||||
await _supabase
|
await _supabase
|
||||||
.from(_tableName)
|
.from(Tables.attachments)
|
||||||
.update({targetType.dbColumn: targetId})
|
.update({targetType.dbColumn: targetId})
|
||||||
.eq('id', fileId);
|
.eq('id', fileId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -105,7 +105,11 @@ class DashboardNotesWidget extends StatelessWidget {
|
|||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Vai al form di dettaglio passando l'ID o l'oggetto
|
// 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(
|
child: Container(
|
||||||
width: 140,
|
width: 140,
|
||||||
|
|||||||
Reference in New Issue
Block a user