added diet complaints and token interceptor for auth handling

This commit is contained in:
Username1548
2025-03-05 17:25:07 +07:00
parent 0c448240f2
commit ede59d0477
14 changed files with 180 additions and 112 deletions

View File

@@ -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),
),
),
],
);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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,
});
}

View File

@@ -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 ||