PMU/lib/data/dtos/recipes_dto.dart
2024-12-18 17:20:52 +04:00

42 lines
1.1 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
part 'recipe_dto.g.dart';
@JsonSerializable(createToJson: false)
class RecipesDto {
final List<RecipeDataDto>? hits; // API возвращает список рецептов под ключом "hits".
const RecipesDto({this.hits});
factory RecipesDto.fromJson(Map<String, dynamic> json) =>
_$RecipesDtoFromJson(json);
}
@JsonSerializable(createToJson: false)
class RecipeDataDto {
final RecipeAttributesDataDto? recipe; // API возвращает объект "recipe" внутри каждого "hit".
const RecipeDataDto({this.recipe});
factory RecipeDataDto.fromJson(Map<String, dynamic> json) =>
_$RecipeDataDtoFromJson(json);
}
@JsonSerializable(createToJson: false)
class RecipeAttributesDataDto {
final String? label;
final double? calories; // API возвращает "calories" как число.
final String? url;
final String? image;
const RecipeAttributesDataDto({
this.label,
this.calories,
this.url,
this.image,
});
factory RecipeAttributesDataDto.fromJson(Map<String, dynamic> json) =>
_$RecipeAttributesDataDtoFromJson(json);
}