diff --git a/lib/features/profile/models/profile_model.dart b/lib/features/profile/models/profile_model.dart index 8ecf3b4f..e7dd87f1 100644 --- a/lib/features/profile/models/profile_model.dart +++ b/lib/features/profile/models/profile_model.dart @@ -1,24 +1,38 @@ import 'package:freezed_annotation/freezed_annotation.dart'; - part 'profile_model.freezed.dart'; part 'profile_model.g.dart'; @freezed -class Profile with _$Profile { - const factory Profile({ +class ProfileModel with _$ProfileModel { + const factory ProfileModel({ @JsonKey(name: "user") required User user, @JsonKey(name: "chartPoints") required List chartPoints, @JsonKey(name: "userDetails") required UserDetails userDetails, - @JsonKey(name: "circumferences") required List circumferences, + @JsonKey(name: "circumferences") required List circumferences, @JsonKey(name: "finishedPlans") required List finishedPlans, @JsonKey(name: "rejectedPlans") required List rejectedPlans, @JsonKey(name: "startedPlan") required List startedPlan, @JsonKey(name: "paidPlan") required List paidPlan, @JsonKey(name: "requestedPlan") required List requestedPlan, @JsonKey(name: "initedPlan") required List initedPlan, - }) = _Profile; + }) = _ProfileModel; - factory Profile.fromJson(Map json) => _$ProfileFromJson(json); + factory ProfileModel.fromJson(Map json) => _$ProfileModelFromJson(json); +} + +@freezed +class Circumference with _$Circumference { + const factory Circumference({ + @JsonKey(name: "id") required int id, + @JsonKey(name: "user_id") required int userId, + @JsonKey(name: "chest_circumference") required int chestCircumference, + @JsonKey(name: "waist_circumference") required int waistCircumference, + @JsonKey(name: "hip_circumference") required int hipCircumference, + @JsonKey(name: "created_at") required DateTime createdAt, + @JsonKey(name: "updated_at") required DateTime updatedAt, + }) = _Circumference; + + factory Circumference.fromJson(Map json) => _$CircumferenceFromJson(json); } @freezed @@ -41,7 +55,7 @@ class User with _$User { @JsonKey(name: "detailz") required UserDetails detailz, }) = _User; - factory User.fromJson(Map json) => _$UserFromJson(json); + factory User.fromJson(Map json) => _$UserFromJson(json); } @freezed @@ -78,5 +92,5 @@ class UserDetails with _$UserDetails { @JsonKey(name: "activity_coefficient") required double activityCoefficient, }) = _UserDetails; - factory UserDetails.fromJson(Map json) => _$UserDetailsFromJson(json); + factory UserDetails.fromJson(Map json) => _$UserDetailsFromJson(json); } diff --git a/lib/features/profile/models/profile_model.freezed.dart b/lib/features/profile/models/profile_model.freezed.dart index bd65ac7b..29d3b3c4 100644 --- a/lib/features/profile/models/profile_model.freezed.dart +++ b/lib/features/profile/models/profile_model.freezed.dart @@ -14,12 +14,12 @@ T _$identity(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'); -Profile _$ProfileFromJson(Map json) { - return _Profile.fromJson(json); +ProfileModel _$ProfileModelFromJson(Map json) { + return _ProfileModel.fromJson(json); } /// @nodoc -mixin _$Profile { +mixin _$ProfileModel { @JsonKey(name: "user") User get user => throw _privateConstructorUsedError; @JsonKey(name: "chartPoints") @@ -27,7 +27,7 @@ mixin _$Profile { @JsonKey(name: "userDetails") UserDetails get userDetails => throw _privateConstructorUsedError; @JsonKey(name: "circumferences") - List get circumferences => throw _privateConstructorUsedError; + List get circumferences => throw _privateConstructorUsedError; @JsonKey(name: "finishedPlans") List get finishedPlans => throw _privateConstructorUsedError; @JsonKey(name: "rejectedPlans") @@ -43,19 +43,21 @@ mixin _$Profile { Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) - $ProfileCopyWith get copyWith => throw _privateConstructorUsedError; + $ProfileModelCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc -abstract class $ProfileCopyWith<$Res> { - factory $ProfileCopyWith(Profile value, $Res Function(Profile) then) = - _$ProfileCopyWithImpl<$Res, Profile>; +abstract class $ProfileModelCopyWith<$Res> { + factory $ProfileModelCopyWith( + ProfileModel value, $Res Function(ProfileModel) then) = + _$ProfileModelCopyWithImpl<$Res, ProfileModel>; @useResult $Res call( {@JsonKey(name: "user") User user, @JsonKey(name: "chartPoints") List chartPoints, @JsonKey(name: "userDetails") UserDetails userDetails, - @JsonKey(name: "circumferences") List circumferences, + @JsonKey(name: "circumferences") List circumferences, @JsonKey(name: "finishedPlans") List finishedPlans, @JsonKey(name: "rejectedPlans") List rejectedPlans, @JsonKey(name: "startedPlan") List startedPlan, @@ -68,9 +70,9 @@ abstract class $ProfileCopyWith<$Res> { } /// @nodoc -class _$ProfileCopyWithImpl<$Res, $Val extends Profile> - implements $ProfileCopyWith<$Res> { - _$ProfileCopyWithImpl(this._value, this._then); +class _$ProfileModelCopyWithImpl<$Res, $Val extends ProfileModel> + implements $ProfileModelCopyWith<$Res> { + _$ProfileModelCopyWithImpl(this._value, this._then); // ignore: unused_field final $Val _value; @@ -107,7 +109,7 @@ class _$ProfileCopyWithImpl<$Res, $Val extends Profile> circumferences: null == circumferences ? _value.circumferences : circumferences // ignore: cast_nullable_to_non_nullable - as List, + as List, finishedPlans: null == finishedPlans ? _value.finishedPlans : finishedPlans // ignore: cast_nullable_to_non_nullable @@ -153,17 +155,18 @@ class _$ProfileCopyWithImpl<$Res, $Val extends Profile> } /// @nodoc -abstract class _$$ProfileImplCopyWith<$Res> implements $ProfileCopyWith<$Res> { - factory _$$ProfileImplCopyWith( - _$ProfileImpl value, $Res Function(_$ProfileImpl) then) = - __$$ProfileImplCopyWithImpl<$Res>; +abstract class _$$ProfileModelImplCopyWith<$Res> + implements $ProfileModelCopyWith<$Res> { + factory _$$ProfileModelImplCopyWith( + _$ProfileModelImpl value, $Res Function(_$ProfileModelImpl) then) = + __$$ProfileModelImplCopyWithImpl<$Res>; @override @useResult $Res call( {@JsonKey(name: "user") User user, @JsonKey(name: "chartPoints") List chartPoints, @JsonKey(name: "userDetails") UserDetails userDetails, - @JsonKey(name: "circumferences") List circumferences, + @JsonKey(name: "circumferences") List circumferences, @JsonKey(name: "finishedPlans") List finishedPlans, @JsonKey(name: "rejectedPlans") List rejectedPlans, @JsonKey(name: "startedPlan") List startedPlan, @@ -178,11 +181,11 @@ abstract class _$$ProfileImplCopyWith<$Res> implements $ProfileCopyWith<$Res> { } /// @nodoc -class __$$ProfileImplCopyWithImpl<$Res> - extends _$ProfileCopyWithImpl<$Res, _$ProfileImpl> - implements _$$ProfileImplCopyWith<$Res> { - __$$ProfileImplCopyWithImpl( - _$ProfileImpl _value, $Res Function(_$ProfileImpl) _then) +class __$$ProfileModelImplCopyWithImpl<$Res> + extends _$ProfileModelCopyWithImpl<$Res, _$ProfileModelImpl> + implements _$$ProfileModelImplCopyWith<$Res> { + __$$ProfileModelImplCopyWithImpl( + _$ProfileModelImpl _value, $Res Function(_$ProfileModelImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -199,7 +202,7 @@ class __$$ProfileImplCopyWithImpl<$Res> Object? requestedPlan = null, Object? initedPlan = null, }) { - return _then(_$ProfileImpl( + return _then(_$ProfileModelImpl( user: null == user ? _value.user : user // ignore: cast_nullable_to_non_nullable @@ -215,7 +218,7 @@ class __$$ProfileImplCopyWithImpl<$Res> circumferences: null == circumferences ? _value._circumferences : circumferences // ignore: cast_nullable_to_non_nullable - as List, + as List, finishedPlans: null == finishedPlans ? _value._finishedPlans : finishedPlans // ignore: cast_nullable_to_non_nullable @@ -246,13 +249,13 @@ class __$$ProfileImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$ProfileImpl implements _Profile { - const _$ProfileImpl( +class _$ProfileModelImpl implements _ProfileModel { + const _$ProfileModelImpl( {@JsonKey(name: "user") required this.user, @JsonKey(name: "chartPoints") required final List chartPoints, @JsonKey(name: "userDetails") required this.userDetails, @JsonKey(name: "circumferences") - required final List circumferences, + required final List circumferences, @JsonKey(name: "finishedPlans") required final List finishedPlans, @JsonKey(name: "rejectedPlans") @@ -271,8 +274,8 @@ class _$ProfileImpl implements _Profile { _requestedPlan = requestedPlan, _initedPlan = initedPlan; - factory _$ProfileImpl.fromJson(Map json) => - _$$ProfileImplFromJson(json); + factory _$ProfileModelImpl.fromJson(Map json) => + _$$ProfileModelImplFromJson(json); @override @JsonKey(name: "user") @@ -289,10 +292,10 @@ class _$ProfileImpl implements _Profile { @override @JsonKey(name: "userDetails") final UserDetails userDetails; - final List _circumferences; + final List _circumferences; @override @JsonKey(name: "circumferences") - List get circumferences { + List get circumferences { if (_circumferences is EqualUnmodifiableListView) return _circumferences; // ignore: implicit_dynamic_type return EqualUnmodifiableListView(_circumferences); @@ -354,14 +357,14 @@ class _$ProfileImpl implements _Profile { @override String toString() { - return 'Profile(user: $user, chartPoints: $chartPoints, userDetails: $userDetails, circumferences: $circumferences, finishedPlans: $finishedPlans, rejectedPlans: $rejectedPlans, startedPlan: $startedPlan, paidPlan: $paidPlan, requestedPlan: $requestedPlan, initedPlan: $initedPlan)'; + return 'ProfileModel(user: $user, chartPoints: $chartPoints, userDetails: $userDetails, circumferences: $circumferences, finishedPlans: $finishedPlans, rejectedPlans: $rejectedPlans, startedPlan: $startedPlan, paidPlan: $paidPlan, requestedPlan: $requestedPlan, initedPlan: $initedPlan)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$ProfileImpl && + other is _$ProfileModelImpl && (identical(other.user, user) || other.user == user) && const DeepCollectionEquality() .equals(other._chartPoints, _chartPoints) && @@ -400,24 +403,24 @@ class _$ProfileImpl implements _Profile { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$ProfileImplCopyWith<_$ProfileImpl> get copyWith => - __$$ProfileImplCopyWithImpl<_$ProfileImpl>(this, _$identity); + _$$ProfileModelImplCopyWith<_$ProfileModelImpl> get copyWith => + __$$ProfileModelImplCopyWithImpl<_$ProfileModelImpl>(this, _$identity); @override Map toJson() { - return _$$ProfileImplToJson( + return _$$ProfileModelImplToJson( this, ); } } -abstract class _Profile implements Profile { - const factory _Profile( +abstract class _ProfileModel implements ProfileModel { + const factory _ProfileModel( {@JsonKey(name: "user") required final User user, @JsonKey(name: "chartPoints") required final List chartPoints, @JsonKey(name: "userDetails") required final UserDetails userDetails, @JsonKey(name: "circumferences") - required final List circumferences, + required final List circumferences, @JsonKey(name: "finishedPlans") required final List finishedPlans, @JsonKey(name: "rejectedPlans") @@ -427,9 +430,10 @@ abstract class _Profile implements Profile { @JsonKey(name: "requestedPlan") required final List requestedPlan, @JsonKey(name: "initedPlan") - required final List initedPlan}) = _$ProfileImpl; + required final List initedPlan}) = _$ProfileModelImpl; - factory _Profile.fromJson(Map json) = _$ProfileImpl.fromJson; + factory _ProfileModel.fromJson(Map json) = + _$ProfileModelImpl.fromJson; @override @JsonKey(name: "user") @@ -442,7 +446,7 @@ abstract class _Profile implements Profile { UserDetails get userDetails; @override @JsonKey(name: "circumferences") - List get circumferences; + List get circumferences; @override @JsonKey(name: "finishedPlans") List get finishedPlans; @@ -463,7 +467,297 @@ abstract class _Profile implements Profile { List get initedPlan; @override @JsonKey(ignore: true) - _$$ProfileImplCopyWith<_$ProfileImpl> get copyWith => + _$$ProfileModelImplCopyWith<_$ProfileModelImpl> get copyWith => + throw _privateConstructorUsedError; +} + +Circumference _$CircumferenceFromJson(Map json) { + return _Circumference.fromJson(json); +} + +/// @nodoc +mixin _$Circumference { + @JsonKey(name: "id") + int get id => throw _privateConstructorUsedError; + @JsonKey(name: "user_id") + int get userId => throw _privateConstructorUsedError; + @JsonKey(name: "chest_circumference") + int get chestCircumference => throw _privateConstructorUsedError; + @JsonKey(name: "waist_circumference") + int get waistCircumference => throw _privateConstructorUsedError; + @JsonKey(name: "hip_circumference") + int get hipCircumference => throw _privateConstructorUsedError; + @JsonKey(name: "created_at") + DateTime get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: "updated_at") + DateTime get updatedAt => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $CircumferenceCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CircumferenceCopyWith<$Res> { + factory $CircumferenceCopyWith( + Circumference value, $Res Function(Circumference) then) = + _$CircumferenceCopyWithImpl<$Res, Circumference>; + @useResult + $Res call( + {@JsonKey(name: "id") int id, + @JsonKey(name: "user_id") int userId, + @JsonKey(name: "chest_circumference") int chestCircumference, + @JsonKey(name: "waist_circumference") int waistCircumference, + @JsonKey(name: "hip_circumference") int hipCircumference, + @JsonKey(name: "created_at") DateTime createdAt, + @JsonKey(name: "updated_at") DateTime updatedAt}); +} + +/// @nodoc +class _$CircumferenceCopyWithImpl<$Res, $Val extends Circumference> + implements $CircumferenceCopyWith<$Res> { + _$CircumferenceCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? userId = null, + Object? chestCircumference = null, + Object? waistCircumference = null, + Object? hipCircumference = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + userId: null == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int, + chestCircumference: null == chestCircumference + ? _value.chestCircumference + : chestCircumference // ignore: cast_nullable_to_non_nullable + as int, + waistCircumference: null == waistCircumference + ? _value.waistCircumference + : waistCircumference // ignore: cast_nullable_to_non_nullable + as int, + hipCircumference: null == hipCircumference + ? _value.hipCircumference + : hipCircumference // ignore: cast_nullable_to_non_nullable + as int, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as DateTime, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as DateTime, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$CircumferenceImplCopyWith<$Res> + implements $CircumferenceCopyWith<$Res> { + factory _$$CircumferenceImplCopyWith( + _$CircumferenceImpl value, $Res Function(_$CircumferenceImpl) then) = + __$$CircumferenceImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: "id") int id, + @JsonKey(name: "user_id") int userId, + @JsonKey(name: "chest_circumference") int chestCircumference, + @JsonKey(name: "waist_circumference") int waistCircumference, + @JsonKey(name: "hip_circumference") int hipCircumference, + @JsonKey(name: "created_at") DateTime createdAt, + @JsonKey(name: "updated_at") DateTime updatedAt}); +} + +/// @nodoc +class __$$CircumferenceImplCopyWithImpl<$Res> + extends _$CircumferenceCopyWithImpl<$Res, _$CircumferenceImpl> + implements _$$CircumferenceImplCopyWith<$Res> { + __$$CircumferenceImplCopyWithImpl( + _$CircumferenceImpl _value, $Res Function(_$CircumferenceImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? userId = null, + Object? chestCircumference = null, + Object? waistCircumference = null, + Object? hipCircumference = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then(_$CircumferenceImpl( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + userId: null == userId + ? _value.userId + : userId // ignore: cast_nullable_to_non_nullable + as int, + chestCircumference: null == chestCircumference + ? _value.chestCircumference + : chestCircumference // ignore: cast_nullable_to_non_nullable + as int, + waistCircumference: null == waistCircumference + ? _value.waistCircumference + : waistCircumference // ignore: cast_nullable_to_non_nullable + as int, + hipCircumference: null == hipCircumference + ? _value.hipCircumference + : hipCircumference // ignore: cast_nullable_to_non_nullable + as int, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as DateTime, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as DateTime, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$CircumferenceImpl implements _Circumference { + const _$CircumferenceImpl( + {@JsonKey(name: "id") required this.id, + @JsonKey(name: "user_id") required this.userId, + @JsonKey(name: "chest_circumference") required this.chestCircumference, + @JsonKey(name: "waist_circumference") required this.waistCircumference, + @JsonKey(name: "hip_circumference") required this.hipCircumference, + @JsonKey(name: "created_at") required this.createdAt, + @JsonKey(name: "updated_at") required this.updatedAt}); + + factory _$CircumferenceImpl.fromJson(Map json) => + _$$CircumferenceImplFromJson(json); + + @override + @JsonKey(name: "id") + final int id; + @override + @JsonKey(name: "user_id") + final int userId; + @override + @JsonKey(name: "chest_circumference") + final int chestCircumference; + @override + @JsonKey(name: "waist_circumference") + final int waistCircumference; + @override + @JsonKey(name: "hip_circumference") + final int hipCircumference; + @override + @JsonKey(name: "created_at") + final DateTime createdAt; + @override + @JsonKey(name: "updated_at") + final DateTime updatedAt; + + @override + String toString() { + return 'Circumference(id: $id, userId: $userId, chestCircumference: $chestCircumference, waistCircumference: $waistCircumference, hipCircumference: $hipCircumference, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$CircumferenceImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.userId, userId) || other.userId == userId) && + (identical(other.chestCircumference, chestCircumference) || + other.chestCircumference == chestCircumference) && + (identical(other.waistCircumference, waistCircumference) || + other.waistCircumference == waistCircumference) && + (identical(other.hipCircumference, hipCircumference) || + other.hipCircumference == hipCircumference) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.updatedAt, updatedAt) || + other.updatedAt == updatedAt)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, userId, chestCircumference, + waistCircumference, hipCircumference, createdAt, updatedAt); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$CircumferenceImplCopyWith<_$CircumferenceImpl> get copyWith => + __$$CircumferenceImplCopyWithImpl<_$CircumferenceImpl>(this, _$identity); + + @override + Map toJson() { + return _$$CircumferenceImplToJson( + this, + ); + } +} + +abstract class _Circumference implements Circumference { + const factory _Circumference( + {@JsonKey(name: "id") required final int id, + @JsonKey(name: "user_id") required final int userId, + @JsonKey(name: "chest_circumference") + required final int chestCircumference, + @JsonKey(name: "waist_circumference") + required final int waistCircumference, + @JsonKey(name: "hip_circumference") required final int hipCircumference, + @JsonKey(name: "created_at") required final DateTime createdAt, + @JsonKey(name: "updated_at") + required final DateTime updatedAt}) = _$CircumferenceImpl; + + factory _Circumference.fromJson(Map json) = + _$CircumferenceImpl.fromJson; + + @override + @JsonKey(name: "id") + int get id; + @override + @JsonKey(name: "user_id") + int get userId; + @override + @JsonKey(name: "chest_circumference") + int get chestCircumference; + @override + @JsonKey(name: "waist_circumference") + int get waistCircumference; + @override + @JsonKey(name: "hip_circumference") + int get hipCircumference; + @override + @JsonKey(name: "created_at") + DateTime get createdAt; + @override + @JsonKey(name: "updated_at") + DateTime get updatedAt; + @override + @JsonKey(ignore: true) + _$$CircumferenceImplCopyWith<_$CircumferenceImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/lib/features/profile/models/profile_model.g.dart b/lib/features/profile/models/profile_model.g.dart index e7943fdf..7197b817 100644 --- a/lib/features/profile/models/profile_model.g.dart +++ b/lib/features/profile/models/profile_model.g.dart @@ -6,13 +6,15 @@ part of 'profile_model.dart'; // JsonSerializableGenerator // ************************************************************************** -_$ProfileImpl _$$ProfileImplFromJson(Map json) => - _$ProfileImpl( +_$ProfileModelImpl _$$ProfileModelImplFromJson(Map json) => + _$ProfileModelImpl( user: User.fromJson(json['user'] as Map), chartPoints: json['chartPoints'] as List, userDetails: UserDetails.fromJson(json['userDetails'] as Map), - circumferences: json['circumferences'] as List, + circumferences: (json['circumferences'] as List) + .map((e) => Circumference.fromJson(e as Map)) + .toList(), finishedPlans: json['finishedPlans'] as List, rejectedPlans: json['rejectedPlans'] as List, startedPlan: json['startedPlan'] as List, @@ -21,7 +23,7 @@ _$ProfileImpl _$$ProfileImplFromJson(Map json) => initedPlan: json['initedPlan'] as List, ); -Map _$$ProfileImplToJson(_$ProfileImpl instance) => +Map _$$ProfileModelImplToJson(_$ProfileModelImpl instance) => { 'user': instance.user, 'chartPoints': instance.chartPoints, @@ -35,6 +37,28 @@ Map _$$ProfileImplToJson(_$ProfileImpl instance) => 'initedPlan': instance.initedPlan, }; +_$CircumferenceImpl _$$CircumferenceImplFromJson(Map json) => + _$CircumferenceImpl( + id: (json['id'] as num).toInt(), + userId: (json['user_id'] as num).toInt(), + chestCircumference: (json['chest_circumference'] as num).toInt(), + waistCircumference: (json['waist_circumference'] as num).toInt(), + hipCircumference: (json['hip_circumference'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + ); + +Map _$$CircumferenceImplToJson(_$CircumferenceImpl instance) => + { + 'id': instance.id, + 'user_id': instance.userId, + 'chest_circumference': instance.chestCircumference, + 'waist_circumference': instance.waistCircumference, + 'hip_circumference': instance.hipCircumference, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + }; + _$UserImpl _$$UserImplFromJson(Map json) => _$UserImpl( id: (json['id'] as num).toInt(), name: json['name'] as String, diff --git a/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart b/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart index 452c1895..a1ee1be7 100644 --- a/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart +++ b/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart @@ -5,11 +5,26 @@ import 'package:eatvio_app/features/profile/repositories/profile_repository.dart class ProfileCubit extends Cubit { final ProfileRepository profileRepository; - ProfileCubit({required this.profileRepository}) : super(const ProfileState.loading()); + ProfileCubit({ + required this.profileRepository, + }) : super(const ProfileState.loading()); getProfileBySlug(String slug) async { try { - emit(ProfileState.loaded(profile: await profileRepository.getProfileBySlug(slug))); + emit(ProfileState.loaded( + profile: await profileRepository.getProfileBySlug(slug), + )); + } catch (e) { + emit(ProfileState.error(errorMessage: e.toString())); + print(e); + } + } + + getMyProfile() async { + try { + emit(ProfileState.loaded( + profile: await profileRepository.getMyProfile(), + )); } catch (e) { emit(ProfileState.error(errorMessage: e.toString())); print(e); diff --git a/lib/features/profile/presentation/bloc/profile_cubit/profile_state.dart b/lib/features/profile/presentation/bloc/profile_cubit/profile_state.dart index 1b6ee5ad..1f06bfe4 100644 --- a/lib/features/profile/presentation/bloc/profile_cubit/profile_state.dart +++ b/lib/features/profile/presentation/bloc/profile_cubit/profile_state.dart @@ -10,7 +10,7 @@ abstract class ProfileState with _$ProfileState { const factory ProfileState.loading() = ProfileStateLoading; const factory ProfileState.loaded({ - required Profile profile, + required ProfileModel profile, }) = ProfileStateLoaded; const factory ProfileState.error({ diff --git a/lib/features/profile/presentation/bloc/profile_cubit/profile_state.freezed.dart b/lib/features/profile/presentation/bloc/profile_cubit/profile_state.freezed.dart index f36c6545..2658d2e2 100644 --- a/lib/features/profile/presentation/bloc/profile_cubit/profile_state.freezed.dart +++ b/lib/features/profile/presentation/bloc/profile_cubit/profile_state.freezed.dart @@ -20,7 +20,7 @@ mixin _$ProfileState { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Profile profile) loaded, + required TResult Function(ProfileModel profile) loaded, required TResult Function(String errorMessage) error, }) => throw _privateConstructorUsedError; @@ -28,7 +28,7 @@ mixin _$ProfileState { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Profile profile)? loaded, + TResult? Function(ProfileModel profile)? loaded, TResult? Function(String errorMessage)? error, }) => throw _privateConstructorUsedError; @@ -36,7 +36,7 @@ mixin _$ProfileState { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Profile profile)? loaded, + TResult Function(ProfileModel profile)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) => @@ -126,7 +126,7 @@ class _$ProfileStateImpl implements _ProfileState { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Profile profile) loaded, + required TResult Function(ProfileModel profile) loaded, required TResult Function(String errorMessage) error, }) { return $default(); @@ -137,7 +137,7 @@ class _$ProfileStateImpl implements _ProfileState { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Profile profile)? loaded, + TResult? Function(ProfileModel profile)? loaded, TResult? Function(String errorMessage)? error, }) { return $default?.call(); @@ -148,7 +148,7 @@ class _$ProfileStateImpl implements _ProfileState { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Profile profile)? loaded, + TResult Function(ProfileModel profile)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { @@ -241,7 +241,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Profile profile) loaded, + required TResult Function(ProfileModel profile) loaded, required TResult Function(String errorMessage) error, }) { return loading(); @@ -252,7 +252,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Profile profile)? loaded, + TResult? Function(ProfileModel profile)? loaded, TResult? Function(String errorMessage)? error, }) { return loading?.call(); @@ -263,7 +263,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Profile profile)? loaded, + TResult Function(ProfileModel profile)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { @@ -321,9 +321,9 @@ abstract class _$$ProfileStateLoadedImplCopyWith<$Res> { $Res Function(_$ProfileStateLoadedImpl) then) = __$$ProfileStateLoadedImplCopyWithImpl<$Res>; @useResult - $Res call({Profile profile}); + $Res call({ProfileModel profile}); - $ProfileCopyWith<$Res> get profile; + $ProfileModelCopyWith<$Res> get profile; } /// @nodoc @@ -343,14 +343,14 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res> profile: null == profile ? _value.profile : profile // ignore: cast_nullable_to_non_nullable - as Profile, + as ProfileModel, )); } @override @pragma('vm:prefer-inline') - $ProfileCopyWith<$Res> get profile { - return $ProfileCopyWith<$Res>(_value.profile, (value) { + $ProfileModelCopyWith<$Res> get profile { + return $ProfileModelCopyWith<$Res>(_value.profile, (value) { return _then(_value.copyWith(profile: value)); }); } @@ -362,7 +362,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded { const _$ProfileStateLoadedImpl({required this.profile}); @override - final Profile profile; + final ProfileModel profile; @override String toString() { @@ -392,7 +392,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Profile profile) loaded, + required TResult Function(ProfileModel profile) loaded, required TResult Function(String errorMessage) error, }) { return loaded(profile); @@ -403,7 +403,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Profile profile)? loaded, + TResult? Function(ProfileModel profile)? loaded, TResult? Function(String errorMessage)? error, }) { return loaded?.call(profile); @@ -414,7 +414,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Profile profile)? loaded, + TResult Function(ProfileModel profile)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { @@ -463,10 +463,10 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded { } abstract class ProfileStateLoaded implements ProfileState { - const factory ProfileStateLoaded({required final Profile profile}) = + const factory ProfileStateLoaded({required final ProfileModel profile}) = _$ProfileStateLoadedImpl; - Profile get profile; + ProfileModel get profile; @JsonKey(ignore: true) _$$ProfileStateLoadedImplCopyWith<_$ProfileStateLoadedImpl> get copyWith => throw _privateConstructorUsedError; @@ -540,7 +540,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Profile profile) loaded, + required TResult Function(ProfileModel profile) loaded, required TResult Function(String errorMessage) error, }) { return error(errorMessage); @@ -551,7 +551,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Profile profile)? loaded, + TResult? Function(ProfileModel profile)? loaded, TResult? Function(String errorMessage)? error, }) { return error?.call(errorMessage); @@ -562,7 +562,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Profile profile)? loaded, + TResult Function(ProfileModel profile)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { diff --git a/lib/features/profile/repositories/profile_repository.dart b/lib/features/profile/repositories/profile_repository.dart index af15d704..b9dbdf1e 100644 --- a/lib/features/profile/repositories/profile_repository.dart +++ b/lib/features/profile/repositories/profile_repository.dart @@ -6,11 +6,19 @@ class ProfileRepository { ProfileRepository({required this.profileService}); - Future getProfileBySlug(String slug) async { + Future getProfileBySlug(String slug) async { try { return await profileService.getProfileBySlug(slug: slug); } catch (e) { rethrow; } } + + Future getMyProfile() async { + try { + return await profileService.getMyProfile(); + } catch (e) { + rethrow; + } + } } diff --git a/lib/features/profile/services/profile_service.dart b/lib/features/profile/services/profile_service.dart index e9863ca2..5f5657b9 100644 --- a/lib/features/profile/services/profile_service.dart +++ b/lib/features/profile/services/profile_service.dart @@ -9,7 +9,10 @@ abstract class ProfileService { factory ProfileService(Dio dio, {String baseUrl}) = _ProfileService; @GET('/api/profile/show/{slug}') - Future getProfileBySlug({ + Future getProfileBySlug({ @Path() required String slug, }); + + @GET('/api/profile/index') + Future getMyProfile(); } diff --git a/lib/features/profile/services/profile_service.g.dart b/lib/features/profile/services/profile_service.g.dart index 79ebdb24..bc096fdf 100644 --- a/lib/features/profile/services/profile_service.g.dart +++ b/lib/features/profile/services/profile_service.g.dart @@ -22,12 +22,12 @@ class _ProfileService implements ProfileService { final ParseErrorLogger? errorLogger; @override - Future getProfileBySlug({required String slug}) async { + Future getProfileBySlug({required String slug}) async { final _extra = {}; final queryParameters = {}; final _headers = {}; const Map? _data = null; - final _options = _setStreamType(Options( + final _options = _setStreamType(Options( method: 'GET', headers: _headers, extra: _extra, @@ -44,9 +44,42 @@ class _ProfileService implements ProfileService { baseUrl, ))); final _result = await _dio.fetch>(_options); - late Profile _value; + late ProfileModel _value; try { - _value = Profile.fromJson(_result.data!); + _value = ProfileModel.fromJson(_result.data!); + } on Object catch (e, s) { + errorLogger?.logError(e, s, _options); + rethrow; + } + return _value; + } + + @override + Future getMyProfile() async { + final _extra = {}; + final queryParameters = {}; + final _headers = {}; + const Map? _data = null; + final _options = _setStreamType(Options( + method: 'GET', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/api/profile/index', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ))); + final _result = await _dio.fetch>(_options); + late ProfileModel _value; + try { + _value = ProfileModel.fromJson(_result.data!); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow;