mnemo_cards/mnemo_cards_backend/lib/extensions.dart

39 lines
1.5 KiB
Dart
Raw Normal View History

2025-11-16 11:25:27 +00:00
import 'package:mnemo_cards_common_backend/mnemo_cards_common_backend.dart';
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
extension ProductExt on MnemoCardsProductDto {
MnemoCardsProductModel toModel() => MnemoCardsProductModelBase(
productId: int.tryParse(id ?? ''),
type: type.toModel(),
);
}
extension ProductModelTypeExt on MnemoCardsProductType {
MnemoCardsProductModelType toModel() => switch (this) {
MnemoCardsProductType.pack => MnemoCardsProductModelType.pack,
MnemoCardsProductType.subscription =>
MnemoCardsProductModelType.subscription,
MnemoCardsProductType.discount => MnemoCardsProductModelType.discount,
MnemoCardsProductType.unknown => MnemoCardsProductModelType.unknown,
MnemoCardsProductType.game => MnemoCardsProductModelType.game,
};
}
extension ProductModelExt on MnemoCardsProductModel {
MnemoCardsProductDto toDto() => MnemoCardsProductDto(
id: id?.toString(),
type: type.toDto(),
);
}
extension ProductTypeExt on MnemoCardsProductModelType {
MnemoCardsProductType toDto() => switch (this) {
MnemoCardsProductModelType.pack => MnemoCardsProductType.pack,
MnemoCardsProductModelType.subscription =>
MnemoCardsProductType.subscription,
MnemoCardsProductModelType.discount => MnemoCardsProductType.discount,
MnemoCardsProductModelType.unknown => MnemoCardsProductType.unknown,
MnemoCardsProductModelType.game => MnemoCardsProductType.game,
};
}