KonectarApp/lib/contacts_module/model_class/section.dart

104 lines
2.5 KiB
Dart
Raw Permalink Normal View History

2024-10-08 12:01:59 +00:00
class Publication {
int id;
int userId;
String articleTitle;
String journalName;
DateTime date;
String author;
DateTime? createdAt;
DateTime? updatedAt;
Publication({
required this.id,
required this.userId,
required this.articleTitle,
required this.journalName,
required this.date,
required this.author,
this.createdAt,
this.updatedAt,
});
// Convert a Publication to a Map
Map<String, dynamic> toMap() {
return {
'id': id,
'user_id': userId,
'article_title': articleTitle,
'journal_name': journalName,
'date': date.toIso8601String(),
'author': author,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
};
}
// Create a Publication from a Map
factory Publication.fromMap(Map<String, dynamic> map) {
return Publication(
id: map['id'],
userId: map['user_id'],
articleTitle: map['article_title'],
journalName: map['journal_name'],
date: DateTime.parse(map['date']),
author: map['author'],
createdAt:
map['created_at'] != null ? DateTime.parse(map['created_at']) : null,
updatedAt:
map['updated_at'] != null ? DateTime.parse(map['updated_at']) : null,
);
}
}
class Affiliation {
int id;
int userId;
String articleTitle;
String journalName;
DateTime date;
String author;
DateTime? createdAt;
DateTime? updatedAt;
Affiliation({
required this.id,
required this.userId,
required this.articleTitle,
required this.journalName,
required this.date,
required this.author,
this.createdAt,
this.updatedAt,
});
// Convert an Affiliation to a Map
Map<String, dynamic> toMap() {
return {
'id': id,
'user_id': userId,
'article_title': articleTitle,
'journal_name': journalName,
'date': date.toIso8601String(),
'author': author,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
};
}
// Create an Affiliation from a Map
factory Affiliation.fromMap(Map<String, dynamic> map) {
return Affiliation(
id: map['id'],
userId: map['user_id'],
articleTitle: map['article_title'],
journalName: map['journal_name'],
date: DateTime.parse(map['date']),
author: map['author'],
createdAt:
map['created_at'] != null ? DateTime.parse(map['created_at']) : null,
updatedAt:
map['updated_at'] != null ? DateTime.parse(map['updated_at']) : null,
);
}
}