workouttest_util/lib/service/training_plan_service.dart
2023-02-10 19:48:58 +01:00

35 lines
1.7 KiB
Dart

import 'dart:convert';
import 'package:workouttest_util/model/customer_training_plan.dart';
import 'package:workouttest_util/model/customer_training_plan_exercise.dart';
import 'package:workouttest_util/service/api.dart';
import 'package:workouttest_util/util/logging.dart';
class TrainingPlanApi with Logging {
final APIClient _client = APIClient();
Future<CustomerTrainingPlan> saveCustomerTrainingPlan(CustomerTrainingPlan plan) async {
String body = const 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 = const 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 = const 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;
}
}