2022-08-24 05:35:49 +00:00
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
2022-09-08 19:58:45 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/server_api.graphql.dart';
|
2022-08-24 05:35:49 +00:00
|
|
|
|
|
|
|
part 'server_job.g.dart';
|
|
|
|
|
|
|
|
@JsonSerializable()
|
|
|
|
class ServerJob {
|
|
|
|
factory ServerJob.fromJson(final Map<String, dynamic> json) =>
|
|
|
|
_$ServerJobFromJson(json);
|
|
|
|
ServerJob({
|
|
|
|
required this.name,
|
|
|
|
required this.description,
|
|
|
|
required this.status,
|
|
|
|
required this.uid,
|
2023-06-29 09:53:13 +00:00
|
|
|
required this.typeId,
|
2022-08-24 05:35:49 +00:00
|
|
|
required this.updatedAt,
|
|
|
|
required this.createdAt,
|
2022-10-26 16:26:09 +00:00
|
|
|
this.error,
|
|
|
|
this.progress,
|
|
|
|
this.result,
|
|
|
|
this.statusText,
|
|
|
|
this.finishedAt,
|
2022-08-24 05:35:49 +00:00
|
|
|
});
|
|
|
|
|
2023-06-29 18:38:46 +00:00
|
|
|
ServerJob.fromGraphQL(final Fragment$basicApiJobsFields serverJob)
|
2022-09-08 19:58:45 +00:00
|
|
|
: this(
|
|
|
|
createdAt: serverJob.createdAt,
|
|
|
|
description: serverJob.description,
|
|
|
|
error: serverJob.error,
|
|
|
|
finishedAt: serverJob.finishedAt,
|
|
|
|
name: serverJob.name,
|
|
|
|
progress: serverJob.progress,
|
|
|
|
result: serverJob.result,
|
2022-09-18 16:29:06 +00:00
|
|
|
status: JobStatusEnum.fromString(serverJob.status),
|
2022-09-08 19:58:45 +00:00
|
|
|
statusText: serverJob.statusText,
|
|
|
|
uid: serverJob.uid,
|
2023-06-29 09:53:13 +00:00
|
|
|
typeId: serverJob.typeId,
|
2022-09-08 19:58:45 +00:00
|
|
|
updatedAt: serverJob.updatedAt,
|
|
|
|
);
|
2022-08-24 05:35:49 +00:00
|
|
|
final String name;
|
|
|
|
final String description;
|
2022-09-18 16:29:06 +00:00
|
|
|
final JobStatusEnum status;
|
2022-08-24 05:35:49 +00:00
|
|
|
final String uid;
|
2023-06-29 09:53:13 +00:00
|
|
|
final String typeId;
|
2022-09-08 19:58:45 +00:00
|
|
|
final DateTime updatedAt;
|
2022-08-24 05:35:49 +00:00
|
|
|
final DateTime createdAt;
|
|
|
|
|
|
|
|
final String? error;
|
|
|
|
final int? progress;
|
|
|
|
final String? result;
|
|
|
|
final String? statusText;
|
2022-09-08 19:58:45 +00:00
|
|
|
final DateTime? finishedAt;
|
2022-08-24 05:35:49 +00:00
|
|
|
}
|
2022-09-18 16:29:06 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|