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,38 @@
import 'package:supabase_flutter/supabase_flutter.dart';
import '../models/company_model.dart';
class CompanyRepository {
final SupabaseClient _supabase = Supabase.instance.client;
Future<CompanyModel> createCompany(CompanyModel company) async {
try {
// .select().single() trasforma la risposta nell'oggetto appena inserito
final response = await _supabase
.from('company')
.insert(company.toJson())
.select()
.single();
return CompanyModel.fromJson(response);
} on PostgrestException catch (e) {
throw e.message;
} catch (e) {
throw 'Errore imprevisto durante la creazione dell\'azienda';
}
}
Future<CompanyModel?> getCompany() async {
try {
final userId = _supabase.auth.currentUser?.id;
final response = await _supabase
.from('company')
.select()
.eq('user_id', userId as Object)
.maybeSingle();
return response != null ? CompanyModel.fromJson(response) : null;
} catch (e) {
return null;
}
}
}