ObjectBox
This commit is contained in:
1 parent
e548f62bde
commit
f8317be627
60 files changed
+2367
-15049
No files matched your search
+52
-23
@@ -1,41 +1,70 @@
|
||||
import 'dart:convert';
|
||||
import 'package:dart_mq/dart_mq.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:objectbox/objectbox.dart';
|
||||
import 'package:stadtbote/model/job_tour.dart';
|
||||
import 'package:stadtbote/model/tour_position.dart';
|
||||
import 'package:stadtbote/model/tour_task.dart';
|
||||
|
||||
part 'job.g.dart';
|
||||
|
||||
@collection
|
||||
@JsonSerializable()
|
||||
@Entity()
|
||||
class Job with ProducerMixin {
|
||||
late Id id;
|
||||
@JsonKey(name: 'ver')
|
||||
@Id()
|
||||
int id = 0;
|
||||
|
||||
late String ver;
|
||||
@JsonKey(name: 'state')
|
||||
late int state;
|
||||
@JsonKey(name: 'cr_filter')
|
||||
late String? crFilter;
|
||||
@JsonKey(name: 'ordertime')
|
||||
String? crFilter;
|
||||
late int ordertime;
|
||||
@JsonKey(name: 'offs_warn')
|
||||
late int offsWarn;
|
||||
@JsonKey(name: 'global')
|
||||
late bool global;
|
||||
@JsonKey(name: 'vht_id')
|
||||
late int vhtId;
|
||||
@JsonKey(name: 'rem')
|
||||
late String rem;
|
||||
@JsonKey(name: 'delayOrderTime')
|
||||
late int delayOrderTime;
|
||||
@JsonKey(name: 'tours')
|
||||
late List<JobTour> tours;
|
||||
|
||||
// Store tours as JSON string for ObjectBox
|
||||
String toursJson = '[]';
|
||||
|
||||
@Transient()
|
||||
List<JobTour> get tours {
|
||||
final List<dynamic> decoded = jsonDecode(toursJson);
|
||||
return decoded.map((e) => JobTour.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
|
||||
set tours(List<JobTour> value) {
|
||||
toursJson = jsonEncode(value.map((e) => e.toJson()).toList());
|
||||
}
|
||||
|
||||
Job();
|
||||
|
||||
factory Job.fromJson(Map<String, dynamic> json) => _$JobFromJson(json);
|
||||
factory Job.fromJson(Map<String, dynamic> json) {
|
||||
final job = Job();
|
||||
job.id = json['id'] as int? ?? 0;
|
||||
job.ver = json['ver'] as String;
|
||||
job.state = json['state'] as int;
|
||||
job.crFilter = json['cr_filter'] as String?;
|
||||
job.ordertime = json['ordertime'] as int;
|
||||
job.offsWarn = json['offs_warn'] as int;
|
||||
job.global = json['global'] as bool;
|
||||
job.vhtId = json['vht_id'] as int;
|
||||
job.rem = json['rem'] as String;
|
||||
job.delayOrderTime = json['delayOrderTime'] as int;
|
||||
job.tours = (json['tours'] as List<dynamic>)
|
||||
.map((e) => JobTour.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
return job;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => _$JobToJson(this);
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'ver': ver,
|
||||
'state': state,
|
||||
'cr_filter': crFilter,
|
||||
'ordertime': ordertime,
|
||||
'offs_warn': offsWarn,
|
||||
'global': global,
|
||||
'vht_id': vhtId,
|
||||
'rem': rem,
|
||||
'delayOrderTime': delayOrderTime,
|
||||
'tours': tours.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user