63 lines
1.9 KiB
Dart
63 lines
1.9 KiB
Dart
|
|
part of '../customer_dtos.dart';
|
||
|
|
|
||
|
|
@freezed
|
||
|
|
class ListCustomerDto with _$ListCustomerDto {
|
||
|
|
const ListCustomerDto._();
|
||
|
|
|
||
|
|
const factory ListCustomerDto({
|
||
|
|
@JsonKey(name: "data") List<CustomerDto>? customers,
|
||
|
|
@JsonKey(name: "total_count") int? totalCount,
|
||
|
|
@JsonKey(name: "page") int? page,
|
||
|
|
@JsonKey(name: "limit") int? limit,
|
||
|
|
@JsonKey(name: "total_pages") int? totalPages,
|
||
|
|
}) = _ListCustomerDto;
|
||
|
|
|
||
|
|
factory ListCustomerDto.fromJson(Map<String, dynamic> json) =>
|
||
|
|
_$ListCustomerDtoFromJson(json);
|
||
|
|
|
||
|
|
ListCustomer toDomain() => ListCustomer(
|
||
|
|
customers: customers?.map((e) => e.toDomain()).toList() ?? [],
|
||
|
|
totalCount: totalCount ?? 0,
|
||
|
|
page: page ?? 0,
|
||
|
|
limit: limit ?? 0,
|
||
|
|
totalPages: totalPages ?? 0,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@freezed
|
||
|
|
class CustomerDto with _$CustomerDto {
|
||
|
|
const CustomerDto._();
|
||
|
|
|
||
|
|
const factory CustomerDto({
|
||
|
|
@JsonKey(name: "id") String? id,
|
||
|
|
@JsonKey(name: "organization_id") String? organizationId,
|
||
|
|
@JsonKey(name: "name") String? name,
|
||
|
|
@JsonKey(name: "email") String? email,
|
||
|
|
@JsonKey(name: "phone") String? phone,
|
||
|
|
@JsonKey(name: "address") String? address,
|
||
|
|
@JsonKey(name: "is_default") bool? isDefault,
|
||
|
|
@JsonKey(name: "is_active") bool? isActive,
|
||
|
|
@JsonKey(name: "metadata") Map<String, dynamic>? metadata,
|
||
|
|
@JsonKey(name: "created_at") String? createdAt,
|
||
|
|
@JsonKey(name: "updated_at") String? updatedAt,
|
||
|
|
}) = _CustomerDto;
|
||
|
|
|
||
|
|
factory CustomerDto.fromJson(Map<String, dynamic> json) =>
|
||
|
|
_$CustomerDtoFromJson(json);
|
||
|
|
|
||
|
|
/// Mapping ke domain
|
||
|
|
Customer toDomain() => Customer(
|
||
|
|
id: id ?? '',
|
||
|
|
organizationId: organizationId ?? '',
|
||
|
|
name: name ?? '',
|
||
|
|
email: email ?? '',
|
||
|
|
phone: phone ?? '',
|
||
|
|
address: address ?? '',
|
||
|
|
isDefault: isDefault ?? false,
|
||
|
|
isActive: isActive ?? false,
|
||
|
|
metadata: metadata ?? {},
|
||
|
|
createdAt: createdAt != null ? DateTime.parse(createdAt!) : DateTime(1970),
|
||
|
|
updatedAt: updatedAt != null ? DateTime.parse(updatedAt!) : DateTime(1970),
|
||
|
|
);
|
||
|
|
}
|