Files
food_hub_app/lib/models/recipe.dart
2026-06-30 23:26:49 +08:00

277 lines
5.6 KiB
Dart

import 'package:json_annotation/json_annotation.dart';
part 'recipe.g.dart';
/// 食材信息
@JsonSerializable()
class RecipeMaterial {
int id;
String type;
String name;
String amount;
RecipeMaterial({
required this.id,
required this.type,
required this.name,
required this.amount,
});
factory RecipeMaterial.fromJson(Map<String, dynamic> json) =>
_$RecipeMaterialFromJson(json);
Map<String, dynamic> toJson() => _$RecipeMaterialToJson(this);
}
/// 步骤信息
@JsonSerializable()
class RecipeStep {
int id;
int sort;
String content;
String imageUrl;
RecipeStep({
required this.id,
required this.sort,
required this.content,
required this.imageUrl,
});
factory RecipeStep.fromJson(Map<String, dynamic> json) =>
_$RecipeStepFromJson(json);
Map<String, dynamic> toJson() => _$RecipeStepToJson(this);
}
/// 评论信息
@JsonSerializable()
class RecipeComment {
int id;
String username;
String avatar;
String content;
String date;
RecipeComment({
required this.id,
required this.username,
required this.avatar,
required this.content,
required this.date,
});
factory RecipeComment.fromJson(Map<String, dynamic> json) =>
_$RecipeCommentFromJson(json);
Map<String, dynamic> toJson() => _$RecipeCommentToJson(this);
}
/// 成果信息
@JsonSerializable()
class FoodRecord {
int? id;
String name;
String category;
int person;
String date;
String imageUrl;
FoodRecord({
this.id,
required this.name,
required this.category,
required this.person,
required this.date,
required this.imageUrl,
});
factory FoodRecord.fromJson(Map<String, dynamic> json) =>
_$FoodRecordFromJson(json);
Map<String, dynamic> toJson() => _$FoodRecordToJson(this);
static FoodRecord getEmpty() {
return FoodRecord(
id: 0,
name: '',
category: '',
person: 0,
date: '',
imageUrl: '',
);
}
}
@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<RecipeMaterial> materialList;
List<RecipeStep> stepList;
List<FoodRecord> recordList;
List<int> likeList;
List<int> favouriteList;
List<RecipeComment> commentList;
Recipe({
required this.id,
required this.name,
required this.category,
required this.recommendRate,
required this.remark,
required this.isShare,
required this.userId,
required this.username,
required this.avatar,
required this.materialList,
required this.stepList,
required this.recordList,
required this.likeList,
required this.favouriteList,
required this.commentList,
});
factory Recipe.fromJson(Map<String, dynamic> json) => _$RecipeFromJson(json);
Map<String, dynamic> toJson() => _$RecipeToJson(this);
static Recipe getEmpty() {
return Recipe(
id: 0,
name: '',
category: '家常菜',
recommendRate: 3,
remark: '',
isShare: true,
userId: 0,
username: '',
avatar: '',
materialList: [],
stepList: [],
recordList: [],
likeList: [],
favouriteList: [],
commentList: []
);
}
}
@JsonSerializable()
class RecipeSummary {
int id;
String name;
String category;
double recommendRate;
bool isShare;
List<FoodRecord> recordList;
int likeCount;
int favouriteCount;
int commentCount;
int userId;
String username;
RecipeSummary({
required this.id,
required this.name,
required this.category,
required this.recommendRate,
required this.isShare,
required this.userId,
required this.username,
required this.recordList,
required this.likeCount,
required this.favouriteCount,
required this.commentCount,
});
factory RecipeSummary.fromJson(Map<String, dynamic> json) =>
_$RecipeSummaryFromJson(json);
Map<String, dynamic> toJson() => _$RecipeSummaryToJson(this);
}
@JsonSerializable()
class RecipeDetail {
int id;
String name;
String category;
double recommendRate;
String remark;
bool isShare;
int userId;
String username;
String avatar;
List<RecipeMaterial> materialList;
List<RecipeStep> stepList;
List<FoodRecord> recordList;
List<int> likeList;
List<int> favouriteList;
List<RecipeComment> commentList;
RecipeDetail({
required this.id,
required this.name,
required this.category,
required this.recommendRate,
required this.remark,
required this.isShare,
required this.userId,
required this.username,
required this.avatar,
required this.materialList,
required this.stepList,
required this.recordList,
required this.likeList,
required this.favouriteList,
required this.commentList,
});
factory RecipeDetail.fromJson(Map<String, dynamic> json) =>
_$RecipeDetailFromJson(json);
Map<String, dynamic> toJson() => _$RecipeDetailToJson(this);
static RecipeDetail getEmpty() {
return RecipeDetail(
id: 0,
name: '',
category: '',
recommendRate: 0,
remark: '',
isShare: false,
userId: 0,
username: '',
avatar: '',
materialList: [],
stepList: [],
recordList: [],
likeList: [],
favouriteList: [],
commentList: [],
);
}
}
enum ViewType { recipe, calendar, timeline }