Refactor provider and store models to use fromMap method; update associated stores handling in UI
This commit is contained in:
@@ -3,12 +3,12 @@ import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import '../models/store_model.dart';
|
||||
|
||||
class StoreRepository {
|
||||
final SupabaseClient _client = GetIt.I.get<SupabaseClient>();
|
||||
final SupabaseClient _supabase = GetIt.I.get<SupabaseClient>();
|
||||
|
||||
/// Crea un nuovo negozio associato alla compagnia dell'utente
|
||||
Future<void> createStore(StoreModel store) async {
|
||||
try {
|
||||
await _client.from('store').insert(store.toJson());
|
||||
await _supabase.from('store').insert(store.toMap());
|
||||
} on PostgrestException catch (e) {
|
||||
// Intercettiamo errori specifici del database
|
||||
throw e.message;
|
||||
@@ -18,19 +18,21 @@ class StoreRepository {
|
||||
}
|
||||
|
||||
/// Recupera tutti i negozi di una determinata compagnia
|
||||
Future<List<StoreModel>> getStoresByCompany(String companyId) async {
|
||||
Future<List<StoreModel>> fetchAllCompanyStores(String companyId) async {
|
||||
try {
|
||||
final response = await _client
|
||||
final response = await _supabase
|
||||
.from('store')
|
||||
.select()
|
||||
.select('''
|
||||
*,
|
||||
providers_count:providers_in_stores(count),
|
||||
staff_members_count:staff_in_stores(count)
|
||||
''')
|
||||
.eq('company_id', companyId)
|
||||
.order('created_at');
|
||||
.order('nome');
|
||||
|
||||
return (response as List)
|
||||
.map((json) => StoreModel.fromJson(json))
|
||||
.toList();
|
||||
return (response as List).map((m) => StoreModel.fromMap(m)).toList();
|
||||
} catch (e) {
|
||||
throw 'Errore nel recupero dei negozi';
|
||||
throw 'Errore nel recupero dei negozi: $e';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user