forked from eatvio/eatvio_app
233 lines
7.1 KiB
Dart
233 lines
7.1 KiB
Dart
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
|
|
part of 'recipe_service.dart';
|
|
|
|
// **************************************************************************
|
|
// RetrofitGenerator
|
|
// **************************************************************************
|
|
|
|
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers,unused_element,unnecessary_string_interpolations
|
|
|
|
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 _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 _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;
|
|
}
|
|
|
|
@override
|
|
Future<Map<String, List<Product>>> getInputProduct(String name) async {
|
|
final _extra = <String, dynamic>{};
|
|
final queryParameters = <String, dynamic>{r'name': name};
|
|
final _headers = <String, dynamic>{};
|
|
const Map<String, dynamic>? _data = null;
|
|
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)),
|
|
);
|
|
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;
|
|
}
|
|
|
|
@override
|
|
Future<RecipeModel> publishRecipe(
|
|
String? type,
|
|
String? state,
|
|
String? title,
|
|
String? description,
|
|
String? video_url,
|
|
List<Map<String, Object>> ingredients,
|
|
List<Map<String, Object>> steps,
|
|
int? cooking_time,
|
|
File image,
|
|
) async {
|
|
final _extra = <String, dynamic>{};
|
|
final queryParameters = <String, dynamic>{};
|
|
queryParameters.removeWhere((k, v) => v == null);
|
|
final _headers = <String, dynamic>{};
|
|
final _data = FormData();
|
|
if (type != null) {
|
|
_data.fields.add(MapEntry('type', type));
|
|
}
|
|
if (state != null) {
|
|
_data.fields.add(MapEntry('state', state));
|
|
}
|
|
if (title != null) {
|
|
_data.fields.add(MapEntry('title', title));
|
|
}
|
|
if (description != null) {
|
|
_data.fields.add(MapEntry('description', description));
|
|
}
|
|
if (video_url != null) {
|
|
_data.fields.add(MapEntry('video_url', video_url));
|
|
}
|
|
ingredients.forEach((i) {
|
|
_data.fields.add(MapEntry('ingredients', jsonEncode(i)));
|
|
});
|
|
steps.forEach((i) {
|
|
_data.fields.add(MapEntry('steps', jsonEncode(i)));
|
|
});
|
|
if (cooking_time != null) {
|
|
_data.fields.add(MapEntry('cooking_time', cooking_time.toString()));
|
|
}
|
|
_data.files.add(
|
|
MapEntry(
|
|
'image',
|
|
MultipartFile.fromFileSync(
|
|
image.path,
|
|
filename: image.path.split(Platform.pathSeparator).last,
|
|
),
|
|
),
|
|
);
|
|
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 _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;
|
|
}
|
|
|
|
@override
|
|
Future<RecipeModel> editRecipe(Map<String, Object?> recipe, String id) async {
|
|
final _extra = <String, dynamic>{};
|
|
final queryParameters = <String, dynamic>{};
|
|
final _headers = <String, dynamic>{};
|
|
final _data = FormData.fromMap(recipe);
|
|
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 _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;
|
|
}
|
|
|
|
@override
|
|
Future<RecipeTagModel> getTags() async {
|
|
final _extra = <String, dynamic>{};
|
|
final queryParameters = <String, dynamic>{};
|
|
final _headers = <String, dynamic>{};
|
|
const Map<String, dynamic>? _data = null;
|
|
final _options = _setStreamType<RecipeTagModel>(
|
|
Options(method: 'GET', headers: _headers, extra: _extra)
|
|
.compose(
|
|
_dio.options,
|
|
'/api/recipes/tags',
|
|
queryParameters: queryParameters,
|
|
data: _data,
|
|
)
|
|
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
|
);
|
|
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
|
late RecipeTagModel _value;
|
|
try {
|
|
_value = RecipeTagModel.fromJson(_result.data!);
|
|
} on Object catch (e, s) {
|
|
errorLogger?.logError(e, s, _options);
|
|
rethrow;
|
|
}
|
|
return _value;
|
|
}
|
|
|
|
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
|
if (T != dynamic &&
|
|
!(requestOptions.responseType == ResponseType.bytes ||
|
|
requestOptions.responseType == ResponseType.stream)) {
|
|
if (T == String) {
|
|
requestOptions.responseType = ResponseType.plain;
|
|
} else {
|
|
requestOptions.responseType = ResponseType.json;
|
|
}
|
|
}
|
|
return requestOptions;
|
|
}
|
|
|
|
String _combineBaseUrls(String dioBaseUrl, String? baseUrl) {
|
|
if (baseUrl == null || baseUrl.trim().isEmpty) {
|
|
return dioBaseUrl;
|
|
}
|
|
|
|
final url = Uri.parse(baseUrl);
|
|
|
|
if (url.isAbsolute) {
|
|
return url.toString();
|
|
}
|
|
|
|
return Uri.parse(dioBaseUrl).resolveUri(url).toString();
|
|
}
|
|
}
|