
Fetches detailed move line and move data, including product information, for stock picking records from the API. Centralizes ObjectBox persistence within `toEntity()` methods for product, move line, and move models, ensuring data is saved upon conversion. Correctly associates product entities with move line and move entities in the local database. Refactors API call processing to directly return mapped entities, leveraging the updated `toEntity()` behavior.
33 lines
967 B
Dart
33 lines
967 B
Dart
import 'package:e_scan/backend/objectbox/entities/product/product_entity.dart';
|
|
import 'package:e_scan/backend/objectbox/objectbox_manager.dart';
|
|
import 'package:e_scan/utils/utils.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'product_model.freezed.dart';
|
|
part 'product_model.g.dart';
|
|
|
|
@Freezed(toJson: true)
|
|
abstract class ProductModel with _$ProductModel {
|
|
factory ProductModel({
|
|
int? id,
|
|
@JsonKey(fromJson: stringFromJson) String? barcode,
|
|
@JsonKey(name: 'display_name', fromJson: stringFromJson)
|
|
String? displayName,
|
|
}) = _ProductModel;
|
|
|
|
factory ProductModel.fromJson(Map<String, dynamic> json) =>
|
|
_$ProductModelFromJson(json);
|
|
}
|
|
|
|
extension ProductModelExt on ProductModel {
|
|
ProductEntity toEntity() {
|
|
final entity = ProductEntity(
|
|
id: id ?? 0,
|
|
displayName: displayName,
|
|
barcode: barcode,
|
|
);
|
|
objectboxManager.store.box<ProductEntity>().put(entity);
|
|
return entity;
|
|
}
|
|
}
|