workouttest_app/lib/service/training_plan_service.dart

35 lines
1.6 KiB
Dart

import 'dart:convert';
import 'package:aitrainer_app/model/customer_training_plan.dart';
import 'package:aitrainer_app/model/customer_training_plan_exercise.dart';
import 'package:aitrainer_app/service/api.dart';
import 'package:aitrainer_app/service/logging.dart';
class TrainingPlanApi with Logging {
final APIClient _client = APIClient();
Future<CustomerTrainingPlan> saveCustomerTrainingPlan(CustomerTrainingPlan plan) async {
String body = JsonEncoder().convert(plan.toJson());
log(" ===== saving customer training plan:" + body);
final String response = await _client.post("customer_training_plan/", body);
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
return saved;
}
Future<CustomerTrainingPlanExercise> saveCustomerTrainingPlanExercise(CustomerTrainingPlanExercise planExercise) async {
String body = JsonEncoder().convert(planExercise.toJson());
log(" ===== saving customer training plan exercise:" + body);
final String response = await _client.post("customer_training_plan_exercise/", body);
final CustomerTrainingPlanExercise saved = CustomerTrainingPlanExercise.fromJson(jsonDecode(response));
return saved;
}
Future<CustomerTrainingPlan> updateCustomerTrainingPlan(CustomerTrainingPlan plan, int customerTrainingPlanId) async {
String body = JsonEncoder().convert(plan.toJson());
log(" ===== update customer training plan:" + body);
final String response = await _client.post("customer_training_plan/update/$customerTrainingPlanId", body);
final CustomerTrainingPlan saved = CustomerTrainingPlan.fromJson(jsonDecode(response));
return saved;
}
}