Files
finger_print_app/lib/data/dto/punishment_dto.dart

47 lines
1.2 KiB
Dart

class PunishmentDto {
final String id;
final DateTime date;
final double amount;
final String? reason;
final String? note;
final String employeeId;
PunishmentDto({
required this.id,
required this.date,
required this.amount,
this.reason,
this.note,
required this.employeeId,
});
factory PunishmentDto.fromJson(Map<String, dynamic> json) {
return PunishmentDto(
id: json['id']?.toString() ?? '',
date:
json['date'] != null ? DateTime.parse(json['date']) : DateTime.now(),
amount: (json['amount'] as num?)?.toDouble() ?? 0.0,
reason: json['reason'],
note: json['note'],
employeeId: json['employeeId']?.toString() ?? '',
);
}
}
class PunishmentListResponseDto {
final List<PunishmentDto> items;
PunishmentListResponseDto({required this.items});
factory PunishmentListResponseDto.fromJson(Map<String, dynamic> json) {
final data = json['data'];
if (data == null || data is! Map<String, dynamic>) {
return PunishmentListResponseDto(items: []);
}
final itemsJson = data['items'] as List? ?? [];
return PunishmentListResponseDto(
items: itemsJson.map((e) => PunishmentDto.fromJson(e)).toList(),
);
}
}