Offline Support
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart';
|
||||
import 'package:brick_sqlite/brick_sqlite.dart';
|
||||
import 'package:brick_supabase/brick_supabase.dart';
|
||||
|
||||
import '../utils/app_time.dart';
|
||||
|
||||
@ConnectOfflineFirstWithSupabase(
|
||||
supabaseConfig: SupabaseSerializable(tableName: 'duty_schedules'),
|
||||
)
|
||||
class DutySchedule extends OfflineFirstWithSupabaseModel {
|
||||
final String id;
|
||||
final String userId;
|
||||
final String shiftType;
|
||||
final DateTime startTime;
|
||||
final DateTime endTime;
|
||||
final String status;
|
||||
final DateTime createdAt;
|
||||
final DateTime? checkInAt;
|
||||
|
||||
// PostGIS geometry — Brick cannot serialize Object; ignored in local cache.
|
||||
@Supabase(ignore: true)
|
||||
@Sqlite(ignore: true)
|
||||
final Object? checkInLocation;
|
||||
|
||||
final List<String> relieverIds;
|
||||
final String? swapRequestId;
|
||||
|
||||
DutySchedule({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.shiftType,
|
||||
required this.startTime,
|
||||
required this.endTime,
|
||||
required this.status,
|
||||
required this.createdAt,
|
||||
this.checkInAt,
|
||||
this.checkInLocation,
|
||||
required this.relieverIds,
|
||||
this.swapRequestId,
|
||||
});
|
||||
|
||||
factory DutySchedule.fromMap(Map<String, dynamic> map) {
|
||||
final relieversRaw = map['reliever_ids'];
|
||||
final relievers = relieversRaw is List
|
||||
? relieversRaw
|
||||
.where((e) => e != null)
|
||||
.map((entry) => entry.toString())
|
||||
.where((s) => s.isNotEmpty)
|
||||
.toList()
|
||||
: <String>[];
|
||||
return DutySchedule(
|
||||
id: map['id'] as String,
|
||||
userId: map['user_id'] as String,
|
||||
shiftType: map['shift_type'] as String? ?? 'normal',
|
||||
startTime: AppTime.parse(map['start_time'] as String),
|
||||
endTime: AppTime.parse(map['end_time'] as String),
|
||||
status: map['status'] as String? ?? 'scheduled',
|
||||
createdAt: AppTime.parse(map['created_at'] as String),
|
||||
checkInAt: map['check_in_at'] == null
|
||||
? null
|
||||
: AppTime.parse(map['check_in_at'] as String),
|
||||
checkInLocation: map['check_in_location'],
|
||||
relieverIds: relievers,
|
||||
swapRequestId: map['swap_request_id'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user