forked from eatvio/eatvio_app
68 lines
2.3 KiB
Dart
68 lines
2.3 KiB
Dart
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'recipes_model.freezed.dart';
|
|
part 'recipes_model.g.dart';
|
|
|
|
@freezed
|
|
abstract class Recipe with _$Recipe {
|
|
const factory Recipe({
|
|
required int id,
|
|
required String image,
|
|
required String state,
|
|
@JsonKey(name: 'cooking_time') required int cookingTime,
|
|
@JsonKey(name: 'active_time') required int activeCookingTime,
|
|
required List<Ingredient>? ingredients,
|
|
@JsonKey(name: 'description_md') required String description,
|
|
required List<Step>? steps,
|
|
@JsonKey(name: 'video_url') required String? videoUrl,
|
|
@JsonKey(name: 'created_at') required DateTime createdAt,
|
|
@JsonKey(name: 'updated_at') required DateTime updatedAt,
|
|
required String? title,
|
|
required String? type,
|
|
required String slug,
|
|
@JsonKey(name: 'total_comments') required int commentsCount,
|
|
@JsonKey(name: 'was_liked_by_me') required bool wasLikedByMe,
|
|
@JsonKey(name: 'is_favorite') required bool isFavorite,
|
|
@JsonKey(name: 'energy_per_serving') required double calories,
|
|
int? servings,
|
|
@JsonKey(name: 'total_likes') required int likesCount,
|
|
@JsonKey(name: 'total_views') required int viewsCount,
|
|
required List<Tag> tags,
|
|
required Author author,
|
|
}) = _Recipes;
|
|
|
|
factory Recipe.fromJson(Map<String, Object?> json) => _$RecipeFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class Tag with _$Tag {
|
|
const factory Tag({required String name}) = _Tag;
|
|
|
|
factory Tag.fromJson(Map<String, Object?> json) => _$TagFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class Ingredient with _$Ingredient {
|
|
const factory Ingredient({
|
|
required String name,
|
|
String? unit,
|
|
required String portion,
|
|
@JsonKey(name: 'product_nutritional_id', fromJson: _parseProductId) required int productId,
|
|
}) = _Ingredient;
|
|
|
|
factory Ingredient.fromJson(Map<String, Object?> json) => _$IngredientFromJson(json);
|
|
}
|
|
int _parseProductId(json) {
|
|
if (json is String) {
|
|
return int.parse(json);
|
|
}
|
|
return json as int;
|
|
}
|
|
@freezed
|
|
abstract class Step with _$Step {
|
|
const factory Step({required String image, @JsonKey(name: 'description_md') required String description}) = _Step;
|
|
|
|
factory Step.fromJson(Map<String, Object?> json) => _$StepFromJson(json);
|
|
}
|