Initial commit — DLS lab-app Flutter project
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import 'package:pocketbase/pocketbase.dart';
|
||||
import '../../../core/api/pocketbase_client.dart';
|
||||
import '../../../models/connection.dart';
|
||||
|
||||
class ClinicConnectionsRepository {
|
||||
ClinicConnectionsRepository._();
|
||||
static final instance = ClinicConnectionsRepository._();
|
||||
|
||||
PocketBase get _pb => PocketBaseClient.instance.pb;
|
||||
|
||||
Future<List<Connection>> listConnections(String clinicTenantId) async {
|
||||
final result = await _pb.collection('connections').getList(
|
||||
filter: 'clinic_tenant_id = "$clinicTenantId"',
|
||||
expand: 'lab_tenant_id,clinic_tenant_id',
|
||||
perPage: 100,
|
||||
);
|
||||
return (result.items.map((r) => Connection.fromJson(r.toJson())).toList()
|
||||
..sort((a, b) => (b.dateCreated ?? '').compareTo(a.dateCreated ?? '')));
|
||||
}
|
||||
|
||||
Future<Connection> requestConnection({
|
||||
required String clinicTenantId,
|
||||
required String labTenantId,
|
||||
}) async {
|
||||
final record = await _pb.collection('connections').create(body: {
|
||||
'clinic_tenant_id': clinicTenantId,
|
||||
'lab_tenant_id': labTenantId,
|
||||
'status': 'pending',
|
||||
});
|
||||
return Connection.fromJson(record.toJson());
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> searchLabs(String query) async {
|
||||
final result = await _pb.collection('tenants').getList(
|
||||
filter: 'kind = "lab" && company_name ~ "$query"',
|
||||
perPage: 20,
|
||||
);
|
||||
return result.items.map((r) => r.toJson()).toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user