Added Service
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../models/service.dart';
|
||||
import 'supabase_provider.dart';
|
||||
|
||||
final servicesProvider = StreamProvider<List<Service>>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
return client
|
||||
.from('services')
|
||||
.stream(primaryKey: ['id'])
|
||||
.order('name')
|
||||
.map((rows) => rows.map((r) => Service.fromMap(r)).toList());
|
||||
});
|
||||
|
||||
final servicesOnceProvider = FutureProvider<List<Service>>((ref) async {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
final rows = await client.from('services').select().order('name');
|
||||
return (rows as List<dynamic>)
|
||||
.map((r) => Service.fromMap(r as Map<String, dynamic>))
|
||||
.toList();
|
||||
});
|
||||
@@ -377,12 +377,20 @@ class OfficesController {
|
||||
|
||||
final SupabaseClient _client;
|
||||
|
||||
Future<void> createOffice({required String name}) async {
|
||||
await _client.from('offices').insert({'name': name});
|
||||
Future<void> createOffice({required String name, String? serviceId}) async {
|
||||
final payload = {'name': name};
|
||||
if (serviceId != null) payload['service_id'] = serviceId;
|
||||
await _client.from('offices').insert(payload);
|
||||
}
|
||||
|
||||
Future<void> updateOffice({required String id, required String name}) async {
|
||||
await _client.from('offices').update({'name': name}).eq('id', id);
|
||||
Future<void> updateOffice({
|
||||
required String id,
|
||||
required String name,
|
||||
String? serviceId,
|
||||
}) async {
|
||||
final payload = {'name': name};
|
||||
if (serviceId != null) payload['service_id'] = serviceId;
|
||||
await _client.from('offices').update(payload).eq('id', id);
|
||||
}
|
||||
|
||||
Future<void> deleteOffice({required String id}) async {
|
||||
|
||||
Reference in New Issue
Block a user