feat(diary): add gallery

This commit is contained in:
mso7nueh
2024-11-01 05:24:08 +03:00
parent b0c687e5fe
commit 972ee605be
10 changed files with 555 additions and 299 deletions

View File

@@ -1,23 +1,11 @@
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/models/diary_index_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:retrofit/retrofit.dart';
part 'diary_service.freezed.dart';
part 'diary_service.g.dart';
@freezed
class ProductInMeal with _$ProductInMeal {
const factory ProductInMeal({
@JsonKey(name: 'product_name') required String productName,
@JsonKey(name: 'portion') required String portion,
@JsonKey(name: 'quantity') required int quantity,
}) = _ProductInMeal;
factory ProductInMeal.fromJson(Map<String, Object?> json) => _$ProductInMealFromJson(json);
}
@RestApi()
abstract class DiaryService {
factory DiaryService(Dio dio, {String baseUrl}) = _DiaryService;
@@ -32,6 +20,22 @@ abstract class DiaryService {
@Path('diary_id') required int index,
});
@POST('/api/diary/{diary_id}/meal/{meal_id}/photo/upload')
@MultiPart()
Future<void> uploadPhotoOfMeal({
@Path('diary_id') required int diaryId,
@Path('meal_id') required int mealId,
@Part(name: 'photo') required File photo,
});
@DELETE('/api/diary/{diary_id}/meal/{meal_id}/photo/delete')
Future<void> deletePhotoOfMeal({
@Path('diary_id') required int diaryId,
@Path('meal_id') required int mealId,
@Query('id') required int id,
@Query('path') required String path,
});
@POST('/api/diary/{diary_id}/meal/{meal_id}/portions/create')
Future<void> addProductToMeal({
@Path('diary_id') required int diaryId,

View File

@@ -1,220 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'diary_service.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
ProductInMeal _$ProductInMealFromJson(Map<String, dynamic> json) {
return _ProductInMeal.fromJson(json);
}
/// @nodoc
mixin _$ProductInMeal {
@JsonKey(name: 'product_name')
String get productName => throw _privateConstructorUsedError;
@JsonKey(name: 'portion')
String get portion => throw _privateConstructorUsedError;
@JsonKey(name: 'quantity')
int get quantity => throw _privateConstructorUsedError;
/// Serializes this ProductInMeal to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of ProductInMeal
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProductInMealCopyWith<ProductInMeal> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProductInMealCopyWith<$Res> {
factory $ProductInMealCopyWith(
ProductInMeal value, $Res Function(ProductInMeal) then) =
_$ProductInMealCopyWithImpl<$Res, ProductInMeal>;
@useResult
$Res call(
{@JsonKey(name: 'product_name') String productName,
@JsonKey(name: 'portion') String portion,
@JsonKey(name: 'quantity') int quantity});
}
/// @nodoc
class _$ProductInMealCopyWithImpl<$Res, $Val extends ProductInMeal>
implements $ProductInMealCopyWith<$Res> {
_$ProductInMealCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProductInMeal
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? productName = null,
Object? portion = null,
Object? quantity = null,
}) {
return _then(_value.copyWith(
productName: null == productName
? _value.productName
: productName // ignore: cast_nullable_to_non_nullable
as String,
portion: null == portion
? _value.portion
: portion // ignore: cast_nullable_to_non_nullable
as String,
quantity: null == quantity
? _value.quantity
: quantity // ignore: cast_nullable_to_non_nullable
as int,
) as $Val);
}
}
/// @nodoc
abstract class _$$ProductInMealImplCopyWith<$Res>
implements $ProductInMealCopyWith<$Res> {
factory _$$ProductInMealImplCopyWith(
_$ProductInMealImpl value, $Res Function(_$ProductInMealImpl) then) =
__$$ProductInMealImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@JsonKey(name: 'product_name') String productName,
@JsonKey(name: 'portion') String portion,
@JsonKey(name: 'quantity') int quantity});
}
/// @nodoc
class __$$ProductInMealImplCopyWithImpl<$Res>
extends _$ProductInMealCopyWithImpl<$Res, _$ProductInMealImpl>
implements _$$ProductInMealImplCopyWith<$Res> {
__$$ProductInMealImplCopyWithImpl(
_$ProductInMealImpl _value, $Res Function(_$ProductInMealImpl) _then)
: super(_value, _then);
/// Create a copy of ProductInMeal
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? productName = null,
Object? portion = null,
Object? quantity = null,
}) {
return _then(_$ProductInMealImpl(
productName: null == productName
? _value.productName
: productName // ignore: cast_nullable_to_non_nullable
as String,
portion: null == portion
? _value.portion
: portion // ignore: cast_nullable_to_non_nullable
as String,
quantity: null == quantity
? _value.quantity
: quantity // ignore: cast_nullable_to_non_nullable
as int,
));
}
}
/// @nodoc
@JsonSerializable()
class _$ProductInMealImpl implements _ProductInMeal {
const _$ProductInMealImpl(
{@JsonKey(name: 'product_name') required this.productName,
@JsonKey(name: 'portion') required this.portion,
@JsonKey(name: 'quantity') required this.quantity});
factory _$ProductInMealImpl.fromJson(Map<String, dynamic> json) =>
_$$ProductInMealImplFromJson(json);
@override
@JsonKey(name: 'product_name')
final String productName;
@override
@JsonKey(name: 'portion')
final String portion;
@override
@JsonKey(name: 'quantity')
final int quantity;
@override
String toString() {
return 'ProductInMeal(productName: $productName, portion: $portion, quantity: $quantity)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProductInMealImpl &&
(identical(other.productName, productName) ||
other.productName == productName) &&
(identical(other.portion, portion) || other.portion == portion) &&
(identical(other.quantity, quantity) ||
other.quantity == quantity));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, productName, portion, quantity);
/// Create a copy of ProductInMeal
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProductInMealImplCopyWith<_$ProductInMealImpl> get copyWith =>
__$$ProductInMealImplCopyWithImpl<_$ProductInMealImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$ProductInMealImplToJson(
this,
);
}
}
abstract class _ProductInMeal implements ProductInMeal {
const factory _ProductInMeal(
{@JsonKey(name: 'product_name') required final String productName,
@JsonKey(name: 'portion') required final String portion,
@JsonKey(name: 'quantity') required final int quantity}) =
_$ProductInMealImpl;
factory _ProductInMeal.fromJson(Map<String, dynamic> json) =
_$ProductInMealImpl.fromJson;
@override
@JsonKey(name: 'product_name')
String get productName;
@override
@JsonKey(name: 'portion')
String get portion;
@override
@JsonKey(name: 'quantity')
int get quantity;
/// Create a copy of ProductInMeal
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProductInMealImplCopyWith<_$ProductInMealImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -2,24 +2,6 @@
part of 'diary_service.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$ProductInMealImpl _$$ProductInMealImplFromJson(Map<String, dynamic> json) =>
_$ProductInMealImpl(
productName: json['product_name'] as String,
portion: json['portion'] as String,
quantity: (json['quantity'] as num).toInt(),
);
Map<String, dynamic> _$$ProductInMealImplToJson(_$ProductInMealImpl instance) =>
<String, dynamic>{
'product_name': instance.productName,
'portion': instance.portion,
'quantity': instance.quantity,
};
// **************************************************************************
// RetrofitGenerator
// **************************************************************************
@@ -105,6 +87,76 @@ class _DiaryService implements DiaryService {
return _value;
}
@override
Future<void> uploadPhotoOfMeal({
required int diaryId,
required int mealId,
required File photo,
}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
final _data = FormData();
_data.files.add(MapEntry(
'photo',
MultipartFile.fromFileSync(
photo.path,
filename: photo.path.split(Platform.pathSeparator).last,
),
));
final _options = _setStreamType<void>(Options(
method: 'POST',
headers: _headers,
extra: _extra,
contentType: 'multipart/form-data',
)
.compose(
_dio.options,
'/api/diary/${diaryId}/meal/${mealId}/photo/upload',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
await _dio.fetch<void>(_options);
}
@override
Future<void> deletePhotoOfMeal({
required int diaryId,
required int mealId,
required int id,
required String path,
}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{
r'id': id,
r'path': path,
};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<void>(Options(
method: 'DELETE',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/api/diary/${diaryId}/meal/${mealId}/photo/delete',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
await _dio.fetch<void>(_options);
}
@override
Future<void> addProductToMeal({
required int diaryId,