Files
food_hub_app/lib/models/recipe.dart
2025-07-16 19:59:35 +08:00

143 lines
2.8 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
part 'recipe.g.dart';
/// 食材信息
@JsonSerializable()
class Material {
String type;
String name;
String amount;
Material({required this.type, required this.name, required this.amount});
factory Material.fromJson(Map<String, dynamic> json) =>
_$MaterialFromJson(json);
Map<String, dynamic> toJson() => _$MaterialToJson(this);
}
/// 步骤信息
@JsonSerializable()
class Step {
int sort;
String content;
String imageUrl;
Step({required this.sort, required this.content, required this.imageUrl});
factory Step.fromJson(Map<String, dynamic> json) => _$StepFromJson(json);
Map<String, dynamic> toJson() => _$StepToJson(this);
}
/// 评论信息
@JsonSerializable()
class Comment {
int id;
String username;
String avatar;
String content;
String date;
Comment({
required this.id,
required this.username,
required this.avatar,
required this.content,
required this.date,
});
factory Comment.fromJson(Map<String, dynamic> json) =>
_$CommentFromJson(json);
Map<String, dynamic> toJson() => _$CommentToJson(this);
}
/// 成果信息
@JsonSerializable()
class Record {
int? id;
String name;
String category;
int person;
String date;
String imageUrl;
Record({
this.id,
required this.name,
required this.category,
required this.person,
required this.date,
required this.imageUrl,
});
factory Record.fromJson(Map<String, dynamic> json) => _$RecordFromJson(json);
Map<String, dynamic> toJson() => _$RecordToJson(this);
}
@JsonSerializable()
class RecipeQuery {
String category;
RecipeQuery({
required this.category
});
factory RecipeQuery.fromJson(Map<String, dynamic> json) => _$RecipeQueryFromJson(json);
Map<String, dynamic> toJson() => _$RecipeQueryToJson(this);
}
/// 菜谱信息
@JsonSerializable()
class Recipe {
int? id;
String name;
String category;
double recommendRate;
String? remark;
bool isShare;
int? userId;
String? username;
String? avatar;
List<Material>? materialList;
List<Step>? stepList;
List<Record> recordList;
List<int>? likeList;
int? likeCount;
List<int>? favouriteList;
int? favouriteCount;
List<Comment>? commentList;
int? commentCount;
Recipe({
this.id,
required this.name,
required this.category,
required this.recommendRate,
this.remark,
required this.isShare,
this.userId,
this.username,
this.avatar,
this.materialList,
this.stepList,
required this.recordList,
this.likeList,
this.likeCount,
this.favouriteList,
this.favouriteCount,
this.commentList,
this.commentCount,
});
factory Recipe.fromJson(Map<String, dynamic> json) => _$RecipeFromJson(json);
Map<String, dynamic> toJson() => _$RecipeToJson(this);
}
enum ViewType { recipe, calendar, timeline }