feat : segmentation model and api call

This commit is contained in:
2025-07-13 13:11:03 +03:30
parent 6de5c21919
commit d78a604d03
5 changed files with 435 additions and 2 deletions

View File

@@ -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<String, dynamic> 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<String, dynamic> json) => _$BuyerFromJson(json);
}

View File

@@ -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>(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<SegmentationModel> get copyWith => _$SegmentationModelCopyWithImpl<SegmentationModel>(this as SegmentationModel, _$identity);
/// Serializes this SegmentationModel to a JSON map.
Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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<Buyer> get copyWith => _$BuyerCopyWithImpl<Buyer>(this as Buyer, _$identity);
/// Serializes this Buyer to a JSON map.
Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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

View File

@@ -0,0 +1,41 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'segmentation_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_SegmentationModel _$SegmentationModelFromJson(Map<String, dynamic> json) =>
_SegmentationModel(
key: json['key'] as String?,
buyer: json['buyer'] == null
? null
: Buyer.fromJson(json['buyer'] as Map<String, dynamic>),
date: json['date'] == null
? null
: DateTime.parse(json['date'] as String),
weight: (json['weight'] as num?)?.toDouble(),
);
Map<String, dynamic> _$SegmentationModelToJson(_SegmentationModel instance) =>
<String, dynamic>{
'key': instance.key,
'buyer': instance.buyer,
'date': instance.date?.toIso8601String(),
'weight': instance.weight,
};
_Buyer _$BuyerFromJson(Map<String, dynamic> json) => _Buyer(
fullname: json['fullname'] as String?,
mobile: json['mobile'] as String?,
shop: json['shop'] as String?,
type: json['type'] as String?,
);
Map<String, dynamic> _$BuyerToJson(_Buyer instance) => <String, dynamic>{
'fullname': instance.fullname,
'mobile': instance.mobile,
'shop': instance.shop,
'type': instance.type,
};

View File

@@ -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<void> updateUserProfile({required String token, required UserProfile userProfile});
Future<void> updatePassword({required String token, required ChangePasswordRequestModel model});
Future<PaginationModel<SegmentationModel>?> getSegmentation({
required String token,
Map<String, dynamic>? queryParameters,
});
Future<void> editSegmentation({required String token, required SegmentationModel model});
Future<void> deleteSegmentation({required String token, required String key});
}

View File

@@ -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<List<InventoryModel>?> getInventory({required String token, CancelToken? cancelToken}) async {
Future<List<InventoryModel>?> 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<PaginationModel<SegmentationModel>?> getSegmentation({
required String token,
Map<String, dynamic>? queryParameters,
}) async {
var res = await _httpClient.get(
'/app-segmentation/',
queryParameters: queryParameters,
headers: {'Authorization': 'Bearer $token'},
fromJson: (json) => PaginationModel<SegmentationModel>.fromJson(
json,
(json) => SegmentationModel.fromJson(json as Map<String, dynamic>),
),
);
return res.data;
}
@override
Future<void> 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<void> deleteSegmentation({required String token, required String key}) async {
await _httpClient.delete(
'/app-segmentation/0/',
queryParameters: {'key': key},
headers: {'Authorization': 'Bearer $token'},
);
}
}