feat(feed): add comments to recipes and diets

This commit is contained in:
mso7nueh
2024-08-23 11:45:24 +03:00
parent 9f2cc55111
commit 177b815820
51 changed files with 2337 additions and 529 deletions

View File

@@ -18,6 +18,24 @@ class CommentsCubit extends Cubit<CommentsState> {
}
}
getRecipesComments(String id) async {
emit(CommentsState.loading());
try {
emit(CommentsState.loaded(comment: await feedRepository.getRecipesComments(id)));
} catch (e) {
emit(CommentsState.error(errorMessage: e.toString()));
}
}
getDietsComments(int id) async {
emit(CommentsState.loading());
try {
emit(CommentsState.loaded(comment: await feedRepository.getDietsComments(id)));
} catch (e) {
emit(CommentsState.error(errorMessage: e.toString()));
}
}
sendBlogPostComment({
required int id,
required String commentText,
@@ -34,4 +52,38 @@ class CommentsCubit extends Cubit<CommentsState> {
emit(CommentsState.error(errorMessage: e.toString()));
}
}
sendRecipesComment({
required String id,
required String commentText,
int? parentCommentId,
}) async {
try {
await feedRepository.sendRecipesComment(
id: id,
commentText: commentText,
parentCommentId: parentCommentId,
);
emit(CommentsState.loaded(comment: await feedRepository.getRecipesComments(id)));
} catch (e) {
emit(CommentsState.error(errorMessage: e.toString()));
}
}
sendDietsComment({
required int id,
required String commentText,
int? parentCommentId,
}) async {
try {
await feedRepository.sendDietsComment(
id: id,
commentText: commentText,
parentCommentId: parentCommentId,
);
emit(CommentsState.loaded(comment: await feedRepository.getDietsComments(id)));
} catch (e) {
emit(CommentsState.error(errorMessage: e.toString()));
}
}
}

View File

@@ -84,6 +84,9 @@ class _$CommentsStateCopyWithImpl<$Res, $Val extends CommentsState>
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -100,6 +103,9 @@ class __$$CommentsStateImplCopyWithImpl<$Res>
__$$CommentsStateImplCopyWithImpl(
_$CommentsStateImpl _value, $Res Function(_$CommentsStateImpl) _then)
: super(_value, _then);
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -214,6 +220,9 @@ class __$$CommentsStateLoadingImplCopyWithImpl<$Res>
__$$CommentsStateLoadingImplCopyWithImpl(_$CommentsStateLoadingImpl _value,
$Res Function(_$CommentsStateLoadingImpl) _then)
: super(_value, _then);
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -334,6 +343,8 @@ class __$$CommentsStateLoadedImplCopyWithImpl<$Res>
$Res Function(_$CommentsStateLoadedImpl) _then)
: super(_value, _then);
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -347,6 +358,8 @@ class __$$CommentsStateLoadedImplCopyWithImpl<$Res>
));
}
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$CommentCopyWith<$Res> get comment {
@@ -380,7 +393,9 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded {
@override
int get hashCode => Object.hash(runtimeType, comment);
@JsonKey(ignore: true)
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CommentsStateLoadedImplCopyWith<_$CommentsStateLoadedImpl> get copyWith =>
@@ -467,7 +482,10 @@ abstract class CommentsStateLoaded implements CommentsState {
_$CommentsStateLoadedImpl;
Comment get comment;
@JsonKey(ignore: true)
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CommentsStateLoadedImplCopyWith<_$CommentsStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -489,6 +507,8 @@ class __$$CommentsStateErrorImplCopyWithImpl<$Res>
$Res Function(_$CommentsStateErrorImpl) _then)
: super(_value, _then);
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -528,7 +548,9 @@ class _$CommentsStateErrorImpl implements CommentsStateError {
@override
int get hashCode => Object.hash(runtimeType, errorMessage);
@JsonKey(ignore: true)
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CommentsStateErrorImplCopyWith<_$CommentsStateErrorImpl> get copyWith =>
@@ -615,7 +637,10 @@ abstract class CommentsStateError implements CommentsState {
_$CommentsStateErrorImpl;
String get errorMessage;
@JsonKey(ignore: true)
/// Create a copy of CommentsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CommentsStateErrorImplCopyWith<_$CommentsStateErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -84,6 +84,9 @@ class _$DietsStateCopyWithImpl<$Res, $Val extends DietsState>
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -100,6 +103,9 @@ class __$$DietsStateImplCopyWithImpl<$Res>
__$$DietsStateImplCopyWithImpl(
_$DietsStateImpl _value, $Res Function(_$DietsStateImpl) _then)
: super(_value, _then);
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -214,6 +220,9 @@ class __$$DietsStateLoadingImplCopyWithImpl<$Res>
__$$DietsStateLoadingImplCopyWithImpl(_$DietsStateLoadingImpl _value,
$Res Function(_$DietsStateLoadingImpl) _then)
: super(_value, _then);
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -333,6 +342,8 @@ class __$$DietsStateLoadedImplCopyWithImpl<$Res>
$Res Function(_$DietsStateLoadedImpl) _then)
: super(_value, _then);
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -346,6 +357,8 @@ class __$$DietsStateLoadedImplCopyWithImpl<$Res>
));
}
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$DietsPaginationCopyWith<$Res> get diets {
@@ -379,7 +392,9 @@ class _$DietsStateLoadedImpl implements DietsStateLoaded {
@override
int get hashCode => Object.hash(runtimeType, diets);
@JsonKey(ignore: true)
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$DietsStateLoadedImplCopyWith<_$DietsStateLoadedImpl> get copyWith =>
@@ -466,7 +481,10 @@ abstract class DietsStateLoaded implements DietsState {
_$DietsStateLoadedImpl;
DietsPagination get diets;
@JsonKey(ignore: true)
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$DietsStateLoadedImplCopyWith<_$DietsStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -488,6 +506,8 @@ class __$$DietsStateErrorImplCopyWithImpl<$Res>
_$DietsStateErrorImpl _value, $Res Function(_$DietsStateErrorImpl) _then)
: super(_value, _then);
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -527,7 +547,9 @@ class _$DietsStateErrorImpl implements DietsStateError {
@override
int get hashCode => Object.hash(runtimeType, errorMessage);
@JsonKey(ignore: true)
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$DietsStateErrorImplCopyWith<_$DietsStateErrorImpl> get copyWith =>
@@ -614,7 +636,10 @@ abstract class DietsStateError implements DietsState {
_$DietsStateErrorImpl;
String get errorMessage;
@JsonKey(ignore: true)
/// Create a copy of DietsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$DietsStateErrorImplCopyWith<_$DietsStateErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -87,6 +87,9 @@ class _$FeedStateCopyWithImpl<$Res, $Val extends FeedState>
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -103,6 +106,9 @@ class __$$FeedStateImplCopyWithImpl<$Res>
__$$FeedStateImplCopyWithImpl(
_$FeedStateImpl _value, $Res Function(_$FeedStateImpl) _then)
: super(_value, _then);
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -221,6 +227,9 @@ class __$$FeedStateLoadingImplCopyWithImpl<$Res>
__$$FeedStateLoadingImplCopyWithImpl(_$FeedStateLoadingImpl _value,
$Res Function(_$FeedStateLoadingImpl) _then)
: super(_value, _then);
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -342,6 +351,8 @@ class __$$FeedStateLoadedImplCopyWithImpl<$Res>
_$FeedStateLoadedImpl _value, $Res Function(_$FeedStateLoadedImpl) _then)
: super(_value, _then);
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -401,7 +412,9 @@ class _$FeedStateLoadedImpl implements FeedStateLoaded {
int get hashCode => Object.hash(runtimeType,
const DeepCollectionEquality().hash(_feedBlogPostList), isLoading);
@JsonKey(ignore: true)
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FeedStateLoadedImplCopyWith<_$FeedStateLoadedImpl> get copyWith =>
@@ -494,7 +507,10 @@ abstract class FeedStateLoaded implements FeedState {
List<FeedBlogPostModel> get feedBlogPostList;
bool get isLoading;
@JsonKey(ignore: true)
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FeedStateLoadedImplCopyWith<_$FeedStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -516,6 +532,8 @@ class __$$FeedStateErrorImplCopyWithImpl<$Res>
_$FeedStateErrorImpl _value, $Res Function(_$FeedStateErrorImpl) _then)
: super(_value, _then);
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -555,7 +573,9 @@ class _$FeedStateErrorImpl implements FeedStateError {
@override
int get hashCode => Object.hash(runtimeType, errorMessage);
@JsonKey(ignore: true)
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FeedStateErrorImplCopyWith<_$FeedStateErrorImpl> get copyWith =>
@@ -646,7 +666,10 @@ abstract class FeedStateError implements FeedState {
_$FeedStateErrorImpl;
String get errorMessage;
@JsonKey(ignore: true)
/// Create a copy of FeedState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FeedStateErrorImplCopyWith<_$FeedStateErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -84,6 +84,9 @@ class _$RecipesStateCopyWithImpl<$Res, $Val extends RecipesState>
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -100,6 +103,9 @@ class __$$RecipesStateImplCopyWithImpl<$Res>
__$$RecipesStateImplCopyWithImpl(
_$RecipesStateImpl _value, $Res Function(_$RecipesStateImpl) _then)
: super(_value, _then);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -214,6 +220,9 @@ class __$$RecipesStateLoadingImplCopyWithImpl<$Res>
__$$RecipesStateLoadingImplCopyWithImpl(_$RecipesStateLoadingImpl _value,
$Res Function(_$RecipesStateLoadingImpl) _then)
: super(_value, _then);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
@@ -332,6 +341,8 @@ class __$$RecipesStateLoadedImplCopyWithImpl<$Res>
$Res Function(_$RecipesStateLoadedImpl) _then)
: super(_value, _then);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -378,7 +389,9 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_recipesList));
@JsonKey(ignore: true)
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$RecipesStateLoadedImplCopyWith<_$RecipesStateLoadedImpl> get copyWith =>
@@ -465,7 +478,10 @@ abstract class RecipesStateLoaded implements RecipesState {
_$RecipesStateLoadedImpl;
List<Recipes> get recipesList;
@JsonKey(ignore: true)
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$RecipesStateLoadedImplCopyWith<_$RecipesStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -487,6 +503,8 @@ class __$$RecipesStateErrorImplCopyWithImpl<$Res>
$Res Function(_$RecipesStateErrorImpl) _then)
: super(_value, _then);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -526,7 +544,9 @@ class _$RecipesStateErrorImpl implements RecipesStateError {
@override
int get hashCode => Object.hash(runtimeType, errorMessage);
@JsonKey(ignore: true)
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$RecipesStateErrorImplCopyWith<_$RecipesStateErrorImpl> get copyWith =>
@@ -613,7 +633,10 @@ abstract class RecipesStateError implements RecipesState {
_$RecipesStateErrorImpl;
String get errorMessage;
@JsonKey(ignore: true)
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$RecipesStateErrorImplCopyWith<_$RecipesStateErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}