ripristinato codice stabile da branch staff
This commit is contained in:
36
lib/features/master_data/store/data/store_repository.dart
Normal file
36
lib/features/master_data/store/data/store_repository.dart
Normal 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user