Merge ssh://git.aitrainer.app:6622/bossanyit/aitrainer_app
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'package:aitrainer_app/model/customer_exercise_device.dart';
|
||||
import 'package:aitrainer_app/util/not_found_exception.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'api.dart';
|
||||
|
||||
class CustomerExerciseDeviceApi {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<List<CustomerExerciseDevice>> getDevices(int customerId) async {
|
||||
List<CustomerExerciseDevice> devices;
|
||||
try {
|
||||
final body = await _client.get("customer_exercise_device/customer/" + customerId.toString(), "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
devices = json.map((device) => CustomerExerciseDevice.fromJson(device)).toList();
|
||||
} on NotFoundException catch (e) {
|
||||
print("No devices found");
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
Future<CustomerExerciseDevice> addDevice(CustomerExerciseDevice device) async {
|
||||
CustomerExerciseDevice savedDevice;
|
||||
try {
|
||||
final String body = JsonEncoder().convert(device.toJson());
|
||||
print(" --- add customer_exercise_device: " + body);
|
||||
final String responseBody = await _client.post("customer_exercise_device", body);
|
||||
savedDevice = CustomerExerciseDevice.fromJson(jsonDecode(responseBody));
|
||||
} on Exception catch (e) {
|
||||
throw new Exception(e.toString());
|
||||
}
|
||||
return savedDevice;
|
||||
}
|
||||
|
||||
Future<void> removeDevice(int id) async {
|
||||
try {
|
||||
print(" --- delete customer_exercise_device: " + id.toString());
|
||||
await _client.post("customer_exercise_device/delete/" + id.toString(), "");
|
||||
} on Exception catch (e) {
|
||||
throw new Exception(e.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import 'package:aitrainer_app/model/property.dart';
|
||||
import 'package:aitrainer_app/model/user.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/util/not_found_exception.dart';
|
||||
|
||||
class CustomerApi {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:aitrainer_app/model/exercise_device.dart';
|
||||
|
||||
import 'api.dart';
|
||||
|
||||
class ExerciseDeviceApi {
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<List<ExerciseDevice>> getDevices() async {
|
||||
final body = await _client.get("exercise_device/", "");
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<ExerciseDevice> devices = json.map((device) => ExerciseDevice.fromJson(device)).toList();
|
||||
Cache().setDevices(devices);
|
||||
return devices;
|
||||
}
|
||||
}
|
||||
@@ -2,30 +2,27 @@ import 'dart:convert';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/service/api.dart';
|
||||
|
||||
|
||||
class ExerciseApi {
|
||||
final APIClient _client=new APIClient();
|
||||
final APIClient _client = new APIClient();
|
||||
|
||||
Future<List<Exercise>> getExerciseTypes(String param) async {
|
||||
final body = await _client.get("exercises", param);
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<Exercise> exerciseTypes = json.map( (exerciseType) => Exercise.fromJson(exerciseType) ).toList();
|
||||
final List<Exercise> exerciseTypes = json.map((exerciseType) => Exercise.fromJson(exerciseType)).toList();
|
||||
|
||||
return exerciseTypes;
|
||||
}
|
||||
|
||||
Future<void> saveExercise(Exercise exercise) async {
|
||||
String body = JsonEncoder().convert(exercise.toJson());
|
||||
print(" ===== saving exercise id: " + exercise.exerciseId.toString() + ":" + body );
|
||||
await _client.post(
|
||||
"exercises/"+exercise.exerciseId.toString(),
|
||||
body);
|
||||
print(" ===== saving exercise id: " + exercise.exerciseId.toString() + ":" + body);
|
||||
await _client.post("exercises/" + exercise.exerciseId.toString(), body);
|
||||
}
|
||||
|
||||
Future<List<Exercise>> getExercisesByCustomer(int customerId ) async {
|
||||
final body = await _client.get("exercises/customer/", customerId.toString() );
|
||||
Future<List<Exercise>> getExercisesByCustomer(int customerId) async {
|
||||
final body = await _client.get("exercises/customer/", customerId.toString());
|
||||
final Iterable json = jsonDecode(body);
|
||||
final List<Exercise> exercises = json.map( (exercise) {
|
||||
final List<Exercise> exercises = json.map((exercise) {
|
||||
Exercise item = Exercise.fromJson(exercise);
|
||||
return item;
|
||||
}).toList();
|
||||
@@ -36,19 +33,16 @@ class ExerciseApi {
|
||||
|
||||
Future<Exercise> addExercise(Exercise exercise) async {
|
||||
String body = JsonEncoder().convert(exercise.toJson());
|
||||
print(" ===== add new exercise: " + body );
|
||||
final String response = await _client.post(
|
||||
"exercises",
|
||||
body);
|
||||
print(" ===== add new exercise: " + body);
|
||||
final String response = await _client.post("exercises", body);
|
||||
final Exercise savedExercise = Exercise.fromJson(jsonDecode(response));
|
||||
return savedExercise;
|
||||
}
|
||||
|
||||
Future<void> deleteExercise(Exercise exercise) async {
|
||||
int exerciseId = exercise.exerciseId;
|
||||
print(" ===== delete exercise: " + exerciseId.toString() );
|
||||
final String response = await _client.post("exercises/" + exerciseId.toString(), "");
|
||||
print(" ===== delete exercise: " + exerciseId.toString());
|
||||
await _client.post("exercises/" + exerciseId.toString(), "");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
||||
//import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
||||
|
||||
class FirebaseApi {
|
||||
static FirebaseApi _instance;
|
||||
@@ -66,10 +66,6 @@ class FirebaseApi {
|
||||
print('The account already exists for that email.');
|
||||
rc = REGISTER_EMAIL_IN_USE;
|
||||
throw Exception("The email address has been registered already");
|
||||
/* userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
|
||||
if (rc != null) {
|
||||
rc = SIGN_IN_OK;
|
||||
} */
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
@@ -78,7 +74,7 @@ class FirebaseApi {
|
||||
return rc;
|
||||
}
|
||||
|
||||
Future<UserCredential> signInWithFacebook() async {
|
||||
/*Future<UserCredential> signInWithFacebook() async {
|
||||
// Trigger the sign-in flow
|
||||
final LoginResult result = await FacebookAuth.instance.login();
|
||||
|
||||
@@ -87,7 +83,7 @@ class FirebaseApi {
|
||||
|
||||
// Once signed in, return the UserCredential
|
||||
return await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
|
||||
}
|
||||
}*/
|
||||
|
||||
Future<void> signOut() async {
|
||||
await FirebaseAuth.instance.signOut();
|
||||
|
||||
Reference in New Issue
Block a user