mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 01:06:44 +00:00
Make job status an enum
This commit is contained in:
parent
d9b82b1250
commit
89c907b109
|
@ -30,14 +30,14 @@ class ServerJob {
|
|||
name: serverJob.name,
|
||||
progress: serverJob.progress,
|
||||
result: serverJob.result,
|
||||
status: serverJob.status,
|
||||
status: JobStatusEnum.fromString(serverJob.status),
|
||||
statusText: serverJob.statusText,
|
||||
uid: serverJob.uid,
|
||||
updatedAt: serverJob.updatedAt,
|
||||
);
|
||||
final String name;
|
||||
final String description;
|
||||
final String status;
|
||||
final JobStatusEnum status;
|
||||
final String uid;
|
||||
final DateTime updatedAt;
|
||||
final DateTime createdAt;
|
||||
|
@ -48,3 +48,29 @@ class ServerJob {
|
|||
final String? statusText;
|
||||
final DateTime? finishedAt;
|
||||
}
|
||||
|
||||
enum JobStatusEnum {
|
||||
@JsonValue('CREATED')
|
||||
created,
|
||||
@JsonValue('RUNNING')
|
||||
running,
|
||||
@JsonValue('FINISHED')
|
||||
finished,
|
||||
@JsonValue('ERROR')
|
||||
error;
|
||||
|
||||
factory JobStatusEnum.fromString(final String status) {
|
||||
switch (status) {
|
||||
case 'CREATED':
|
||||
return created;
|
||||
case 'RUNNING':
|
||||
return running;
|
||||
case 'FINISHED':
|
||||
return finished;
|
||||
case 'ERROR':
|
||||
return error;
|
||||
default:
|
||||
throw Exception('Unknown status: $status');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ part of 'server_job.dart';
|
|||
ServerJob _$ServerJobFromJson(Map<String, dynamic> json) => ServerJob(
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
status: json['status'] as String,
|
||||
status: $enumDecode(_$JobStatusEnumEnumMap, json['status']),
|
||||
uid: json['uid'] as String,
|
||||
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
|
@ -25,7 +25,7 @@ ServerJob _$ServerJobFromJson(Map<String, dynamic> json) => ServerJob(
|
|||
Map<String, dynamic> _$ServerJobToJson(ServerJob instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'description': instance.description,
|
||||
'status': instance.status,
|
||||
'status': _$JobStatusEnumEnumMap[instance.status]!,
|
||||
'uid': instance.uid,
|
||||
'updatedAt': instance.updatedAt.toIso8601String(),
|
||||
'createdAt': instance.createdAt.toIso8601String(),
|
||||
|
@ -35,3 +35,10 @@ Map<String, dynamic> _$ServerJobToJson(ServerJob instance) => <String, dynamic>{
|
|||
'statusText': instance.statusText,
|
||||
'finishedAt': instance.finishedAt?.toIso8601String(),
|
||||
};
|
||||
|
||||
const _$JobStatusEnumEnumMap = {
|
||||
JobStatusEnum.created: 'CREATED',
|
||||
JobStatusEnum.running: 'RUNNING',
|
||||
JobStatusEnum.finished: 'FINISHED',
|
||||
JobStatusEnum.error: 'ERROR',
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue