This commit is contained in:
mso7nueh
2024-08-16 17:37:25 +03:00
parent f9da25df5a
commit 7128d4f2d6
3 changed files with 99 additions and 79 deletions

View File

@@ -1,15 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'image.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$ImageImpl _$$ImageImplFromJson(Map<String, dynamic> json) => _$ImageImpl(
path: json['path'] as String,
);
Map<String, dynamic> _$$ImageImplToJson(_$ImageImpl instance) => <String, dynamic>{
'path': instance.path,
};

View File

@@ -6,9 +6,16 @@ part of 'recipe_model.dart';
// JsonSerializableGenerator
// **************************************************************************
_$RecipeModelImpl _$$RecipeModelImplFromJson(Map<String, dynamic> json) => _$RecipeModelImpl(
ingredients: (json['ingredients'] as List<dynamic>?)?.map((e) => e == null ? null : Ingredient.fromJson(e as Map<String, dynamic>)).toList(),
steps: (json['steps'] as List<dynamic>?)?.map((e) => e == null ? null : Step.fromJson(e as Map<String, dynamic>)).toList(),
_$RecipeModelImpl _$$RecipeModelImplFromJson(Map<String, dynamic> json) =>
_$RecipeModelImpl(
ingredients: (json['ingredients'] as List<dynamic>?)
?.map((e) =>
e == null ? null : Ingredient.fromJson(e as Map<String, dynamic>))
.toList(),
steps: (json['steps'] as List<dynamic>?)
?.map((e) =>
e == null ? null : Step.fromJson(e as Map<String, dynamic>))
.toList(),
type: json['type'] as String?,
state: json['state'] as String?,
title: json['title'] as String?,
@@ -18,7 +25,8 @@ _$RecipeModelImpl _$$RecipeModelImplFromJson(Map<String, dynamic> json) => _$Rec
cooking_time: (json['cooking_time'] as num?)?.toInt(),
);
Map<String, dynamic> _$$RecipeModelImplToJson(_$RecipeModelImpl instance) => <String, dynamic>{
Map<String, dynamic> _$$RecipeModelImplToJson(_$RecipeModelImpl instance) =>
<String, dynamic>{
'ingredients': instance.ingredients,
'steps': instance.steps,
'type': instance.type,

View File

@@ -12,36 +12,45 @@ class _RecipeService implements RecipeService {
_RecipeService(
this._dio, {
this.baseUrl,
this.errorLogger,
});
final Dio _dio;
String? baseUrl;
final ParseErrorLogger? errorLogger;
@override
Future<RecipeModel> getRecipe(String id) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _result = await _dio
.fetch<Map<String, dynamic>>(_setStreamType<RecipeModel>(Options(
final _options = _setStreamType<RecipeModel>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/api/recipes/show/${id}',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
))));
final _value = RecipeModel.fromJson(_result.data!);
.compose(
_dio.options,
'/api/recipes/show/${id}',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late RecipeModel _value;
try {
_value = RecipeModel.fromJson(_result.data!);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
return _value;
}
@@ -51,28 +60,34 @@ class _RecipeService implements RecipeService {
final queryParameters = <String, dynamic>{r'name': name};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _result = await _dio.fetch<Map<String, dynamic>>(
_setStreamType<Map<String, List<Product>>>(Options(
final _options = _setStreamType<Map<String, List<Product>>>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/api/diary/product_nutritional_values/filter',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
))));
var _value = _result.data!.map((k, dynamic v) => MapEntry(
k,
(v as List)
.map((i) => Product.fromJson(i as Map<String, dynamic>))
.toList()));
.compose(
_dio.options,
'/api/diary/product_nutritional_values/filter',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late Map<String, List<Product>> _value;
try {
_value = _result.data!.map((k, dynamic v) => MapEntry(
k,
(v as List)
.map((i) => Product.fromJson(i as Map<String, dynamic>))
.toList()));
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
return _value;
}
@@ -82,24 +97,30 @@ class _RecipeService implements RecipeService {
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
final _data = FormData.fromMap(recipe);
final _result = await _dio
.fetch<Map<String, dynamic>>(_setStreamType<RecipeModel>(Options(
final _options = _setStreamType<RecipeModel>(Options(
method: 'POST',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/api/recipes/create',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
))));
final _value = RecipeModel.fromJson(_result.data!);
.compose(
_dio.options,
'/api/recipes/create',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late RecipeModel _value;
try {
_value = RecipeModel.fromJson(_result.data!);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
return _value;
}
@@ -112,24 +133,30 @@ class _RecipeService implements RecipeService {
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
final _data = FormData.fromMap(recipe);
final _result = await _dio
.fetch<Map<String, dynamic>>(_setStreamType<RecipeModel>(Options(
final _options = _setStreamType<RecipeModel>(Options(
method: 'POST',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/api/recipes/update/{id}',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
))));
final _value = RecipeModel.fromJson(_result.data!);
.compose(
_dio.options,
'/api/recipes/update/{id}',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late RecipeModel _value;
try {
_value = RecipeModel.fromJson(_result.data!);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
return _value;
}