2024-08-26 17:37:23 +02:00
|
|
|
import 'package:oc_front/models/abstract.dart';
|
2024-08-30 12:52:32 +02:00
|
|
|
import 'package:oc_front/models/response.dart';
|
2024-08-26 17:37:23 +02:00
|
|
|
import 'package:oc_front/models/workflow.dart';
|
|
|
|
import 'package:oc_front/models/workspace.dart';
|
|
|
|
|
|
|
|
class SharedWorkspace extends SerializerDeserializer<SharedWorkspace> {
|
|
|
|
String? id;
|
|
|
|
String? name;
|
|
|
|
String? description;
|
|
|
|
String? creatorID;
|
|
|
|
String? version;
|
|
|
|
Map<String, dynamic> attributes = {};
|
|
|
|
List<Workspace> workspaces = [];
|
|
|
|
List<Workflow> workflows = [];
|
|
|
|
List<Peer> peers = [];
|
|
|
|
List<Rule> rules = [];
|
|
|
|
|
|
|
|
SharedWorkspace(
|
|
|
|
{this.id,
|
|
|
|
this.name,
|
|
|
|
this.description,
|
|
|
|
this.creatorID,
|
|
|
|
this.version,
|
|
|
|
this.attributes = const {},
|
|
|
|
this.workspaces = const [],
|
|
|
|
this.workflows = const [],
|
|
|
|
this.peers = const [],
|
|
|
|
this.rules = const []});
|
|
|
|
|
|
|
|
@override
|
|
|
|
deserialize(dynamic json) {
|
|
|
|
try { json = json as Map<String, dynamic>;
|
|
|
|
} catch (e) { return SharedWorkspace(); }
|
|
|
|
return SharedWorkspace(
|
|
|
|
id: json.containsKey("id") ? json["id"] : null,
|
|
|
|
name: json.containsKey("name") ? json["name"] : null,
|
|
|
|
description: json.containsKey("description") ? json["description"] : null,
|
2024-08-30 12:52:32 +02:00
|
|
|
creatorID: json.containsKey("peer_id") ? json["peer_id"] : null,
|
2024-08-26 17:37:23 +02:00
|
|
|
version: json.containsKey("version") ? json["version"] : null,
|
|
|
|
attributes: json.containsKey("attributes") ? json["attributes"] : {},
|
|
|
|
workspaces: json.containsKey("shared_workspaces") ? fromListJson(json["shared_workspaces"], Workspace()) : [],
|
|
|
|
workflows: json.containsKey("shared_workflows") ? fromListJson(json["shared_workflows"], Workflow()) : [],
|
|
|
|
peers: json.containsKey("shared_peers") ? fromListJson(json["shared_peers"], Peer()) : [],
|
|
|
|
rules: json.containsKey("shared_rules") ? fromListJson(json["shared_rules"], Rule()) : [],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> serialize() => {
|
|
|
|
"id": id,
|
|
|
|
"name": name,
|
|
|
|
"description": description,
|
|
|
|
"creator_id": creatorID,
|
|
|
|
"version": version,
|
|
|
|
"attributes": attributes,
|
|
|
|
"workspaces": workspaces.map((e) => e.id).toList(),
|
|
|
|
"workflows": workflows.map((e) => e.id).toList(),
|
|
|
|
"peers": peers.map((e) => e.id).toList(),
|
|
|
|
"rules": rules.map((e) => e.id).toList(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class Rule extends SerializerDeserializer<Rule> {
|
|
|
|
String? id;
|
|
|
|
String? name;
|
|
|
|
String? description;
|
|
|
|
|
|
|
|
Rule(
|
|
|
|
{this.id,
|
|
|
|
this.name,
|
|
|
|
this.description,});
|
|
|
|
|
|
|
|
@override
|
|
|
|
deserialize(dynamic json) {
|
|
|
|
try { json = json as Map<String, dynamic>;
|
|
|
|
} catch (e) { return Rule(); }
|
|
|
|
return Rule(
|
|
|
|
id: json.containsKey("id") ? json["id"] : null,
|
|
|
|
name: json.containsKey("name") ? json["name"] : null,
|
|
|
|
description: json.containsKey("description") ? json["description"] : null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> serialize() => {
|
|
|
|
"id": id,
|
|
|
|
"name": name,
|
|
|
|
"description": description,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-08-30 12:52:32 +02:00
|
|
|
class Peer extends SerializerDeserializer<Peer> implements ShallowData {
|
2024-08-26 17:37:23 +02:00
|
|
|
String? id;
|
|
|
|
String? name;
|
|
|
|
|
|
|
|
Peer(
|
|
|
|
{this.id,
|
|
|
|
this.name,});
|
2024-08-30 12:52:32 +02:00
|
|
|
|
|
|
|
@override String getID() => id ?? "";
|
|
|
|
@override String getName() => name ?? "";
|
2024-08-26 17:37:23 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
deserialize(dynamic json) {
|
|
|
|
try { json = json as Map<String, dynamic>;
|
|
|
|
} catch (e) { return Peer(); }
|
|
|
|
return Peer(
|
|
|
|
id: json.containsKey("id") ? json["id"] : null,
|
|
|
|
name: json.containsKey("name") ? json["name"] : null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
@override
|
|
|
|
Map<String, dynamic> serialize() => {
|
|
|
|
"id": id,
|
|
|
|
"name": name,
|
|
|
|
};
|
|
|
|
}
|