sistemato assets, finito creazione company, inizio lavoro store

This commit is contained in:
2026-04-09 11:30:57 +02:00
parent 0033a0aee6
commit 510d8e6f15
19 changed files with 524 additions and 231 deletions

View File

@@ -0,0 +1,36 @@
import 'package:get_it/get_it.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import '../models/store_model.dart';
class StoreRepository {
final SupabaseClient _client = 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());
} on PostgrestException catch (e) {
// Intercettiamo errori specifici del database
throw e.message;
} catch (e) {
throw 'Errore imprevisto durante la creazione del negozio: $e';
}
}
/// Recupera tutti i negozi di una determinata compagnia
Future<List<StoreModel>> getStoresByCompany(String companyId) async {
try {
final response = await _client
.from('store')
.select()
.eq('company_id', companyId)
.order('created_at');
return (response as List)
.map((json) => StoreModel.fromJson(json))
.toList();
} catch (e) {
throw 'Errore nel recupero dei negozi';
}
}
}