refactor nomi tabelle

This commit is contained in:
2026-05-20 11:03:33 +02:00
parent f190ad9353
commit c85f4b086e
24 changed files with 217 additions and 159 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flux/core/blocs/session/session_cubit.dart';
import 'package:flux/core/enums_and_consts/consts.dart';
import 'package:get_it/get_it.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import '../models/provider_model.dart';
@@ -11,12 +12,12 @@ class ProviderRepository {
// 1. Carica i provider abilitati per uno specifico Store
Future<List<ProviderModel>> getProvidersByStore(String storeId) async {
final response = await _supabase
.from('providers_in_stores')
.from(Tables.providersInStores)
.select('''
provider_id,
provider:provider (
provider:${Tables.providers} (
*,
provider_locations (*)
${Tables.providerLocations} (*)
)
''')
.eq('store_id', storeId)
@@ -31,8 +32,8 @@ class ProviderRepository {
// 2. Carica TUTTI i provider della Company (per la gestione anagrafica)
Future<List<ProviderModel>> getAllCompanyProviders() async {
final response = await _supabase
.from('provider')
.select('*, provider_locations (*)')
.from(Tables.providers)
.select('*, ${Tables.providerLocations} (*)')
.order('name');
return (response as List)
@@ -48,7 +49,7 @@ class ProviderRepository {
// A. Salva/Aggiorna il Provider principale
final providerWithCompany = provider.copyWith(companyId: _companyId);
final savedRow = await _supabase
.from('provider')
.from(Tables.providers)
.upsert(providerWithCompany.toMap())
.select()
.single();
@@ -58,7 +59,7 @@ class ProviderRepository {
// B. Sincronizza gli Store (Cancelliamo i vecchi e mettiamo i nuovi per semplicità)
// In un'app ad alto traffico faremmo un confronto, qui l'upsert totale è più veloce da scrivere.
await _supabase
.from('providers_in_stores')
.from(Tables.providersInStores)
.delete()
.eq('provider_id', savedProvider.id!);
@@ -67,7 +68,7 @@ class ProviderRepository {
.map((sId) => {'provider_id': savedProvider.id, 'store_id': sId})
.toList();
await _supabase.from('providers_in_stores').insert(storeLinks);
await _supabase.from(Tables.providersInStores).insert(storeLinks);
}
return savedProvider;
@@ -75,10 +76,13 @@ class ProviderRepository {
// 4. Gestione Sedi (Locations)
Future<void> saveLocation(ProviderLocationModel location) async {
await _supabase.from('provider_locations').upsert(location.toMap());
await _supabase.from(Tables.providerLocations).upsert(location.toMap());
}
Future<void> deleteLocation(String locationId) async {
await _supabase.from('provider_locations').delete().eq('id', locationId);
await _supabase
.from(Tables.providerLocations)
.delete()
.eq('id', locationId);
}
}