feat: product

This commit is contained in:
efrilm
2025-08-17 14:18:10 +07:00
parent 82c0eaf5fe
commit 7d24b3296d
22 changed files with 3779 additions and 183 deletions
@@ -0,0 +1,52 @@
import 'dart:developer';
import 'package:data_channel/data_channel.dart';
import 'package:injectable/injectable.dart';
import '../../../common/api/api_client.dart';
import '../../../common/api/api_failure.dart';
import '../../../common/url/api_path.dart';
import '../../../domain/product/product.dart';
import '../product_dtos.dart';
@injectable
class ProductRemoteDataProvider {
final ApiClient _apiClient;
final String _logName = 'ProductRemoteDataProvider';
ProductRemoteDataProvider(this._apiClient);
Future<DC<ProductFailure, List<ProductDto>>> fetch({
int page = 1,
int limit = 10,
String? categoryId,
String? search,
}) async {
try {
Map<String, dynamic> params = {'page': page, 'limit': limit};
if (categoryId != null) {
params['category_id'] = categoryId;
}
if (search != null) {
params['search'] = search;
}
final response = await _apiClient.get(ApiPath.product, params: params);
if (response.data['data'] == null) {
return DC.error(ProductFailure.empty());
}
final dto = (response.data['data']['products'] as List)
.map((item) => ProductDto.fromJson(item))
.toList();
return DC.data(dto);
} on ApiFailure catch (e, s) {
log('fetchProductError', name: _logName, error: e, stackTrace: s);
return DC.error(ProductFailure.serverError(e));
}
}
}
@@ -0,0 +1,70 @@
part of '../product_dtos.dart';
@freezed
class ProductDto with _$ProductDto {
const ProductDto._();
const factory ProductDto({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'organization_id') String? organizationId,
@JsonKey(name: 'category_id') String? categoryId,
@JsonKey(name: 'sku') String? sku,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'description') String? description,
@JsonKey(name: 'price') int? price,
@JsonKey(name: 'cost') int? cost,
@JsonKey(name: 'business_type') String? businessType,
@JsonKey(name: 'image_url') String? imageUrl,
@JsonKey(name: 'printer_type') String? printerType,
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
@JsonKey(name: 'is_active') bool? isActive,
@JsonKey(name: 'created_at') DateTime? createdAt,
@JsonKey(name: 'updated_at') DateTime? updatedAt,
@JsonKey(name: 'variants') List<ProductVariantDto>? variants,
}) = _ProductDto;
factory ProductDto.fromJson(Map<String, dynamic> json) =>
_$ProductDtoFromJson(json);
/// DTO -> Domain (isi default kalau null)
Product toDomain() => Product(
id: id ?? '',
organizationId: organizationId ?? '',
categoryId: categoryId ?? '',
sku: sku ?? '',
name: name ?? '',
description: description ?? '',
price: price ?? 0,
cost: cost ?? 0,
businessType: businessType ?? '',
imageUrl: imageUrl ?? '',
printerType: printerType ?? '',
metadata: metadata ?? {},
isActive: isActive ?? false,
createdAt: createdAt ?? DateTime.now(),
updatedAt: updatedAt ?? DateTime.now(),
variants: variants?.map((v) => v.toDomain()).toList() ?? [],
);
/// Domain -> DTO
factory ProductDto.fromDomain(Product product) => ProductDto(
id: product.id,
organizationId: product.organizationId,
categoryId: product.categoryId,
sku: product.sku,
name: product.name,
description: product.description,
price: product.price,
cost: product.cost,
businessType: product.businessType,
imageUrl: product.imageUrl,
printerType: product.printerType,
metadata: product.metadata,
isActive: product.isActive,
createdAt: product.createdAt,
updatedAt: product.updatedAt,
variants: product.variants
.map((v) => ProductVariantDto.fromDomain(v))
.toList(),
);
}
@@ -0,0 +1,45 @@
part of '../product_dtos.dart';
@freezed
class ProductVariantDto with _$ProductVariantDto {
const ProductVariantDto._();
const factory ProductVariantDto({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'product_id') String? productId,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'price_modifier') int? priceModifier,
@JsonKey(name: 'cost') int? cost,
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
@JsonKey(name: 'created_at') DateTime? createdAt,
@JsonKey(name: 'updated_at') DateTime? updatedAt,
}) = _ProductVariantDto;
factory ProductVariantDto.fromJson(Map<String, dynamic> json) =>
_$ProductVariantDtoFromJson(json);
/// DTO -> Domain
ProductVariant toDomain() => ProductVariant(
id: id ?? '',
productId: productId ?? '',
name: name ?? '',
priceModifier: priceModifier ?? 0,
cost: cost ?? 0,
metadata: metadata ?? {},
createdAt: createdAt ?? DateTime.now(),
updatedAt: updatedAt ?? DateTime.now(),
);
/// Domain -> DTO
factory ProductVariantDto.fromDomain(ProductVariant variant) =>
ProductVariantDto(
id: variant.id,
productId: variant.productId,
name: variant.name,
priceModifier: variant.priceModifier,
cost: variant.cost,
metadata: variant.metadata,
createdAt: variant.createdAt,
updatedAt: variant.updatedAt,
);
}
@@ -0,0 +1,9 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../domain/product/product.dart';
part 'product_dtos.freezed.dart';
part 'product_dtos.g.dart';
part 'dto/product_dto.dart';
part 'dto/product_variant_dto.dart';
@@ -0,0 +1,926 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'product_dtos.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
ProductDto _$ProductDtoFromJson(Map<String, dynamic> json) {
return _ProductDto.fromJson(json);
}
/// @nodoc
mixin _$ProductDto {
@JsonKey(name: 'id')
String? get id => throw _privateConstructorUsedError;
@JsonKey(name: 'organization_id')
String? get organizationId => throw _privateConstructorUsedError;
@JsonKey(name: 'category_id')
String? get categoryId => throw _privateConstructorUsedError;
@JsonKey(name: 'sku')
String? get sku => throw _privateConstructorUsedError;
@JsonKey(name: 'name')
String? get name => throw _privateConstructorUsedError;
@JsonKey(name: 'description')
String? get description => throw _privateConstructorUsedError;
@JsonKey(name: 'price')
int? get price => throw _privateConstructorUsedError;
@JsonKey(name: 'cost')
int? get cost => throw _privateConstructorUsedError;
@JsonKey(name: 'business_type')
String? get businessType => throw _privateConstructorUsedError;
@JsonKey(name: 'image_url')
String? get imageUrl => throw _privateConstructorUsedError;
@JsonKey(name: 'printer_type')
String? get printerType => throw _privateConstructorUsedError;
@JsonKey(name: 'metadata')
Map<String, dynamic>? get metadata => throw _privateConstructorUsedError;
@JsonKey(name: 'is_active')
bool? get isActive => throw _privateConstructorUsedError;
@JsonKey(name: 'created_at')
DateTime? get createdAt => throw _privateConstructorUsedError;
@JsonKey(name: 'updated_at')
DateTime? get updatedAt => throw _privateConstructorUsedError;
@JsonKey(name: 'variants')
List<ProductVariantDto>? get variants => throw _privateConstructorUsedError;
/// Serializes this ProductDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of ProductDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProductDtoCopyWith<ProductDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProductDtoCopyWith<$Res> {
factory $ProductDtoCopyWith(
ProductDto value,
$Res Function(ProductDto) then,
) = _$ProductDtoCopyWithImpl<$Res, ProductDto>;
@useResult
$Res call({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'organization_id') String? organizationId,
@JsonKey(name: 'category_id') String? categoryId,
@JsonKey(name: 'sku') String? sku,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'description') String? description,
@JsonKey(name: 'price') int? price,
@JsonKey(name: 'cost') int? cost,
@JsonKey(name: 'business_type') String? businessType,
@JsonKey(name: 'image_url') String? imageUrl,
@JsonKey(name: 'printer_type') String? printerType,
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
@JsonKey(name: 'is_active') bool? isActive,
@JsonKey(name: 'created_at') DateTime? createdAt,
@JsonKey(name: 'updated_at') DateTime? updatedAt,
@JsonKey(name: 'variants') List<ProductVariantDto>? variants,
});
}
/// @nodoc
class _$ProductDtoCopyWithImpl<$Res, $Val extends ProductDto>
implements $ProductDtoCopyWith<$Res> {
_$ProductDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProductDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? organizationId = freezed,
Object? categoryId = freezed,
Object? sku = freezed,
Object? name = freezed,
Object? description = freezed,
Object? price = freezed,
Object? cost = freezed,
Object? businessType = freezed,
Object? imageUrl = freezed,
Object? printerType = freezed,
Object? metadata = freezed,
Object? isActive = freezed,
Object? createdAt = freezed,
Object? updatedAt = freezed,
Object? variants = freezed,
}) {
return _then(
_value.copyWith(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
organizationId: freezed == organizationId
? _value.organizationId
: organizationId // ignore: cast_nullable_to_non_nullable
as String?,
categoryId: freezed == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String?,
sku: freezed == sku
? _value.sku
: sku // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
description: freezed == description
? _value.description
: description // ignore: cast_nullable_to_non_nullable
as String?,
price: freezed == price
? _value.price
: price // ignore: cast_nullable_to_non_nullable
as int?,
cost: freezed == cost
? _value.cost
: cost // ignore: cast_nullable_to_non_nullable
as int?,
businessType: freezed == businessType
? _value.businessType
: businessType // ignore: cast_nullable_to_non_nullable
as String?,
imageUrl: freezed == imageUrl
? _value.imageUrl
: imageUrl // ignore: cast_nullable_to_non_nullable
as String?,
printerType: freezed == printerType
? _value.printerType
: printerType // ignore: cast_nullable_to_non_nullable
as String?,
metadata: freezed == metadata
? _value.metadata
: metadata // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
isActive: freezed == isActive
? _value.isActive
: isActive // ignore: cast_nullable_to_non_nullable
as bool?,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
updatedAt: freezed == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
variants: freezed == variants
? _value.variants
: variants // ignore: cast_nullable_to_non_nullable
as List<ProductVariantDto>?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$ProductDtoImplCopyWith<$Res>
implements $ProductDtoCopyWith<$Res> {
factory _$$ProductDtoImplCopyWith(
_$ProductDtoImpl value,
$Res Function(_$ProductDtoImpl) then,
) = __$$ProductDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'organization_id') String? organizationId,
@JsonKey(name: 'category_id') String? categoryId,
@JsonKey(name: 'sku') String? sku,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'description') String? description,
@JsonKey(name: 'price') int? price,
@JsonKey(name: 'cost') int? cost,
@JsonKey(name: 'business_type') String? businessType,
@JsonKey(name: 'image_url') String? imageUrl,
@JsonKey(name: 'printer_type') String? printerType,
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
@JsonKey(name: 'is_active') bool? isActive,
@JsonKey(name: 'created_at') DateTime? createdAt,
@JsonKey(name: 'updated_at') DateTime? updatedAt,
@JsonKey(name: 'variants') List<ProductVariantDto>? variants,
});
}
/// @nodoc
class __$$ProductDtoImplCopyWithImpl<$Res>
extends _$ProductDtoCopyWithImpl<$Res, _$ProductDtoImpl>
implements _$$ProductDtoImplCopyWith<$Res> {
__$$ProductDtoImplCopyWithImpl(
_$ProductDtoImpl _value,
$Res Function(_$ProductDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of ProductDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? organizationId = freezed,
Object? categoryId = freezed,
Object? sku = freezed,
Object? name = freezed,
Object? description = freezed,
Object? price = freezed,
Object? cost = freezed,
Object? businessType = freezed,
Object? imageUrl = freezed,
Object? printerType = freezed,
Object? metadata = freezed,
Object? isActive = freezed,
Object? createdAt = freezed,
Object? updatedAt = freezed,
Object? variants = freezed,
}) {
return _then(
_$ProductDtoImpl(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
organizationId: freezed == organizationId
? _value.organizationId
: organizationId // ignore: cast_nullable_to_non_nullable
as String?,
categoryId: freezed == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String?,
sku: freezed == sku
? _value.sku
: sku // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
description: freezed == description
? _value.description
: description // ignore: cast_nullable_to_non_nullable
as String?,
price: freezed == price
? _value.price
: price // ignore: cast_nullable_to_non_nullable
as int?,
cost: freezed == cost
? _value.cost
: cost // ignore: cast_nullable_to_non_nullable
as int?,
businessType: freezed == businessType
? _value.businessType
: businessType // ignore: cast_nullable_to_non_nullable
as String?,
imageUrl: freezed == imageUrl
? _value.imageUrl
: imageUrl // ignore: cast_nullable_to_non_nullable
as String?,
printerType: freezed == printerType
? _value.printerType
: printerType // ignore: cast_nullable_to_non_nullable
as String?,
metadata: freezed == metadata
? _value._metadata
: metadata // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
isActive: freezed == isActive
? _value.isActive
: isActive // ignore: cast_nullable_to_non_nullable
as bool?,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
updatedAt: freezed == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
variants: freezed == variants
? _value._variants
: variants // ignore: cast_nullable_to_non_nullable
as List<ProductVariantDto>?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$ProductDtoImpl extends _ProductDto {
const _$ProductDtoImpl({
@JsonKey(name: 'id') this.id,
@JsonKey(name: 'organization_id') this.organizationId,
@JsonKey(name: 'category_id') this.categoryId,
@JsonKey(name: 'sku') this.sku,
@JsonKey(name: 'name') this.name,
@JsonKey(name: 'description') this.description,
@JsonKey(name: 'price') this.price,
@JsonKey(name: 'cost') this.cost,
@JsonKey(name: 'business_type') this.businessType,
@JsonKey(name: 'image_url') this.imageUrl,
@JsonKey(name: 'printer_type') this.printerType,
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
@JsonKey(name: 'is_active') this.isActive,
@JsonKey(name: 'created_at') this.createdAt,
@JsonKey(name: 'updated_at') this.updatedAt,
@JsonKey(name: 'variants') final List<ProductVariantDto>? variants,
}) : _metadata = metadata,
_variants = variants,
super._();
factory _$ProductDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$ProductDtoImplFromJson(json);
@override
@JsonKey(name: 'id')
final String? id;
@override
@JsonKey(name: 'organization_id')
final String? organizationId;
@override
@JsonKey(name: 'category_id')
final String? categoryId;
@override
@JsonKey(name: 'sku')
final String? sku;
@override
@JsonKey(name: 'name')
final String? name;
@override
@JsonKey(name: 'description')
final String? description;
@override
@JsonKey(name: 'price')
final int? price;
@override
@JsonKey(name: 'cost')
final int? cost;
@override
@JsonKey(name: 'business_type')
final String? businessType;
@override
@JsonKey(name: 'image_url')
final String? imageUrl;
@override
@JsonKey(name: 'printer_type')
final String? printerType;
final Map<String, dynamic>? _metadata;
@override
@JsonKey(name: 'metadata')
Map<String, dynamic>? get metadata {
final value = _metadata;
if (value == null) return null;
if (_metadata is EqualUnmodifiableMapView) return _metadata;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
@override
@JsonKey(name: 'is_active')
final bool? isActive;
@override
@JsonKey(name: 'created_at')
final DateTime? createdAt;
@override
@JsonKey(name: 'updated_at')
final DateTime? updatedAt;
final List<ProductVariantDto>? _variants;
@override
@JsonKey(name: 'variants')
List<ProductVariantDto>? get variants {
final value = _variants;
if (value == null) return null;
if (_variants is EqualUnmodifiableListView) return _variants;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override
String toString() {
return 'ProductDto(id: $id, organizationId: $organizationId, categoryId: $categoryId, sku: $sku, name: $name, description: $description, price: $price, cost: $cost, businessType: $businessType, imageUrl: $imageUrl, printerType: $printerType, metadata: $metadata, isActive: $isActive, createdAt: $createdAt, updatedAt: $updatedAt, variants: $variants)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProductDtoImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.organizationId, organizationId) ||
other.organizationId == organizationId) &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId) &&
(identical(other.sku, sku) || other.sku == sku) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.description, description) ||
other.description == description) &&
(identical(other.price, price) || other.price == price) &&
(identical(other.cost, cost) || other.cost == cost) &&
(identical(other.businessType, businessType) ||
other.businessType == businessType) &&
(identical(other.imageUrl, imageUrl) ||
other.imageUrl == imageUrl) &&
(identical(other.printerType, printerType) ||
other.printerType == printerType) &&
const DeepCollectionEquality().equals(other._metadata, _metadata) &&
(identical(other.isActive, isActive) ||
other.isActive == isActive) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt) &&
const DeepCollectionEquality().equals(other._variants, _variants));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
organizationId,
categoryId,
sku,
name,
description,
price,
cost,
businessType,
imageUrl,
printerType,
const DeepCollectionEquality().hash(_metadata),
isActive,
createdAt,
updatedAt,
const DeepCollectionEquality().hash(_variants),
);
/// Create a copy of ProductDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProductDtoImplCopyWith<_$ProductDtoImpl> get copyWith =>
__$$ProductDtoImplCopyWithImpl<_$ProductDtoImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$ProductDtoImplToJson(this);
}
}
abstract class _ProductDto extends ProductDto {
const factory _ProductDto({
@JsonKey(name: 'id') final String? id,
@JsonKey(name: 'organization_id') final String? organizationId,
@JsonKey(name: 'category_id') final String? categoryId,
@JsonKey(name: 'sku') final String? sku,
@JsonKey(name: 'name') final String? name,
@JsonKey(name: 'description') final String? description,
@JsonKey(name: 'price') final int? price,
@JsonKey(name: 'cost') final int? cost,
@JsonKey(name: 'business_type') final String? businessType,
@JsonKey(name: 'image_url') final String? imageUrl,
@JsonKey(name: 'printer_type') final String? printerType,
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
@JsonKey(name: 'is_active') final bool? isActive,
@JsonKey(name: 'created_at') final DateTime? createdAt,
@JsonKey(name: 'updated_at') final DateTime? updatedAt,
@JsonKey(name: 'variants') final List<ProductVariantDto>? variants,
}) = _$ProductDtoImpl;
const _ProductDto._() : super._();
factory _ProductDto.fromJson(Map<String, dynamic> json) =
_$ProductDtoImpl.fromJson;
@override
@JsonKey(name: 'id')
String? get id;
@override
@JsonKey(name: 'organization_id')
String? get organizationId;
@override
@JsonKey(name: 'category_id')
String? get categoryId;
@override
@JsonKey(name: 'sku')
String? get sku;
@override
@JsonKey(name: 'name')
String? get name;
@override
@JsonKey(name: 'description')
String? get description;
@override
@JsonKey(name: 'price')
int? get price;
@override
@JsonKey(name: 'cost')
int? get cost;
@override
@JsonKey(name: 'business_type')
String? get businessType;
@override
@JsonKey(name: 'image_url')
String? get imageUrl;
@override
@JsonKey(name: 'printer_type')
String? get printerType;
@override
@JsonKey(name: 'metadata')
Map<String, dynamic>? get metadata;
@override
@JsonKey(name: 'is_active')
bool? get isActive;
@override
@JsonKey(name: 'created_at')
DateTime? get createdAt;
@override
@JsonKey(name: 'updated_at')
DateTime? get updatedAt;
@override
@JsonKey(name: 'variants')
List<ProductVariantDto>? get variants;
/// Create a copy of ProductDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProductDtoImplCopyWith<_$ProductDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
ProductVariantDto _$ProductVariantDtoFromJson(Map<String, dynamic> json) {
return _ProductVariantDto.fromJson(json);
}
/// @nodoc
mixin _$ProductVariantDto {
@JsonKey(name: 'id')
String? get id => throw _privateConstructorUsedError;
@JsonKey(name: 'product_id')
String? get productId => throw _privateConstructorUsedError;
@JsonKey(name: 'name')
String? get name => throw _privateConstructorUsedError;
@JsonKey(name: 'price_modifier')
int? get priceModifier => throw _privateConstructorUsedError;
@JsonKey(name: 'cost')
int? get cost => throw _privateConstructorUsedError;
@JsonKey(name: 'metadata')
Map<String, dynamic>? get metadata => throw _privateConstructorUsedError;
@JsonKey(name: 'created_at')
DateTime? get createdAt => throw _privateConstructorUsedError;
@JsonKey(name: 'updated_at')
DateTime? get updatedAt => throw _privateConstructorUsedError;
/// Serializes this ProductVariantDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of ProductVariantDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProductVariantDtoCopyWith<ProductVariantDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProductVariantDtoCopyWith<$Res> {
factory $ProductVariantDtoCopyWith(
ProductVariantDto value,
$Res Function(ProductVariantDto) then,
) = _$ProductVariantDtoCopyWithImpl<$Res, ProductVariantDto>;
@useResult
$Res call({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'product_id') String? productId,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'price_modifier') int? priceModifier,
@JsonKey(name: 'cost') int? cost,
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
@JsonKey(name: 'created_at') DateTime? createdAt,
@JsonKey(name: 'updated_at') DateTime? updatedAt,
});
}
/// @nodoc
class _$ProductVariantDtoCopyWithImpl<$Res, $Val extends ProductVariantDto>
implements $ProductVariantDtoCopyWith<$Res> {
_$ProductVariantDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProductVariantDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? productId = freezed,
Object? name = freezed,
Object? priceModifier = freezed,
Object? cost = freezed,
Object? metadata = freezed,
Object? createdAt = freezed,
Object? updatedAt = freezed,
}) {
return _then(
_value.copyWith(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
productId: freezed == productId
? _value.productId
: productId // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
priceModifier: freezed == priceModifier
? _value.priceModifier
: priceModifier // ignore: cast_nullable_to_non_nullable
as int?,
cost: freezed == cost
? _value.cost
: cost // ignore: cast_nullable_to_non_nullable
as int?,
metadata: freezed == metadata
? _value.metadata
: metadata // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
updatedAt: freezed == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$ProductVariantDtoImplCopyWith<$Res>
implements $ProductVariantDtoCopyWith<$Res> {
factory _$$ProductVariantDtoImplCopyWith(
_$ProductVariantDtoImpl value,
$Res Function(_$ProductVariantDtoImpl) then,
) = __$$ProductVariantDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
@JsonKey(name: 'id') String? id,
@JsonKey(name: 'product_id') String? productId,
@JsonKey(name: 'name') String? name,
@JsonKey(name: 'price_modifier') int? priceModifier,
@JsonKey(name: 'cost') int? cost,
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
@JsonKey(name: 'created_at') DateTime? createdAt,
@JsonKey(name: 'updated_at') DateTime? updatedAt,
});
}
/// @nodoc
class __$$ProductVariantDtoImplCopyWithImpl<$Res>
extends _$ProductVariantDtoCopyWithImpl<$Res, _$ProductVariantDtoImpl>
implements _$$ProductVariantDtoImplCopyWith<$Res> {
__$$ProductVariantDtoImplCopyWithImpl(
_$ProductVariantDtoImpl _value,
$Res Function(_$ProductVariantDtoImpl) _then,
) : super(_value, _then);
/// Create a copy of ProductVariantDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? productId = freezed,
Object? name = freezed,
Object? priceModifier = freezed,
Object? cost = freezed,
Object? metadata = freezed,
Object? createdAt = freezed,
Object? updatedAt = freezed,
}) {
return _then(
_$ProductVariantDtoImpl(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
productId: freezed == productId
? _value.productId
: productId // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
priceModifier: freezed == priceModifier
? _value.priceModifier
: priceModifier // ignore: cast_nullable_to_non_nullable
as int?,
cost: freezed == cost
? _value.cost
: cost // ignore: cast_nullable_to_non_nullable
as int?,
metadata: freezed == metadata
? _value._metadata
: metadata // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
updatedAt: freezed == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$ProductVariantDtoImpl extends _ProductVariantDto {
const _$ProductVariantDtoImpl({
@JsonKey(name: 'id') this.id,
@JsonKey(name: 'product_id') this.productId,
@JsonKey(name: 'name') this.name,
@JsonKey(name: 'price_modifier') this.priceModifier,
@JsonKey(name: 'cost') this.cost,
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
@JsonKey(name: 'created_at') this.createdAt,
@JsonKey(name: 'updated_at') this.updatedAt,
}) : _metadata = metadata,
super._();
factory _$ProductVariantDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$ProductVariantDtoImplFromJson(json);
@override
@JsonKey(name: 'id')
final String? id;
@override
@JsonKey(name: 'product_id')
final String? productId;
@override
@JsonKey(name: 'name')
final String? name;
@override
@JsonKey(name: 'price_modifier')
final int? priceModifier;
@override
@JsonKey(name: 'cost')
final int? cost;
final Map<String, dynamic>? _metadata;
@override
@JsonKey(name: 'metadata')
Map<String, dynamic>? get metadata {
final value = _metadata;
if (value == null) return null;
if (_metadata is EqualUnmodifiableMapView) return _metadata;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
@override
@JsonKey(name: 'created_at')
final DateTime? createdAt;
@override
@JsonKey(name: 'updated_at')
final DateTime? updatedAt;
@override
String toString() {
return 'ProductVariantDto(id: $id, productId: $productId, name: $name, priceModifier: $priceModifier, cost: $cost, metadata: $metadata, createdAt: $createdAt, updatedAt: $updatedAt)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProductVariantDtoImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.productId, productId) ||
other.productId == productId) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.priceModifier, priceModifier) ||
other.priceModifier == priceModifier) &&
(identical(other.cost, cost) || other.cost == cost) &&
const DeepCollectionEquality().equals(other._metadata, _metadata) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
productId,
name,
priceModifier,
cost,
const DeepCollectionEquality().hash(_metadata),
createdAt,
updatedAt,
);
/// Create a copy of ProductVariantDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProductVariantDtoImplCopyWith<_$ProductVariantDtoImpl> get copyWith =>
__$$ProductVariantDtoImplCopyWithImpl<_$ProductVariantDtoImpl>(
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$ProductVariantDtoImplToJson(this);
}
}
abstract class _ProductVariantDto extends ProductVariantDto {
const factory _ProductVariantDto({
@JsonKey(name: 'id') final String? id,
@JsonKey(name: 'product_id') final String? productId,
@JsonKey(name: 'name') final String? name,
@JsonKey(name: 'price_modifier') final int? priceModifier,
@JsonKey(name: 'cost') final int? cost,
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
@JsonKey(name: 'created_at') final DateTime? createdAt,
@JsonKey(name: 'updated_at') final DateTime? updatedAt,
}) = _$ProductVariantDtoImpl;
const _ProductVariantDto._() : super._();
factory _ProductVariantDto.fromJson(Map<String, dynamic> json) =
_$ProductVariantDtoImpl.fromJson;
@override
@JsonKey(name: 'id')
String? get id;
@override
@JsonKey(name: 'product_id')
String? get productId;
@override
@JsonKey(name: 'name')
String? get name;
@override
@JsonKey(name: 'price_modifier')
int? get priceModifier;
@override
@JsonKey(name: 'cost')
int? get cost;
@override
@JsonKey(name: 'metadata')
Map<String, dynamic>? get metadata;
@override
@JsonKey(name: 'created_at')
DateTime? get createdAt;
@override
@JsonKey(name: 'updated_at')
DateTime? get updatedAt;
/// Create a copy of ProductVariantDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProductVariantDtoImplCopyWith<_$ProductVariantDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,83 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'product_dtos.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$ProductDtoImpl _$$ProductDtoImplFromJson(Map<String, dynamic> json) =>
_$ProductDtoImpl(
id: json['id'] as String?,
organizationId: json['organization_id'] as String?,
categoryId: json['category_id'] as String?,
sku: json['sku'] as String?,
name: json['name'] as String?,
description: json['description'] as String?,
price: (json['price'] as num?)?.toInt(),
cost: (json['cost'] as num?)?.toInt(),
businessType: json['business_type'] as String?,
imageUrl: json['image_url'] as String?,
printerType: json['printer_type'] as String?,
metadata: json['metadata'] as Map<String, dynamic>?,
isActive: json['is_active'] as bool?,
createdAt: json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String),
updatedAt: json['updated_at'] == null
? null
: DateTime.parse(json['updated_at'] as String),
variants: (json['variants'] as List<dynamic>?)
?.map((e) => ProductVariantDto.fromJson(e as Map<String, dynamic>))
.toList(),
);
Map<String, dynamic> _$$ProductDtoImplToJson(_$ProductDtoImpl instance) =>
<String, dynamic>{
'id': instance.id,
'organization_id': instance.organizationId,
'category_id': instance.categoryId,
'sku': instance.sku,
'name': instance.name,
'description': instance.description,
'price': instance.price,
'cost': instance.cost,
'business_type': instance.businessType,
'image_url': instance.imageUrl,
'printer_type': instance.printerType,
'metadata': instance.metadata,
'is_active': instance.isActive,
'created_at': instance.createdAt?.toIso8601String(),
'updated_at': instance.updatedAt?.toIso8601String(),
'variants': instance.variants,
};
_$ProductVariantDtoImpl _$$ProductVariantDtoImplFromJson(
Map<String, dynamic> json,
) => _$ProductVariantDtoImpl(
id: json['id'] as String?,
productId: json['product_id'] as String?,
name: json['name'] as String?,
priceModifier: (json['price_modifier'] as num?)?.toInt(),
cost: (json['cost'] as num?)?.toInt(),
metadata: json['metadata'] as Map<String, dynamic>?,
createdAt: json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String),
updatedAt: json['updated_at'] == null
? null
: DateTime.parse(json['updated_at'] as String),
);
Map<String, dynamic> _$$ProductVariantDtoImplToJson(
_$ProductVariantDtoImpl instance,
) => <String, dynamic>{
'id': instance.id,
'product_id': instance.productId,
'name': instance.name,
'price_modifier': instance.priceModifier,
'cost': instance.cost,
'metadata': instance.metadata,
'created_at': instance.createdAt?.toIso8601String(),
'updated_at': instance.updatedAt?.toIso8601String(),
};
@@ -0,0 +1,43 @@
import 'dart:developer';
import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/product/product.dart';
import '../datasources/remote_data_provider.dart';
@Injectable(as: IProductRepository)
class ProductRepository implements IProductRepository {
final ProductRemoteDataProvider _dataProvider;
final String _logName = 'ProductRepository';
ProductRepository(this._dataProvider);
@override
Future<Either<ProductFailure, List<Product>>> get({
int page = 1,
int limit = 10,
String? categoryId,
String? search,
}) async {
try {
final result = await _dataProvider.fetch(
page: page,
limit: limit,
categoryId: categoryId,
search: search,
);
if (result.hasError) {
return left(result.error!);
}
final auth = result.data!.map((e) => e.toDomain()).toList();
return right(auth);
} catch (e, s) {
log('getProductError', name: _logName, error: e, stackTrace: s);
return left(const ProductFailure.unexpectedError());
}
}
}