136 lines
3.5 KiB
Dart
136 lines
3.5 KiB
Dart
|
import 'dart:convert';
|
||
|
|
||
|
import 'package:flutter_passvault/modelclasses/jsomdata.dart';
|
||
|
|
||
|
MyCredentialList myCredentialListFromJson(String str) =>
|
||
|
MyCredentialList.fromJson(json.decode(str));
|
||
|
|
||
|
String myCredentialListToJson(MyCredentialList data) =>
|
||
|
json.encode(data.toJson());
|
||
|
|
||
|
class MyCredentialList {
|
||
|
bool success;
|
||
|
String message;
|
||
|
List<CredentialList> data;
|
||
|
|
||
|
MyCredentialList({
|
||
|
required this.success,
|
||
|
required this.message,
|
||
|
required this.data,
|
||
|
});
|
||
|
|
||
|
factory MyCredentialList.fromJson(Map<String, dynamic> json) =>
|
||
|
MyCredentialList(
|
||
|
success: json["success"],
|
||
|
message: json["message"],
|
||
|
data: List<CredentialList>.from(
|
||
|
json["data"].map((x) => CredentialList.fromJson(x))),
|
||
|
);
|
||
|
|
||
|
Map<String, dynamic> toJson() => {
|
||
|
"success": success,
|
||
|
"message": message,
|
||
|
"data": List<dynamic>.from(data.map((x) => x.toJson())),
|
||
|
};
|
||
|
}
|
||
|
|
||
|
class CredentialList implements JsonData {
|
||
|
@override
|
||
|
int id;
|
||
|
@override
|
||
|
String name;
|
||
|
@override
|
||
|
String username;
|
||
|
@override
|
||
|
String password;
|
||
|
@override
|
||
|
late String detail;
|
||
|
@override
|
||
|
late int createdBy;
|
||
|
@override
|
||
|
late int modifiedBy;
|
||
|
@override
|
||
|
late DateTime createdAt;
|
||
|
@override
|
||
|
late DateTime updatedAt;
|
||
|
late Pivot? pivot;
|
||
|
|
||
|
CredentialList({
|
||
|
required this.id,
|
||
|
required this.name,
|
||
|
required this.username,
|
||
|
required this.password,
|
||
|
detail,
|
||
|
createdBy,
|
||
|
modifiedBy,
|
||
|
createdAt,
|
||
|
updatedAt,
|
||
|
this.pivot,
|
||
|
}) {
|
||
|
this.detail = detail ?? '';
|
||
|
this.createdBy = createdBy ?? 0;
|
||
|
this.modifiedBy = modifiedBy ?? 0;
|
||
|
this.createdAt = createdAt ?? DateTime.now();
|
||
|
this.updatedAt = updatedAt ?? DateTime.now(); // Initialize pivot normally
|
||
|
}
|
||
|
|
||
|
factory CredentialList.fromJson(Map<String, dynamic> json) => CredentialList(
|
||
|
id: json["id"],
|
||
|
name: json["name"],
|
||
|
username: json["username"],
|
||
|
password: json["password"],
|
||
|
detail: json["detail"],
|
||
|
createdBy: json["created_by"],
|
||
|
modifiedBy: json["modified_by"],
|
||
|
createdAt: DateTime.parse(json["created_at"]),
|
||
|
updatedAt: DateTime.parse(json["updated_at"]),
|
||
|
pivot: Pivot.fromJson(json["pivot"]),
|
||
|
);
|
||
|
|
||
|
Map<String, dynamic> toJson() => {
|
||
|
"id": id,
|
||
|
"name": name,
|
||
|
"username": username,
|
||
|
"password": password,
|
||
|
"detail": detail,
|
||
|
"created_by": createdBy,
|
||
|
"modified_by": modifiedBy,
|
||
|
"created_at": createdAt.toIso8601String(),
|
||
|
"updated_at": updatedAt.toIso8601String(),
|
||
|
"pivot": pivot?.toJson(),
|
||
|
};
|
||
|
|
||
|
@override
|
||
|
String toString() {
|
||
|
return 'MyCredentialList{id: $id, name: $name, username: $username, password: $password,detail: $detail,created_by: $createdBy,modified_by: $modifiedBy,created_at: $createdAt.toIso8601String(), updated_at: $updatedAt.toIso8601String(),pivot: $pivot?.toJson(),}';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class Pivot {
|
||
|
int userId;
|
||
|
int credId;
|
||
|
DateTime createdAt;
|
||
|
DateTime updatedAt;
|
||
|
|
||
|
Pivot({
|
||
|
required this.userId,
|
||
|
required this.credId,
|
||
|
required this.createdAt,
|
||
|
required this.updatedAt,
|
||
|
});
|
||
|
|
||
|
factory Pivot.fromJson(Map<String, dynamic> json) => Pivot(
|
||
|
userId: json["user_id"],
|
||
|
credId: json["cred_id"],
|
||
|
createdAt: DateTime.parse(json["created_at"]),
|
||
|
updatedAt: DateTime.parse(json["updated_at"]),
|
||
|
);
|
||
|
|
||
|
Map<String, dynamic> toJson() => {
|
||
|
"user_id": userId,
|
||
|
"cred_id": credId,
|
||
|
"created_at": createdAt.toIso8601String(),
|
||
|
"updated_at": updatedAt.toIso8601String(),
|
||
|
};
|
||
|
}
|