From d78a604d037ba99c7e9503ccc4cb72b4d6f15d51 Mon Sep 17 00:00:00 2001 From: "mr.mojtaba" Date: Sun, 13 Jul 2025 13:11:03 +0330 Subject: [PATCH] feat : segmentation model and api call --- .../segmentation_model.dart | 21 ++ .../segmentation_model.freezed.dart | 323 ++++++++++++++++++ .../segmentation_model.g.dart | 41 +++ .../data/repositories/chicken_repository.dart | 10 + .../repositories/chicken_repository_imp.dart | 42 ++- 5 files changed, 435 insertions(+), 2 deletions(-) create mode 100644 packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.dart create mode 100644 packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.freezed.dart create mode 100644 packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.g.dart diff --git a/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.dart b/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.dart new file mode 100644 index 0000000..3ab099b --- /dev/null +++ b/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.dart @@ -0,0 +1,21 @@ +// segmentation_model.dart +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'segmentation_model.freezed.dart'; +part 'segmentation_model.g.dart'; + +@freezed +abstract class SegmentationModel with _$SegmentationModel { + const factory SegmentationModel({String? key, Buyer? buyer, DateTime? date, double? weight}) = + _SegmentationModel; + + factory SegmentationModel.fromJson(Map json) => + _$SegmentationModelFromJson(json); +} + +@freezed +abstract class Buyer with _$Buyer { + const factory Buyer({String? fullname, String? mobile, String? shop, String? type}) = _Buyer; + + factory Buyer.fromJson(Map json) => _$BuyerFromJson(json); +} diff --git a/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.freezed.dart b/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.freezed.dart new file mode 100644 index 0000000..0546eca --- /dev/null +++ b/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.freezed.dart @@ -0,0 +1,323 @@ +// dart format width=80 +// 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 'segmentation_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +// dart format off +T _$identity(T value) => value; + +/// @nodoc +mixin _$SegmentationModel { + + String? get key; Buyer? get buyer; DateTime? get date; double? get weight; +/// Create a copy of SegmentationModel +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$SegmentationModelCopyWith get copyWith => _$SegmentationModelCopyWithImpl(this as SegmentationModel, _$identity); + + /// Serializes this SegmentationModel to a JSON map. + Map toJson(); + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is SegmentationModel&&(identical(other.key, key) || other.key == key)&&(identical(other.buyer, buyer) || other.buyer == buyer)&&(identical(other.date, date) || other.date == date)&&(identical(other.weight, weight) || other.weight == weight)); +} + +@JsonKey(includeFromJson: false, includeToJson: false) +@override +int get hashCode => Object.hash(runtimeType,key,buyer,date,weight); + +@override +String toString() { + return 'SegmentationModel(key: $key, buyer: $buyer, date: $date, weight: $weight)'; +} + + +} + +/// @nodoc +abstract mixin class $SegmentationModelCopyWith<$Res> { + factory $SegmentationModelCopyWith(SegmentationModel value, $Res Function(SegmentationModel) _then) = _$SegmentationModelCopyWithImpl; +@useResult +$Res call({ + String? key, Buyer? buyer, DateTime? date, double? weight +}); + + +$BuyerCopyWith<$Res>? get buyer; + +} +/// @nodoc +class _$SegmentationModelCopyWithImpl<$Res> + implements $SegmentationModelCopyWith<$Res> { + _$SegmentationModelCopyWithImpl(this._self, this._then); + + final SegmentationModel _self; + final $Res Function(SegmentationModel) _then; + +/// Create a copy of SegmentationModel +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') @override $Res call({Object? key = freezed,Object? buyer = freezed,Object? date = freezed,Object? weight = freezed,}) { + return _then(_self.copyWith( +key: freezed == key ? _self.key : key // ignore: cast_nullable_to_non_nullable +as String?,buyer: freezed == buyer ? _self.buyer : buyer // ignore: cast_nullable_to_non_nullable +as Buyer?,date: freezed == date ? _self.date : date // ignore: cast_nullable_to_non_nullable +as DateTime?,weight: freezed == weight ? _self.weight : weight // ignore: cast_nullable_to_non_nullable +as double?, + )); +} +/// Create a copy of SegmentationModel +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$BuyerCopyWith<$Res>? get buyer { + if (_self.buyer == null) { + return null; + } + + return $BuyerCopyWith<$Res>(_self.buyer!, (value) { + return _then(_self.copyWith(buyer: value)); + }); +} +} + + +/// @nodoc +@JsonSerializable() + +class _SegmentationModel implements SegmentationModel { + const _SegmentationModel({this.key, this.buyer, this.date, this.weight}); + factory _SegmentationModel.fromJson(Map json) => _$SegmentationModelFromJson(json); + +@override final String? key; +@override final Buyer? buyer; +@override final DateTime? date; +@override final double? weight; + +/// Create a copy of SegmentationModel +/// with the given fields replaced by the non-null parameter values. +@override @JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +_$SegmentationModelCopyWith<_SegmentationModel> get copyWith => __$SegmentationModelCopyWithImpl<_SegmentationModel>(this, _$identity); + +@override +Map toJson() { + return _$SegmentationModelToJson(this, ); +} + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is _SegmentationModel&&(identical(other.key, key) || other.key == key)&&(identical(other.buyer, buyer) || other.buyer == buyer)&&(identical(other.date, date) || other.date == date)&&(identical(other.weight, weight) || other.weight == weight)); +} + +@JsonKey(includeFromJson: false, includeToJson: false) +@override +int get hashCode => Object.hash(runtimeType,key,buyer,date,weight); + +@override +String toString() { + return 'SegmentationModel(key: $key, buyer: $buyer, date: $date, weight: $weight)'; +} + + +} + +/// @nodoc +abstract mixin class _$SegmentationModelCopyWith<$Res> implements $SegmentationModelCopyWith<$Res> { + factory _$SegmentationModelCopyWith(_SegmentationModel value, $Res Function(_SegmentationModel) _then) = __$SegmentationModelCopyWithImpl; +@override @useResult +$Res call({ + String? key, Buyer? buyer, DateTime? date, double? weight +}); + + +@override $BuyerCopyWith<$Res>? get buyer; + +} +/// @nodoc +class __$SegmentationModelCopyWithImpl<$Res> + implements _$SegmentationModelCopyWith<$Res> { + __$SegmentationModelCopyWithImpl(this._self, this._then); + + final _SegmentationModel _self; + final $Res Function(_SegmentationModel) _then; + +/// Create a copy of SegmentationModel +/// with the given fields replaced by the non-null parameter values. +@override @pragma('vm:prefer-inline') $Res call({Object? key = freezed,Object? buyer = freezed,Object? date = freezed,Object? weight = freezed,}) { + return _then(_SegmentationModel( +key: freezed == key ? _self.key : key // ignore: cast_nullable_to_non_nullable +as String?,buyer: freezed == buyer ? _self.buyer : buyer // ignore: cast_nullable_to_non_nullable +as Buyer?,date: freezed == date ? _self.date : date // ignore: cast_nullable_to_non_nullable +as DateTime?,weight: freezed == weight ? _self.weight : weight // ignore: cast_nullable_to_non_nullable +as double?, + )); +} + +/// Create a copy of SegmentationModel +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$BuyerCopyWith<$Res>? get buyer { + if (_self.buyer == null) { + return null; + } + + return $BuyerCopyWith<$Res>(_self.buyer!, (value) { + return _then(_self.copyWith(buyer: value)); + }); +} +} + + +/// @nodoc +mixin _$Buyer { + + String? get fullname; String? get mobile; String? get shop; String? get type; +/// Create a copy of Buyer +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$BuyerCopyWith get copyWith => _$BuyerCopyWithImpl(this as Buyer, _$identity); + + /// Serializes this Buyer to a JSON map. + Map toJson(); + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is Buyer&&(identical(other.fullname, fullname) || other.fullname == fullname)&&(identical(other.mobile, mobile) || other.mobile == mobile)&&(identical(other.shop, shop) || other.shop == shop)&&(identical(other.type, type) || other.type == type)); +} + +@JsonKey(includeFromJson: false, includeToJson: false) +@override +int get hashCode => Object.hash(runtimeType,fullname,mobile,shop,type); + +@override +String toString() { + return 'Buyer(fullname: $fullname, mobile: $mobile, shop: $shop, type: $type)'; +} + + +} + +/// @nodoc +abstract mixin class $BuyerCopyWith<$Res> { + factory $BuyerCopyWith(Buyer value, $Res Function(Buyer) _then) = _$BuyerCopyWithImpl; +@useResult +$Res call({ + String? fullname, String? mobile, String? shop, String? type +}); + + + + +} +/// @nodoc +class _$BuyerCopyWithImpl<$Res> + implements $BuyerCopyWith<$Res> { + _$BuyerCopyWithImpl(this._self, this._then); + + final Buyer _self; + final $Res Function(Buyer) _then; + +/// Create a copy of Buyer +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') @override $Res call({Object? fullname = freezed,Object? mobile = freezed,Object? shop = freezed,Object? type = freezed,}) { + return _then(_self.copyWith( +fullname: freezed == fullname ? _self.fullname : fullname // ignore: cast_nullable_to_non_nullable +as String?,mobile: freezed == mobile ? _self.mobile : mobile // ignore: cast_nullable_to_non_nullable +as String?,shop: freezed == shop ? _self.shop : shop // ignore: cast_nullable_to_non_nullable +as String?,type: freezed == type ? _self.type : type // ignore: cast_nullable_to_non_nullable +as String?, + )); +} + +} + + +/// @nodoc +@JsonSerializable() + +class _Buyer implements Buyer { + const _Buyer({this.fullname, this.mobile, this.shop, this.type}); + factory _Buyer.fromJson(Map json) => _$BuyerFromJson(json); + +@override final String? fullname; +@override final String? mobile; +@override final String? shop; +@override final String? type; + +/// Create a copy of Buyer +/// with the given fields replaced by the non-null parameter values. +@override @JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +_$BuyerCopyWith<_Buyer> get copyWith => __$BuyerCopyWithImpl<_Buyer>(this, _$identity); + +@override +Map toJson() { + return _$BuyerToJson(this, ); +} + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is _Buyer&&(identical(other.fullname, fullname) || other.fullname == fullname)&&(identical(other.mobile, mobile) || other.mobile == mobile)&&(identical(other.shop, shop) || other.shop == shop)&&(identical(other.type, type) || other.type == type)); +} + +@JsonKey(includeFromJson: false, includeToJson: false) +@override +int get hashCode => Object.hash(runtimeType,fullname,mobile,shop,type); + +@override +String toString() { + return 'Buyer(fullname: $fullname, mobile: $mobile, shop: $shop, type: $type)'; +} + + +} + +/// @nodoc +abstract mixin class _$BuyerCopyWith<$Res> implements $BuyerCopyWith<$Res> { + factory _$BuyerCopyWith(_Buyer value, $Res Function(_Buyer) _then) = __$BuyerCopyWithImpl; +@override @useResult +$Res call({ + String? fullname, String? mobile, String? shop, String? type +}); + + + + +} +/// @nodoc +class __$BuyerCopyWithImpl<$Res> + implements _$BuyerCopyWith<$Res> { + __$BuyerCopyWithImpl(this._self, this._then); + + final _Buyer _self; + final $Res Function(_Buyer) _then; + +/// Create a copy of Buyer +/// with the given fields replaced by the non-null parameter values. +@override @pragma('vm:prefer-inline') $Res call({Object? fullname = freezed,Object? mobile = freezed,Object? shop = freezed,Object? type = freezed,}) { + return _then(_Buyer( +fullname: freezed == fullname ? _self.fullname : fullname // ignore: cast_nullable_to_non_nullable +as String?,mobile: freezed == mobile ? _self.mobile : mobile // ignore: cast_nullable_to_non_nullable +as String?,shop: freezed == shop ? _self.shop : shop // ignore: cast_nullable_to_non_nullable +as String?,type: freezed == type ? _self.type : type // ignore: cast_nullable_to_non_nullable +as String?, + )); +} + + +} + +// dart format on diff --git a/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.g.dart b/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.g.dart new file mode 100644 index 0000000..22b4989 --- /dev/null +++ b/packages/chicken/lib/data/models/response/segmentation_model/segmentation_model.g.dart @@ -0,0 +1,41 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'segmentation_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_SegmentationModel _$SegmentationModelFromJson(Map json) => + _SegmentationModel( + key: json['key'] as String?, + buyer: json['buyer'] == null + ? null + : Buyer.fromJson(json['buyer'] as Map), + date: json['date'] == null + ? null + : DateTime.parse(json['date'] as String), + weight: (json['weight'] as num?)?.toDouble(), + ); + +Map _$SegmentationModelToJson(_SegmentationModel instance) => + { + 'key': instance.key, + 'buyer': instance.buyer, + 'date': instance.date?.toIso8601String(), + 'weight': instance.weight, + }; + +_Buyer _$BuyerFromJson(Map json) => _Buyer( + fullname: json['fullname'] as String?, + mobile: json['mobile'] as String?, + shop: json['shop'] as String?, + type: json['type'] as String?, +); + +Map _$BuyerToJson(_Buyer instance) => { + 'fullname': instance.fullname, + 'mobile': instance.mobile, + 'shop': instance.shop, + 'type': instance.type, +}; diff --git a/packages/chicken/lib/data/repositories/chicken_repository.dart b/packages/chicken/lib/data/repositories/chicken_repository.dart index e85f4a9..54c88f7 100644 --- a/packages/chicken/lib/data/repositories/chicken_repository.dart +++ b/packages/chicken/lib/data/repositories/chicken_repository.dart @@ -13,6 +13,7 @@ import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_pr import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart'; import 'package:rasadyar_chicken/data/models/response/out_province_carcasses_buyer/out_province_carcasses_buyer.dart'; import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart'; +import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart'; import 'package:rasadyar_chicken/data/models/response/steward_free_bar/steward_free_bar.dart'; import 'package:rasadyar_chicken/data/models/response/steward_free_bar_dashboard/steward_free_bar_dashboard.dart'; import 'package:rasadyar_chicken/data/models/response/steward_free_sale_bar/steward_free_sale_bar.dart'; @@ -141,4 +142,13 @@ abstract class ChickenRepository { Future updateUserProfile({required String token, required UserProfile userProfile}); Future updatePassword({required String token, required ChangePasswordRequestModel model}); + + Future?> getSegmentation({ + required String token, + Map? queryParameters, + }); + + Future editSegmentation({required String token, required SegmentationModel model}); + + Future deleteSegmentation({required String token, required String key}); } diff --git a/packages/chicken/lib/data/repositories/chicken_repository_imp.dart b/packages/chicken/lib/data/repositories/chicken_repository_imp.dart index 6067433..3e1a80a 100644 --- a/packages/chicken/lib/data/repositories/chicken_repository_imp.dart +++ b/packages/chicken/lib/data/repositories/chicken_repository_imp.dart @@ -14,6 +14,7 @@ import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_pr import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart'; import 'package:rasadyar_chicken/data/models/response/out_province_carcasses_buyer/out_province_carcasses_buyer.dart'; import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart'; +import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart'; import 'package:rasadyar_chicken/data/models/response/steward_free_bar/steward_free_bar.dart'; import 'package:rasadyar_chicken/data/models/response/steward_free_bar_dashboard/steward_free_bar_dashboard.dart'; import 'package:rasadyar_chicken/data/models/response/steward_free_sale_bar/steward_free_sale_bar.dart'; @@ -30,8 +31,10 @@ class ChickenRepositoryImpl implements ChickenRepository { ChickenRepositoryImpl(this._httpClient); @override - Future?> getInventory({required String token, CancelToken? cancelToken}) async { - + Future?> getInventory({ + required String token, + CancelToken? cancelToken, + }) async { eLog(_httpClient.baseUrl); var res = await _httpClient.get( '/roles-products/?role=Steward', @@ -429,4 +432,39 @@ class ChickenRepositoryImpl implements ChickenRepository { data: model.toJson()..removeWhere((key, value) => value == null), ); } + + @override + Future?> getSegmentation({ + required String token, + Map? queryParameters, + }) async { + var res = await _httpClient.get( + '/app-segmentation/', + queryParameters: queryParameters, + headers: {'Authorization': 'Bearer $token'}, + fromJson: (json) => PaginationModel.fromJson( + json, + (json) => SegmentationModel.fromJson(json as Map), + ), + ); + return res.data; + } + + @override + Future editSegmentation({required String token, required SegmentationModel model}) async { + await _httpClient.put( + '/app-segmentation/0/', + data: model.toJson()..removeWhere((key, value) => value == null), + headers: {'Authorization': 'Bearer $token'}, + ); + } + + @override + Future deleteSegmentation({required String token, required String key}) async { + await _httpClient.delete( + '/app-segmentation/0/', + queryParameters: {'key': key}, + headers: {'Authorization': 'Bearer $token'}, + ); + } }