63 lines
No EOL
1.6 KiB
Dart
63 lines
No EOL
1.6 KiB
Dart
// Version: 1.0 - Employee モデル定義(簡易 POJO)
|
||
class Employee {
|
||
final int? id;
|
||
final String name;
|
||
final String email;
|
||
final String tel;
|
||
final String department;
|
||
final String role;
|
||
final DateTime createdAt;
|
||
|
||
Employee({
|
||
this.id,
|
||
required this.name,
|
||
required this.email,
|
||
required this.tel,
|
||
required this.department,
|
||
required this.role,
|
||
this.createdAt = DateTime.now(),
|
||
});
|
||
|
||
// JSON シリアライゼーション(簡素版)
|
||
Map<String, dynamic> toJson() => {
|
||
'id': id,
|
||
'name': name,
|
||
'email': email,
|
||
'tel': tel,
|
||
'department': department,
|
||
'role': role,
|
||
'created_at': createdAt.toIso8601String(),
|
||
};
|
||
|
||
// JSON デシリアライゼーション(簡素版)
|
||
factory Employee.fromJson(Map<String, dynamic> json) => Employee(
|
||
id: json['id'] as int?,
|
||
name: json['name'] as String,
|
||
email: json['email'] as String,
|
||
tel: json['tel'] as String,
|
||
department: json['department'] as String,
|
||
role: json['role'] as String,
|
||
);
|
||
|
||
// 深コピー用メソッド(編集時の使用)
|
||
Employee copyWith({
|
||
int? id,
|
||
String? name,
|
||
String? email,
|
||
String? tel,
|
||
String? department,
|
||
String? role,
|
||
DateTime? createdAt,
|
||
}) => Employee(
|
||
id: id ?? this.id,
|
||
name: name ?? this.name,
|
||
email: email ?? this.email,
|
||
tel: tel ?? this.tel,
|
||
department: department ?? this.department,
|
||
role: role ?? this.role,
|
||
createdAt: createdAt ?? this.createdAt,
|
||
);
|
||
|
||
@override
|
||
String toString() => 'Employee(id: $id, name: $name)';
|
||
} |