forked from eatvio/eatvio_app
added diet complaints and token interceptor for auth handling
This commit is contained in:
@@ -319,9 +319,11 @@ class _ViolenceAndHostilityState extends State<_ViolenceAndHostility> {
|
||||
});
|
||||
},
|
||||
),
|
||||
Text(
|
||||
element.$2,
|
||||
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
|
||||
Expanded(
|
||||
child: Text(
|
||||
element.$2,
|
||||
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -43,8 +43,11 @@ class ComplainingCubit extends Cubit<ComplainingState> {
|
||||
if (category != null && contentType != null) {
|
||||
switch (contentType) {
|
||||
case ComplainedContent.diet:
|
||||
emit(state.copyWith(wasSentSuccessfully: true));
|
||||
return;
|
||||
if (id != null) {
|
||||
await repository.sendDietComplain(id: id, category: category.getValue(), body: state.complainInfo);
|
||||
emit(state.copyWith(wasSentSuccessfully: true));
|
||||
return;
|
||||
}
|
||||
case ComplainedContent.plan:
|
||||
if (slug != null) {
|
||||
await repository.sendPlanComplain(slug: slug, category: category.getValue(), body: state.complainInfo);
|
||||
|
||||
@@ -11,7 +11,7 @@ class ComplainingRepository {
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
service.sendPlanComplain(slug: slug, category: category, body: body);
|
||||
await service.sendPlanComplain(slug: slug, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class ComplainingRepository {
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
service.sendRecipeComplain(slug: slug, category: category, body: body);
|
||||
await service.sendRecipeComplain(slug: slug, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class ComplainingRepository {
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
service.sendBlogPostsComplain(id: id, category: category, body: body);
|
||||
await service.sendBlogPostsComplain(id: id, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
@@ -47,7 +47,19 @@ class ComplainingRepository {
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
service.sendProfileComplain(slug: slug, category: category, body: body);
|
||||
await service.sendProfileComplain(slug: slug, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> sendDietComplain({
|
||||
required int id,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
await service.sendDietComplain(id: id, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
@@ -35,5 +35,12 @@ abstract class ComplainingService {
|
||||
@Path() required String category,
|
||||
@Body() required ComplainModel body,
|
||||
});
|
||||
|
||||
@POST('/api/diets/{id}/complain/{category}')
|
||||
Future<void> sendDietComplain({
|
||||
@Path() required int id,
|
||||
@Path() required String category,
|
||||
@Body() required ComplainModel body,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -109,6 +109,29 @@ class _ComplainingService implements ComplainingService {
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> sendDietComplain({
|
||||
required int id,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = body;
|
||||
final _options = _setStreamType<void>(
|
||||
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/diets/${id}/complain/${category}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
if (T != dynamic &&
|
||||
!(requestOptions.responseType == ResponseType.bytes ||
|
||||
|
||||
@@ -90,6 +90,7 @@ class MoreOptions extends StatelessWidget {
|
||||
if (complainedContentType != null) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => ComplainingBottomSheet(
|
||||
complainedContentType: complainedContentType!,
|
||||
id: id,
|
||||
|
||||
@@ -6,49 +6,57 @@ part of 'diets_pagination_model.dart';
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$DietsPaginationImpl _$$DietsPaginationImplFromJson(Map<String, dynamic> json) => _$DietsPaginationImpl(
|
||||
data: (json['data'] as List<dynamic>).map((e) => Diet.fromJson(e as Map<String, dynamic>)).toList(),
|
||||
_$DietsPaginationImpl _$$DietsPaginationImplFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$DietsPaginationImpl(
|
||||
data: (json['data'] as List<dynamic>)
|
||||
.map((e) => Diet.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
links: Links.fromJson(json['links'] as Map<String, dynamic>),
|
||||
meta: Meta.fromJson(json['meta'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$DietsPaginationImplToJson(_$DietsPaginationImpl instance) => <String, dynamic>{
|
||||
Map<String, dynamic> _$$DietsPaginationImplToJson(
|
||||
_$DietsPaginationImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'data': instance.data,
|
||||
'links': instance.links,
|
||||
'meta': instance.meta,
|
||||
};
|
||||
|
||||
_$DietImpl _$$DietImplFromJson(Map<String, dynamic> json) {
|
||||
return _$DietImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
name: json['name'] as String,
|
||||
image: json['image'] as String,
|
||||
duration: (json['duration'] as num).toInt(),
|
||||
state: $enumDecode(_$DietStateEnumMap, json['state']),
|
||||
type: DietType.fromJson(json['type'] as Map<String, dynamic>),
|
||||
details: json['details'] as String,
|
||||
dailySchedule: (json['daily_schedule'] as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(
|
||||
int.parse(k),
|
||||
(e as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(
|
||||
int.parse(k),
|
||||
(e as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(int.parse(k), DailySchedule.fromJson(e as Map<String, dynamic>)),
|
||||
)),
|
||||
)),
|
||||
),
|
||||
author: Author.fromJson(json['author'] as Map<String, dynamic>),
|
||||
totalLikes: (json['total_likes'] as num).toInt(),
|
||||
totalViews: (json['total_views'] as num).toInt(),
|
||||
totalComments: (json['total_comments'] as num).toInt(),
|
||||
wasLikedByMe: json['was_liked_by_me'] as bool,
|
||||
isFavorite: json['is_favorite'] as bool,
|
||||
dailyNutrition: (json['daily_nutrition'] as List<dynamic>).map((e) => DailyNutrition.fromJson(e as Map<String, dynamic>)).toList(),
|
||||
);
|
||||
}
|
||||
_$DietImpl _$$DietImplFromJson(Map<String, dynamic> json) => _$DietImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
name: json['name'] as String,
|
||||
image: json['image'] as String,
|
||||
duration: (json['duration'] as num).toInt(),
|
||||
state: $enumDecode(_$DietStateEnumMap, json['state']),
|
||||
type: DietType.fromJson(json['type'] as Map<String, dynamic>),
|
||||
details: json['details'] as String,
|
||||
dailySchedule: (json['daily_schedule'] as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(
|
||||
int.parse(k),
|
||||
(e as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(
|
||||
int.parse(k),
|
||||
(e as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(int.parse(k),
|
||||
DailySchedule.fromJson(e as Map<String, dynamic>)),
|
||||
)),
|
||||
)),
|
||||
),
|
||||
author: Author.fromJson(json['author'] as Map<String, dynamic>),
|
||||
totalLikes: (json['total_likes'] as num).toInt(),
|
||||
totalViews: (json['total_views'] as num).toInt(),
|
||||
totalComments: (json['total_comments'] as num).toInt(),
|
||||
wasLikedByMe: json['was_liked_by_me'] as bool,
|
||||
isFavorite: json['is_favorite'] as bool,
|
||||
dailyNutrition: (json['daily_nutrition'] as List<dynamic>)
|
||||
.map((e) => DailyNutrition.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$DietImplToJson(_$DietImpl instance) => <String, dynamic>{
|
||||
Map<String, dynamic> _$$DietImplToJson(_$DietImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'image': instance.image,
|
||||
@@ -56,8 +64,10 @@ Map<String, dynamic> _$$DietImplToJson(_$DietImpl instance) => <String, dynamic>
|
||||
'state': _$DietStateEnumMap[instance.state]!,
|
||||
'type': instance.type,
|
||||
'details': instance.details,
|
||||
'daily_schedule':
|
||||
instance.dailySchedule.map((k, e) => MapEntry(k.toString(), e.map((k, e) => MapEntry(k.toString(), e.map((k, e) => MapEntry(k.toString(), e)))))),
|
||||
'daily_schedule': instance.dailySchedule.map((k, e) => MapEntry(
|
||||
k.toString(),
|
||||
e.map((k, e) => MapEntry(
|
||||
k.toString(), e.map((k, e) => MapEntry(k.toString(), e)))))),
|
||||
'author': instance.author,
|
||||
'total_likes': instance.totalLikes,
|
||||
'total_views': instance.totalViews,
|
||||
@@ -73,11 +83,13 @@ const _$DietStateEnumMap = {
|
||||
DietState.personal: 'personal',
|
||||
};
|
||||
|
||||
_$CreatedDietImpl _$$CreatedDietImplFromJson(Map<String, dynamic> json) => _$CreatedDietImpl(
|
||||
_$CreatedDietImpl _$$CreatedDietImplFromJson(Map<String, dynamic> json) =>
|
||||
_$CreatedDietImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$CreatedDietImplToJson(_$CreatedDietImpl instance) => <String, dynamic>{
|
||||
Map<String, dynamic> _$$CreatedDietImplToJson(_$CreatedDietImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
};
|
||||
|
||||
@@ -90,7 +102,8 @@ _$AuthorImpl _$$AuthorImplFromJson(Map<String, dynamic> json) => _$AuthorImpl(
|
||||
authorPlaceInRating: (json['author_place_in_rating'] as num?)?.toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$AuthorImplToJson(_$AuthorImpl instance) => <String, dynamic>{
|
||||
Map<String, dynamic> _$$AuthorImplToJson(_$AuthorImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'author_slug': instance.authorSlug,
|
||||
'author_name': instance.authorName,
|
||||
'author_profile_icon': instance.authorProfileIcon,
|
||||
@@ -99,18 +112,23 @@ Map<String, dynamic> _$$AuthorImplToJson(_$AuthorImpl instance) => <String, dyna
|
||||
'author_place_in_rating': instance.authorPlaceInRating,
|
||||
};
|
||||
|
||||
_$DailyScheduleImpl _$$DailyScheduleImplFromJson(Map<String, dynamic> json) => _$DailyScheduleImpl(
|
||||
_$DailyScheduleImpl _$$DailyScheduleImplFromJson(Map<String, dynamic> json) =>
|
||||
_$DailyScheduleImpl(
|
||||
name: json['name'] as String,
|
||||
portion: $enumDecode(_$PortionEnumMap, json['portion']),
|
||||
quantity: _parseQuantity(json['quantity']),
|
||||
dailyNutrition: json['nutrition'] == null ? null : DailyNutrition.fromJson(json['nutrition'] as Map<String, dynamic>),
|
||||
dailyNutrition: json['nutrition'] == null
|
||||
? null
|
||||
: DailyNutrition.fromJson(json['nutrition'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$DailyScheduleImplToJson(_$DailyScheduleImpl instance) => <String, dynamic>{
|
||||
Map<String, dynamic> _$$DailyScheduleImplToJson(_$DailyScheduleImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'name': instance.name,
|
||||
'portion': _$PortionEnumMap[instance.portion]!,
|
||||
'quantity': instance.quantity,
|
||||
if (instance.productNutritionalValueId case final value?) 'product_nutritional_value_id': value,
|
||||
if (instance.productNutritionalValueId case final value?)
|
||||
'product_nutritional_value_id': value,
|
||||
};
|
||||
|
||||
const _$PortionEnumMap = {
|
||||
@@ -119,28 +137,33 @@ const _$PortionEnumMap = {
|
||||
Portion.PCS: 'pcs',
|
||||
};
|
||||
|
||||
_$DietTypeImpl _$$DietTypeImplFromJson(Map<String, dynamic> json) => _$DietTypeImpl(
|
||||
_$DietTypeImpl _$$DietTypeImplFromJson(Map<String, dynamic> json) =>
|
||||
_$DietTypeImpl(
|
||||
light: json['light'] as bool?,
|
||||
veg: json['veg'] as bool?,
|
||||
carb: json['carb'] as bool?,
|
||||
meat: json['meat'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$DietTypeImplToJson(_$DietTypeImpl instance) => <String, dynamic>{
|
||||
Map<String, dynamic> _$$DietTypeImplToJson(_$DietTypeImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'light': instance.light,
|
||||
'veg': instance.veg,
|
||||
'carb': instance.carb,
|
||||
'meat': instance.meat,
|
||||
};
|
||||
|
||||
_$DailyNutritionImpl _$$DailyNutritionImplFromJson(Map<String, dynamic> json) => _$DailyNutritionImpl(
|
||||
_$DailyNutritionImpl _$$DailyNutritionImplFromJson(Map<String, dynamic> json) =>
|
||||
_$DailyNutritionImpl(
|
||||
energy: (json['energy'] as num).toDouble(),
|
||||
proteins: (json['proteins'] as num).toDouble(),
|
||||
fats: (json['fats'] as num).toDouble(),
|
||||
carbohydrates: (json['carbohydrates'] as num).toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$DailyNutritionImplToJson(_$DailyNutritionImpl instance) => <String, dynamic>{
|
||||
Map<String, dynamic> _$$DailyNutritionImplToJson(
|
||||
_$DailyNutritionImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'energy': instance.energy,
|
||||
'proteins': instance.proteins,
|
||||
'fats': instance.fats,
|
||||
|
||||
@@ -1021,6 +1021,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
} else {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => ComplainingBottomSheet(
|
||||
complainedContentType: ComplainedContent.profile,
|
||||
slug: widget.author?.authorSlug,
|
||||
|
||||
Reference in New Issue
Block a user