基本完成
This commit is contained in:
23
lib/api/endpoints/food_api.dart
Normal file
23
lib/api/endpoints/food_api.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:food_health/api/dto/food_scan_dto.dart';
|
||||
|
||||
import '../network/request.dart';
|
||||
|
||||
///食物检测
|
||||
Future<FoodScanDto> foodScanApi(List<int> bytes) async {
|
||||
FormData formData = FormData.fromMap({
|
||||
"food_image": MultipartFile.fromBytes(
|
||||
bytes,
|
||||
filename: "upload.jpg",
|
||||
contentType: DioMediaType("image", "jpeg"),
|
||||
),
|
||||
});
|
||||
var res = await Request().post("/food/scan", formData);
|
||||
return FoodScanDto.fromJson(res);
|
||||
}
|
||||
|
||||
///食物检测列表
|
||||
Future<List<FoodScanDto>> foodScanListApi() async {
|
||||
var res = await Request().get("/food/records");
|
||||
return res['list'].map<FoodScanDto>((e) => FoodScanDto.fromJson(e)).toList();
|
||||
}
|
||||
27
lib/api/endpoints/profile_api.dart
Normal file
27
lib/api/endpoints/profile_api.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:food_health/api/dto/profile_options_dto.dart';
|
||||
import 'package:food_health/api/dto/user_profile_dto.dart';
|
||||
import 'package:food_health/api/network/request.dart';
|
||||
|
||||
///获取用户档案
|
||||
Future<UserProfileDto> getUserProfileApi() async {
|
||||
var res = await Request().get("/user/profile");
|
||||
return UserProfileDto.fromJson(res);
|
||||
}
|
||||
|
||||
///获取档案选项
|
||||
Future<List<ProfileOptionDto>> getProfileOptionsApi() async {
|
||||
var res = await Request().get("/user/get_user_profile_options");
|
||||
return (res as List).map((e) => ProfileOptionDto.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
///更新档案
|
||||
Future<void> updateProfileApi(UserProfileDto userProfile) async {
|
||||
await Request().post("/user/update_profile", {
|
||||
"age_range": userProfile.ageRange,
|
||||
"food_allergies": userProfile.foodAllergiesList,
|
||||
"dietary_preferences": userProfile.dietaryPreferencesList,
|
||||
"medical_information": userProfile.medicalInformationList,
|
||||
"current_medications": userProfile.currentMedicationsList,
|
||||
"activity_level": userProfile.activityLevel,
|
||||
});
|
||||
}
|
||||
49
lib/api/endpoints/user_api.dart
Normal file
49
lib/api/endpoints/user_api.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:food_health/api/dto/login_dto.dart';
|
||||
import 'package:food_health/api/network/request.dart';
|
||||
import 'package:food_health/data/models/other_login_type.dart';
|
||||
|
||||
///检查是否注册
|
||||
Future<bool> checkRegisterApi(String email) async {
|
||||
var res = await Request().post("/auth/email_check", {
|
||||
"email": email,
|
||||
});
|
||||
if (res["next"] == "login") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///邮箱密码登陆
|
||||
Future<LoginDto> loginApi(String email, String password) async {
|
||||
var res = await Request().post("/auth/login/account", {
|
||||
"email": email,
|
||||
"password": password,
|
||||
});
|
||||
return LoginDto.fromJson(res);
|
||||
}
|
||||
|
||||
///注册处
|
||||
Future<LoginDto> registerApi(String email, String password, String code) async {
|
||||
var res = await Request().post("/auth/register", {
|
||||
"email": email,
|
||||
"password": password,
|
||||
"email_code": code,
|
||||
});
|
||||
return LoginDto.fromJson(res);
|
||||
}
|
||||
|
||||
///发送邮箱验证码
|
||||
Future<void> sendEmailCodeApi(String email) async {
|
||||
return Request().post("/send_email_code", {
|
||||
"email": email,
|
||||
});
|
||||
}
|
||||
|
||||
///三方登录
|
||||
Future<LoginDto> thirdLoginApi(String token, OtherLoginType type) async {
|
||||
var res = await Request().post("/auth/login/oauth", {
|
||||
"login_token": token,
|
||||
"login_type": type.value,
|
||||
});
|
||||
return LoginDto.fromJson(res);
|
||||
}
|
||||
Reference in New Issue
Block a user