v1.0.3 webapi client

This commit is contained in:
Tibor Bossanyi
2023-02-12 22:42:51 +01:00
parent af0fbaf180
commit 65e9daa273
64 changed files with 1160 additions and 1014 deletions
@@ -7,26 +7,26 @@ import 'package:workouttest_util/service/customer_exercise_device_service.dart';
class CustomerExerciseDeviceRepository {
List<CustomerExerciseDevice> _devices = [];
List<CustomerExerciseDevice> getDevices() => this._devices;
List<CustomerExerciseDevice> getDevices() => _devices;
void setDevices(List<CustomerExerciseDevice> devices) => this._devices = devices;
void setDevices(List<CustomerExerciseDevice> devices) => _devices = devices;
Future<List<CustomerExerciseDevice>?> getDBDevices() async {
if (Cache().userLoggedIn != null) {
final int customerId = Cache().userLoggedIn!.customerId!;
this._devices = await CustomerExerciseDeviceApi().getDevices(customerId);
_devices = await CustomerExerciseDeviceApi().getDevices(customerId);
}
return this._devices;
return _devices;
}
Future<void> addDevice(ExerciseDevice device) async {
CustomerExerciseDevice? found;
this._devices.forEach((element) {
for (var element in _devices) {
if (element.exerciseDeviceId == device.exerciseDeviceId) {
found = element;
}
});
}
if (found == null) {
int? customerId;
@@ -37,7 +37,7 @@ class CustomerExerciseDeviceRepository {
CustomerExerciseDevice(customerId: customerId!, exerciseDeviceId: device.exerciseDeviceId, favourite: false);
newDevice.change = ModelChange.add;
CustomerExerciseDevice saved = await CustomerExerciseDeviceApi().addDevice(newDevice);
this._devices.add(saved);
_devices.add(saved);
Cache().setCustomerDevices(_devices);
}
}
@@ -45,16 +45,16 @@ class CustomerExerciseDeviceRepository {
Future<void> removeDevice(ExerciseDevice device) async {
CustomerExerciseDevice? found;
this._devices.forEach((element) {
for (var element in _devices) {
if (element.exerciseDeviceId == device.exerciseDeviceId) {
found = element;
}
});
}
if (found != null) {
this._devices.remove(found);
_devices.remove(found);
//if (found.change != ModelChange.add) {
await CustomerExerciseDeviceApi().removeDevice(found!.customerExerciseDeviceId!);
await CustomerExerciseDeviceApi().removeDevice(found.customerExerciseDeviceId!);
//}
Cache().setCustomerDevices(_devices);
}
@@ -63,11 +63,11 @@ class CustomerExerciseDeviceRepository {
bool hasDevice(int exerciseDeviceId) {
bool found = false;
this._devices.forEach((element) {
for (var element in _devices) {
if (element.exerciseDeviceId == exerciseDeviceId) {
found = true;
}
});
}
return found;
}
+125 -129
View File
@@ -50,54 +50,54 @@ class CustomerRepository with Logging {
String? getGenderByName(String name) {
String? dbValue;
genders.forEach((element) {
for (var element in genders) {
if (element.name == name) {
dbValue = element.dbValue;
}
});
}
return dbValue;
}
String? getGenderByDBValue(String dbValue) {
String? name;
genders.forEach((element) {
for (var element in genders) {
if (element.dbValue == dbValue) {
name = element.name;
}
});
}
return name;
}
String? get name {
return this.customer != null && this.customer!.name != null ? this.customer!.name : "";
return customer != null && customer!.name != null ? customer!.name : "";
}
String? get firstName {
return this.customer != null && this.customer!.firstname != null ? this.customer!.firstname : "";
return customer != null && customer!.firstname != null ? customer!.firstname : "";
}
String get sex {
if (this.customer == null) throw Exception("Initialize the customer object");
return this.customer!.sex == "m" ? "Man" : "Woman";
if (customer == null) throw Exception("Initialize the customer object");
return customer!.sex == "m" ? "Man" : "Woman";
}
int? get birthYear {
if (this.customer == null) throw Exception("Initialize the customer object");
return this.customer!.birthYear;
if (customer == null) throw Exception("Initialize the customer object");
return customer!.birthYear;
}
String? get goal {
if (this.customer == null) throw Exception("Initialize the customer object");
return this.customer!.goal;
if (customer == null) throw Exception("Initialize the customer object");
return customer!.goal;
}
String? getSportString() {
if (this.customer == null) throw Exception("Initialize the customer object");
if (customer == null) throw Exception("Initialize the customer object");
String? sport;
List<Sport>? sports = Cache().getSports();
if (sports != null) {
for (Sport sportObject in sports) {
if (sportObject.sportId == this.customer!.sportId) {
if (sportObject.sportId == customer!.sportId) {
sport = sportObject.name;
break;
}
@@ -107,12 +107,12 @@ class CustomerRepository with Logging {
}
Sport? getSport() {
if (this.customer == null) throw Exception("Initialize the customer object");
if (customer == null) throw Exception("Initialize the customer object");
Sport? sport;
List<Sport>? sports = Cache().getSports();
if (sports != null) {
for (Sport sportObject in sports) {
if (sportObject.sportId == this.customer!.sportId) {
if (sportObject.sportId == customer!.sportId) {
sport = sportObject;
break;
}
@@ -122,69 +122,69 @@ class CustomerRepository with Logging {
}
String? get fitnessLevel {
if (this.customer == null) throw Exception("Initialize the customer object");
return this.customer!.fitnessLevel;
if (customer == null) throw Exception("Initialize the customer object");
return customer!.fitnessLevel;
}
String? get bodyType {
if (this.customer == null) throw Exception("Initialize the customer object");
return this.customer!.bodyType;
if (customer == null) throw Exception("Initialize the customer object");
return customer!.bodyType;
}
setName(String name) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.name = name;
if (customer == null) throw Exception("Initialize the customer object");
customer!.name = name;
}
setFirstName(String firstName) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.firstname = firstName;
if (customer == null) throw Exception("Initialize the customer object");
customer!.firstname = firstName;
}
setPassword(String password) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.password = password;
if (customer == null) throw Exception("Initialize the customer object");
customer!.password = password;
}
setEmail(String email) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.email = email;
if (customer == null) throw Exception("Initialize the customer object");
customer!.email = email;
}
setSex(String sex) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.sex = sex;
if (customer == null) throw Exception("Initialize the customer object");
customer!.sex = sex;
}
setWeight(double weight) {
final propertyName = "Weight";
this.setCustomerProperty(propertyName, weight);
const propertyName = "Weight";
setCustomerProperty(propertyName, weight);
}
setHeight(int height) {
final propertyName = "Height";
this.setCustomerProperty(propertyName, height.toDouble());
const propertyName = "Height";
setCustomerProperty(propertyName, height.toDouble());
}
setCustomerProperty(String propertyName, double value, {id = 0}) {
if (this.customer == null) {
if (customer == null) {
throw Exception("Initialize the customer object");
}
if (this.customer!.properties[propertyName] == null) {
this.customer!.properties[propertyName] = CustomerProperty(
if (customer!.properties[propertyName] == null) {
customer!.properties[propertyName] = CustomerProperty(
propertyId: propertyRepository.getPropertyByName("Height")!.propertyId,
customerId: this.customer!.customerId == null ? 0 : this.customer!.customerId!,
customerId: customer!.customerId == null ? 0 : customer!.customerId!,
propertyValue: value,
dateAdd: DateTime.now());
} else {
this.customer!.properties[propertyName]!.propertyValue = value;
customer!.properties[propertyName]!.propertyValue = value;
}
this.customer!.properties[propertyName]!.dateAdd = DateTime.now();
this.customer!.properties[propertyName]!.newData = true;
customer!.properties[propertyName]!.dateAdd = DateTime.now();
customer!.properties[propertyName]!.newData = true;
if (id > 0) {
this.customer!.properties[propertyName]!.customerPropertyId = id;
customer!.properties[propertyName]!.customerPropertyId = id;
}
Cache().addCustomerProperty(this.customer!.properties[propertyName]!);
Cache().addCustomerProperty(customer!.properties[propertyName]!);
}
double getWeight() {
@@ -196,40 +196,40 @@ class CustomerRepository with Logging {
}
double getCustomerPropertyValue(String propertyName) {
if (this.customer == null || this.customer!.properties[propertyName] == null) {
if (customer == null || customer!.properties[propertyName] == null) {
return 0.0;
} else {
return this.customer!.properties[propertyName]!.propertyValue;
return customer!.properties[propertyName]!.propertyValue;
}
}
CustomerProperty? getCustomerProperty(String propertyName) {
if (this.customer == null) throw Exception("Initialize the customer object");
return this.customer!.properties[propertyName];
if (customer == null) throw Exception("Initialize the customer object");
return customer!.properties[propertyName];
}
setBirthYear(int birthYear) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.birthYear = birthYear;
if (customer == null) throw Exception("Initialize the customer object");
customer!.birthYear = birthYear;
}
setFitnessLevel(String level) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.fitnessLevel = level;
if (customer == null) throw Exception("Initialize the customer object");
customer!.fitnessLevel = level;
}
setGoal(String goal) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.goal = goal;
if (customer == null) throw Exception("Initialize the customer object");
customer!.goal = goal;
}
setSportString(String selectedSport) {
if (this.customer == null) throw Exception("Initialize the customer object");
if (customer == null) throw Exception("Initialize the customer object");
List<Sport>? sports = Cache().getSports();
if (sports != null) {
for (Sport sportObject in sports) {
if (sportObject.name == selectedSport) {
this.customer!.sportId = sportObject.sportId;
customer!.sportId = sportObject.sportId;
break;
}
}
@@ -237,40 +237,36 @@ class CustomerRepository with Logging {
}
setBodyType(String bodyType) {
if (this.customer == null) throw Exception("Initialize the customer object");
this.customer!.bodyType = bodyType;
if (customer == null) throw Exception("Initialize the customer object");
customer!.bodyType = bodyType;
}
createNew() {
this.customer = Customer();
customer = Customer();
}
Customer getCustomer() {
if (this.customer == null) throw Exception("Initialize the customer object");
return this.customer!;
if (customer == null) throw Exception("Initialize the customer object");
return customer!;
}
void setCustomer(Customer customer) {
this.customer = customer;
customer = customer;
}
Future<void> addCustomer() async {
if (this.customer == null) throw Exception("Initialize the customer object");
if (customer == null) throw Exception("Initialize the customer object");
final Customer modelCustomer = customer!;
await CustomerApi().addCustomer(modelCustomer);
}
Future<void> saveCustomer() async {
if (this.customer == null) throw Exception("Initialize the customer object");
if (customer == null) throw Exception("Initialize the customer object");
final Customer modelCustomer = customer!;
if (modelCustomer.sex == null) {
modelCustomer.sex = "m";
}
if (modelCustomer.fitnessLevel == null) {
modelCustomer.fitnessLevel = "beginner";
}
modelCustomer.sex ??= "m";
modelCustomer.fitnessLevel ??= "beginner";
await CustomerApi().saveCustomer(modelCustomer);
await this.saveProperties(modelCustomer.properties);
await saveProperties(modelCustomer.properties);
}
Future<void> saveProperties(LinkedHashMap<String, CustomerProperty> properties) async {
@@ -283,8 +279,8 @@ class CustomerRepository with Logging {
}
Future<void> savePropertyByName(String name) async {
await Future.forEach(this._properties!, (element) async {
final CustomerProperty customerProperty = element as CustomerProperty;
await Future.forEach(_properties!, (element) async {
final CustomerProperty customerProperty = element;
final Property? property = propertyRepository.getPropertyByName(name);
if (property != null) {
if (property.propertyId == customerProperty.propertyId) {
@@ -295,26 +291,26 @@ class CustomerRepository with Logging {
}
Future<Customer?> getTraineeAsCustomer() async {
this._trainee = await CustomerApi().getTrainee(Cache().userLoggedIn!.customerId!);
_trainee = await CustomerApi().getTrainee(Cache().userLoggedIn!.customerId!);
return _trainee;
}
Future<List<Customer?>?> getTrainees() async {
int trainerId = Cache().userLoggedIn!.customerId!;
final results = await CustomerApi().getTrainees(trainerId);
this._trainees = results;
_trainees = results;
return results;
}
Future<List<CustomerProperty>> getAllCustomerProperties() async {
int customerId = Cache().userLoggedIn!.customerId!;
final results = await CustomerApi().getAllProperties(customerId);
this._properties = results;
_properties = results;
return results;
}
List<CustomerProperty>? getAllProperties() {
return this._properties;
return _properties;
}
List<Customer>? getTraineesList() {
@@ -325,11 +321,11 @@ class CustomerRepository with Logging {
if (_trainees == null) {
return;
}
_trainees!.forEach((element) {
for (var element in _trainees!) {
if (traineeId == element.customerId) {
this._trainee = element;
_trainee = element;
}
});
}
}
void emptyTrainees() {
@@ -338,18 +334,18 @@ class CustomerRepository with Logging {
}
Customer? getTrainee() {
return this._trainee;
return _trainee;
}
Customer? getTraineeById(int customerId) {
if (_trainees == null) {
return null;
}
_trainees!.forEach((element) {
for (var element in _trainees!) {
if (customerId == element.customerId) {
this._trainee = element;
_trainee = element;
}
});
}
return _trainee;
}
@@ -364,13 +360,13 @@ class CustomerRepository with Logging {
}
void setMediaDimensions(double width, double height) {
this.mediaHeight = height;
this.mediaWidth = width;
this.addSizes(this.sex);
mediaHeight = height;
mediaWidth = width;
addSizes(sex);
}
void addSizes(String sex) {
if (this.customer == null) throw Exception("Initialize the customer object");
if (customer == null) throw Exception("Initialize the customer object");
List<Property>? properties = Cache().getProperties();
if (properties == null) {
return;
@@ -378,139 +374,139 @@ class CustomerRepository with Logging {
final double distortionWidth = mediaWidth / baseWidth;
final double distortionHeight = mediaHeight / baseHeight;
if (isMan) {
properties.forEach((element) {
for (var element in properties) {
if (element.propertyName == "Shoulder") {
element.top = (122 * distortionHeight).toInt();
element.left = (130 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Shoulder");
element.value = customer!.getProperty("Shoulder");
manSizes.add(element);
} else if (element.propertyName == "Neck") {
element.top = (68 * distortionHeight).toInt();
element.left = (130 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Neck");
element.value = customer!.getProperty("Neck");
manSizes.add(element);
} else if (element.propertyName == "Biceps") {
element.top = (178 * distortionHeight).toInt();
element.left = (208 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Biceps");
element.value = customer!.getProperty("Biceps");
manSizes.add(element);
} else if (element.propertyName == "Chest") {
element.top = (154 * distortionHeight).toInt();
element.left = (130 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Chest");
element.value = customer!.getProperty("Chest");
manSizes.add(element);
} else if (element.propertyName == "Belly") {
element.top = (244 * distortionHeight).toInt();
element.left = (130 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Belly");
element.value = customer!.getProperty("Belly");
manSizes.add(element);
} else if (element.propertyName == "Hip") {
element.top = (308 * distortionHeight).toInt();
element.left = (130 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Hip");
element.value = customer!.getProperty("Hip");
manSizes.add(element);
} else if (element.propertyName == "Thigh Top") {
element.top = (332 * distortionHeight).toInt();
element.left = (165 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Thigh Top");
element.value = customer!.getProperty("Thigh Top");
manSizes.add(element);
} else if (element.propertyName == "Thigh Middle") {
element.top = (382 * distortionHeight).toInt();
element.left = (100 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Thigh Middle");
element.value = customer!.getProperty("Thigh Middle");
manSizes.add(element);
} else if (element.propertyName == "Knee") {
element.top = (464 * distortionHeight).toInt();
element.left = (97 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Knee");
element.value = customer!.getProperty("Knee");
manSizes.add(element);
} else if (element.propertyName == "Calf") {
element.top = (520 * distortionHeight).toInt();
element.left = (97 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Calf");
element.value = customer!.getProperty("Calf");
manSizes.add(element);
} else if (element.propertyName == "Ankle") {
element.top = (620 * distortionHeight).toInt();
element.left = (150 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Ankle");
element.value = customer!.getProperty("Ankle");
manSizes.add(element);
} else if (element.propertyName == "Weight") {
element.top = (402 * distortionHeight).toInt();
element.left = (240 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Weight");
element.value = customer!.getProperty("Weight");
manSizes.add(element);
}
});
}
} else {
properties.forEach((element) {
for (var element in properties) {
if (element.propertyName == "Shoulder") {
element.top = (122 * distortionHeight).toInt();
element.left = (151 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Shoulder");
element.value = customer!.getProperty("Shoulder");
manSizes.add(element);
} else if (element.propertyName == "Neck") {
element.top = (78 * distortionHeight).toInt();
element.left = (151 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Neck");
element.value = customer!.getProperty("Neck");
manSizes.add(element);
} else if (element.propertyName == "Biceps") {
element.top = (178 * distortionHeight).toInt();
element.left = (212 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Biceps");
element.value = customer!.getProperty("Biceps");
manSizes.add(element);
} else if (element.propertyName == "Chest") {
element.top = (154 * distortionHeight).toInt();
element.left = (151 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Chest");
element.value = customer!.getProperty("Chest");
manSizes.add(element);
} else if (element.propertyName == "Belly") {
element.top = (230 * distortionHeight).toInt();
element.left = (151 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Belly");
element.value = customer!.getProperty("Belly");
manSizes.add(element);
} else if (element.propertyName == "Hip") {
element.top = (294 * distortionHeight).toInt();
element.left = (151 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Hip");
element.value = customer!.getProperty("Hip");
manSizes.add(element);
} else if (element.propertyName == "Thigh Top") {
element.top = (335 * distortionHeight).toInt();
element.left = (185 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Thigh Top");
element.value = customer!.getProperty("Thigh Top");
manSizes.add(element);
} else if (element.propertyName == "Thigh Middle") {
element.top = (377 * distortionHeight).toInt();
element.left = (125 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Thigh Middle");
element.value = customer!.getProperty("Thigh Middle");
manSizes.add(element);
} else if (element.propertyName == "Knee") {
element.top = (468 * distortionHeight).toInt();
element.left = (129 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Knee");
element.value = customer!.getProperty("Knee");
manSizes.add(element);
} else if (element.propertyName == "Calf") {
element.top = (525 * distortionHeight).toInt();
element.left = (129 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Calf");
element.value = customer!.getProperty("Calf");
manSizes.add(element);
} else if (element.propertyName == "Ankle") {
element.top = (620 * distortionHeight).toInt();
element.left = (162 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Ankle");
element.value = customer!.getProperty("Ankle");
manSizes.add(element);
} else if (element.propertyName == "Weight") {
element.top = (402 * distortionHeight).toInt();
element.left = (240 * distortionWidth).toInt();
element.value = this.customer!.getProperty("Weight");
element.value = customer!.getProperty("Weight");
manSizes.add(element);
}
});
}
}
}
int? getWeightCoordinate(isMan, {isTop = false, isLeft = false}) {
int? value = 0;
this.manSizes.forEach((element) {
for (var element in manSizes) {
if (element.propertyName == SizesEnum.Weight.toStr()) {
if (isTop == true) {
value = element.top;
@@ -518,40 +514,40 @@ class CustomerRepository with Logging {
value = element.left;
}
}
});
}
return value;
}
Property? getPropertyByName(String propertyName) {
Property? property;
List<Property> sizes;
if (this.sex == "m") {
sizes = this.manSizes;
if (sex == "m") {
sizes = manSizes;
} else {
sizes = this.womanSizes;
sizes = womanSizes;
}
sizes.forEach((element) {
for (var element in sizes) {
if (element.propertyName == propertyName) {
property = element;
}
});
}
return property;
}
void updateSizes(String propertyName, double value) {
List<Property> sizes;
if (this.sex == "m") {
sizes = this.manSizes;
if (sex == "m") {
sizes = manSizes;
} else {
sizes = this.womanSizes;
sizes = womanSizes;
}
sizes.forEach((element) {
for (var element in sizes) {
if (element.propertyName == propertyName) {
element.value = value;
}
});
}
}
List<CustomerProperty> getAllCustomerPropertyByName(String propertyName) {
@@ -563,11 +559,11 @@ class CustomerRepository with Logging {
return allProperties;
}
Cache().getCustomerPropertyAll()!.forEach((element) {
for (var element in Cache().getCustomerPropertyAll()!) {
if (element.propertyId == property.propertyId) {
allProperties.add(element);
}
});
}
return allProperties;
}
}
+99 -105
View File
@@ -7,10 +7,10 @@ import 'package:workouttest_util/model/exercise.dart';
import 'package:workouttest_util/model/exercise_type.dart';
import 'package:workouttest_util/model/workout_menu_tree.dart';
import 'package:workouttest_util/service/exercise_service.dart';
// ignore: depend_on_referenced_packages
import 'package:intl/intl.dart';
import 'package:workouttest_util/util/logging.dart';
class ExerciseRepository {
class ExerciseRepository with Logging {
Exercise? exercise;
Customer? customer;
ExerciseType? exerciseType;
@@ -30,69 +30,69 @@ class ExerciseRepository {
DateTime? end;
ExerciseRepository() {
this.createNew();
createNew();
}
createNew() {
this.exercise = Exercise();
exercise = Exercise();
exercise!.dateAdd = DateTime.now();
}
setQuantity(double quantity) {
if (this.exercise == null) {
this.createNew();
if (exercise == null) {
createNew();
}
this.exercise!.quantity = quantity;
exercise!.quantity = quantity;
}
setUnitQuantity(double unitQuantity) {
if (this.exercise == null) {
this.createNew();
if (exercise == null) {
createNew();
}
this.exercise!.unitQuantity = unitQuantity;
exercise!.unitQuantity = unitQuantity;
}
setUnit(String unit) {
if (this.exercise == null) {
this.createNew();
if (exercise == null) {
createNew();
}
this.exercise!.unit = unit;
exercise!.unit = unit;
}
setDatetimeExercise(DateTime datetimeExercise) {
if (this.exercise == null) {
this.createNew();
if (exercise == null) {
createNew();
}
this.exercise!.dateAdd = datetimeExercise;
exercise!.dateAdd = datetimeExercise;
}
double? get unitQuantity => this.exercise!.unitQuantity;
double? get unitQuantity => exercise!.unitQuantity;
double? get quantity => this.exercise!.quantity;
double? get quantity => exercise!.quantity;
Exercise? getExercise() => this.exercise;
Exercise? getExercise() => exercise;
Future<Exercise> addExercise() async {
if (this.customer == null) {
if (customer == null) {
throw Exception("Please log in");
}
final Exercise modelExercise = this.exercise!;
modelExercise.customerId = this.customer!.customerId;
modelExercise.exerciseTypeId = this.exerciseType!.exerciseTypeId;
final Exercise modelExercise = exercise!;
modelExercise.customerId = customer!.customerId;
modelExercise.exerciseTypeId = exerciseType!.exerciseTypeId;
if (exerciseType!.unitQuantity != "1") {
modelExercise.unitQuantity = null;
}
Exercise copy = modelExercise.copy();
this.actualExerciseList!.add(copy);
//final int index = this.actualExerciseList.length - 1;
//print("$index. actual exercise " + this.actualExerciseList[index].toJson().toString());
actualExerciseList!.add(copy);
//final int index = actualExerciseList.length - 1;
//print("$index. actual exercise " + actualExerciseList[index].toJson().toString());
Exercise savedExercise = await ExerciseApi().addExercise(modelExercise);
//this.actualExerciseList[index].exerciseId = savedExercise.exerciseId;
//actualExerciseList[index].exerciseId = savedExercise.exerciseId;
if (customer!.customerId == Cache().userLoggedIn!.customerId) {
Cache().addExercise(savedExercise);
} else if (Cache().getTrainee() != null && customer!.customerId == Cache().getTrainee()!.customerId) {
@@ -103,41 +103,41 @@ class ExerciseRepository {
}
void addExerciseNoRegistration() {
final Exercise modelExercise = this.exercise!;
modelExercise.exerciseTypeId = this.exerciseType!.exerciseTypeId;
final Exercise modelExercise = exercise!;
modelExercise.exerciseTypeId = exerciseType!.exerciseTypeId;
if (exerciseType!.unitQuantity != "1") {
modelExercise.unitQuantity = null;
}
Exercise copy = modelExercise.copy();
this.actualExerciseList!.add(copy);
this.exerciseList = [];
this.exerciseList!.add(copy);
this.noRegistration = true;
actualExerciseList!.add(copy);
exerciseList = [];
exerciseList!.add(copy);
noRegistration = true;
}
void initExercise() {
this.createNew();
this.exerciseType = exerciseType;
this.setUnit(exerciseType!.unit);
exercise!.exerciseTypeId = this.exerciseType!.exerciseTypeId;
this.setQuantity(12);
this.setUnitQuantity(30);
this.exercise!.exercisePlanDetailId = 0;
createNew();
exerciseType = exerciseType;
setUnit(exerciseType!.unit);
exercise!.exerciseTypeId = exerciseType!.exerciseTypeId;
setQuantity(12);
setUnitQuantity(30);
exercise!.exercisePlanDetailId = 0;
exercise!.exerciseId = 0;
this.start = DateTime.now();
start = DateTime.now();
}
Future<void> deleteExercise(Exercise exercise) async {
await ExerciseApi().deleteExercise(exercise);
}
setCustomer(Customer customer) => this.customer = customer;
setCustomer(Customer customer) => customer = customer;
setExerciseType(ExerciseType exerciseType) => this.exerciseType = exerciseType;
setExerciseType(ExerciseType exerciseType) => exerciseType = exerciseType;
Future<List<Exercise>> getExercisesByCustomer(int customerId) async {
final results = await ExerciseApi().getExercisesByCustomer(customerId);
this.exerciseList = results;
exerciseList = results;
if (Cache().userLoggedIn != null) {
if (customerId == Cache().userLoggedIn!.customerId) {
Cache().setExercises(exerciseList!);
@@ -145,23 +145,21 @@ class ExerciseRepository {
Cache().setExercisesTrainee(exerciseList!);
}
}
return this.exerciseList!;
return exerciseList!;
}
List<Exercise>? getExerciseList() {
this.exerciseList = Cache().getExercises();
return this.exerciseList;
exerciseList = Cache().getExercises();
return exerciseList;
}
List<Exercise>? getExerciseListTrainee() {
this.exerciseList = Cache().getExercisesTrainee();
return this.exerciseList;
exerciseList = Cache().getExercisesTrainee();
return exerciseList;
}
String? nextMissingBaseExercise(SplayTreeMap sortedTree) {
if (exerciseList == null) {
exerciseList = Cache().getExercises();
}
exerciseList ??= Cache().getExercises();
if (exerciseList == null) {
return null;
@@ -175,22 +173,20 @@ class ExerciseRepository {
String treeName = key as String;
treeName = treeName.substring(3);
foundTreeName = null;
listByMuscle.forEach((exercise) {
if (missingTreeName == null) {
missingTreeName = treeName;
}
for (var exercise in listByMuscle) {
missingTreeName ??= treeName;
if (exercise.base) {
if (exerciseList != null) {
exerciseList!.forEach((element) {
for (var element in exerciseList!) {
if (element.exerciseTypeId == exercise.exerciseTypeId) {
foundTreeName = treeName;
//print("Found " + foundTreeName + " Missing actual: " + missingTreeName);
isBreak = true;
}
});
}
}
}
});
}
if (foundTreeName == null && !isBreak) {
missingTreeName = treeName;
isBreak = true;
@@ -218,15 +214,13 @@ class ExerciseRepository {
}
});
if (exerciseList == null) {
exerciseList = Cache().getExercises();
}
exerciseList ??= Cache().getExercises();
if (exerciseList == null) {
return;
}
exerciseList!.forEach((element) {
for (var element in exerciseList!) {
Exercise exercise = element;
if (!checkedExerciseTypeId.contains(exercise.exerciseTypeId)) {
checkedExerciseTypeId.add(exercise.exerciseTypeId!);
@@ -242,7 +236,7 @@ class ExerciseRepository {
}
});
}
});
}
//print ("checkedExerciseTypeid: " + checkedExerciseTypeId.toString());
//print ("baseTreeItem: " + baseTreeItem.toString());
@@ -252,19 +246,19 @@ class ExerciseRepository {
}
void getLastExercise() {
List<Exercise>? exercises = this.getExerciseList();
List<Exercise>? exercises = getExerciseList();
Exercise? lastExercise = exercises == null ? null : exercises[0];
if (exercises != null) {
exercises.forEach((element) {
for (var element in exercises) {
Exercise actualExercise = element;
if (actualExercise.dateAdd!.compareTo(lastExercise!.dateAdd!) > 0) {
lastExercise = actualExercise;
}
});
}
}
this.exercise = lastExercise;
this.customer = Cache().userLoggedIn!;
this.exerciseType = getExerciseTypeById(exercise!.exerciseTypeId!);
exercise = lastExercise;
customer = Cache().userLoggedIn!;
exerciseType = getExerciseTypeById(exercise!.exerciseTypeId!);
return;
}
@@ -272,12 +266,12 @@ class ExerciseRepository {
ExerciseType? actualExerciseType;
List<ExerciseType>? exercises = Cache().getExerciseTypes();
if (exercises != null) {
exercises.forEach((element) {
for (var element in exercises) {
ExerciseType exerciseType = element;
if (exerciseType.exerciseTypeId == exerciseTypeId) {
actualExerciseType = exerciseType;
}
});
}
}
if (actualExerciseType == null) {
throw Exception("Data error, no ExerciseType for exerciseTypeId $exerciseTypeId");
@@ -286,16 +280,16 @@ class ExerciseRepository {
}
void getSameExercise(int exerciseTypeId, String day) {
if (!this.noRegistration) {
this.actualExerciseList = [];
if (!noRegistration) {
actualExerciseList = [];
}
if (exerciseList != null) {
int index = 0;
for (int i = 0; i < this.exerciseList!.length; i++) {
for (int i = 0; i < exerciseList!.length; i++) {
Exercise exercise = exerciseList![i];
final String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
if (exerciseTypeId == exercise.exerciseTypeId && exerciseDate == day && index < 4) {
this.actualExerciseList!.add(exercise);
actualExerciseList!.add(exercise);
index++;
}
}
@@ -318,12 +312,12 @@ class ExerciseRepository {
double getBest1RM(Exercise exercise) {
double result = 0;
if (this.exerciseList == null || this.exerciseList!.isEmpty) {
this.exerciseList = Cache().getExercises();
if (exerciseList == null || exerciseList!.isEmpty) {
exerciseList = Cache().getExercises();
}
final int exerciseTypeId = exercise.exerciseTypeId!;
double toCompare = this.calculate1RM(exercise);
double toCompare = calculate1RM(exercise);
result = toCompare;
final String today = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(DateTime.now());
@@ -331,12 +325,12 @@ class ExerciseRepository {
if (exerciseList == null) {
return toCompare;
}
this.exerciseList!.forEach((exercise) {
for (var exercise in exerciseList!) {
final String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
if (exercise.exerciseTypeId == exerciseTypeId && exerciseDate.compareTo(today) < 0) {
oldExercises.add(exercise);
}
});
}
if (oldExercises.isNotEmpty) {
oldExercises.sort((a, b) {
@@ -352,7 +346,7 @@ class ExerciseRepository {
return sumA >= sumB ? 1 : -1;
});
double withCompare = this.calculate1RM(oldExercises.last);
double withCompare = calculate1RM(oldExercises.last);
//result = toCompare >= withCompare ? (1 - toCompare / withCompare) * 100 : (1 - toCompare / withCompare) * -100;
result = toCompare >= withCompare ? toCompare : withCompare;
@@ -362,12 +356,12 @@ class ExerciseRepository {
double getLast1RMPercent(Exercise exercise) {
double result = 0;
if (this.exerciseList == null || this.exerciseList!.isEmpty) {
this.exerciseList = Cache().getExercises();
if (exerciseList == null || exerciseList!.isEmpty) {
exerciseList = Cache().getExercises();
}
final int exerciseTypeId = exercise.exerciseTypeId!;
double toCompare = this.calculate1RM(exercise);
double toCompare = calculate1RM(exercise);
final String today = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
List<Exercise> oldExercises = [];
@@ -375,15 +369,15 @@ class ExerciseRepository {
if (exerciseList == null) {
return result;
}
this.exerciseList!.forEach((exercise) {
for (var exercise in exerciseList!) {
final String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
if (exercise.exerciseTypeId == exerciseTypeId && exerciseDate.compareTo(today) < 0) {
oldExercises.add(exercise);
}
});
}
if (oldExercises.isNotEmpty) {
double withCompare = this.calculate1RM(oldExercises.first);
double withCompare = calculate1RM(oldExercises.first);
result = toCompare >= withCompare ? (toCompare / withCompare) * 100 : (1 - toCompare / withCompare) * -100;
}
return result;
@@ -391,8 +385,8 @@ class ExerciseRepository {
double getBestVolume(Exercise exercise) {
double result = 0;
if (this.exerciseList == null || this.exerciseList!.isEmpty) {
this.exerciseList = Cache().getExercises();
if (exerciseList == null || exerciseList!.isEmpty) {
exerciseList = Cache().getExercises();
}
final int exerciseTypeId = exercise.exerciseTypeId!;
@@ -404,12 +398,12 @@ class ExerciseRepository {
if (exerciseList == null) {
return toCompare;
}
this.exerciseList!.forEach((exercise) {
for (var exercise in exerciseList!) {
final String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
if (exercise.exerciseTypeId == exerciseTypeId && exerciseDate.compareTo(today) < 0) {
oldExercises.add(exercise);
}
});
}
if (oldExercises.isNotEmpty) {
oldExercises.sort((a, b) {
@@ -437,8 +431,8 @@ class ExerciseRepository {
double getLastExercisePercent(Exercise exercise) {
double result = 0;
if (this.exerciseList == null || this.exerciseList!.isEmpty) {
this.exerciseList = Cache().getExercises();
if (exerciseList == null || exerciseList!.isEmpty) {
exerciseList = Cache().getExercises();
}
final int exerciseTypeId = exercise.exerciseTypeId!;
@@ -449,19 +443,19 @@ class ExerciseRepository {
if (exerciseList == null) {
return result;
}
this.exerciseList!.forEach((exercise) {
for (var exercise in exerciseList!) {
final String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
if (exercise.exerciseTypeId == exerciseTypeId && exerciseDate.compareTo(today) < 0) {
oldExercises.add(exercise);
}
});
}
if (oldExercises.isNotEmpty) {
double withCompare =
oldExercises.first.unitQuantity != null ? oldExercises.first.quantity! * oldExercises.first.unitQuantity! : oldExercises.first.quantity!;
result = toCompare >= withCompare ? (toCompare / withCompare) * 100 : (1 - toCompare / withCompare) * -100;
print("Last Last: ${oldExercises.first} vs. $exercise - - result: $result");
log("Last Last: ${oldExercises.first} vs. $exercise - - result: $result");
}
return result;
}
@@ -473,20 +467,20 @@ class ExerciseRepository {
exerciseList!.sort((a, b) {
final String datePartA = DateFormat('yyyyMMdd', AppLanguage().appLocal.toString()).format(a.dateAdd!);
String aId = datePartA + "_" + a.exerciseTypeId.toString();
String aId = "${datePartA}_${a.exerciseTypeId}";
final String datePartB = DateFormat('yyyyMMdd', AppLanguage().appLocal.toString()).format(b.dateAdd!);
String bId = datePartB + "_" + b.exerciseTypeId.toString();
String bId = "${datePartB}_${b.exerciseTypeId}";
return bId.compareTo(aId);
});
this.exerciseLogList = [];
exerciseLogList = [];
String summary = "";
String prevDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exerciseList![0].dateAdd!);
int prevExerciseTypeId = exerciseList![0].exerciseTypeId!;
Exercise prevExercise = exerciseList![0];
int prevCount = 0;
for (int i = 0; i < this.exerciseList!.length; i++) {
for (int i = 0; i < exerciseList!.length; i++) {
Exercise exercise = exerciseList![i];
int exerciseTypeId = exercise.exerciseTypeId!;
String exerciseDate = DateFormat("yyyy-MM-dd", AppLanguage().appLocal.toString()).format(exercise.dateAdd!);
@@ -494,7 +488,7 @@ class ExerciseRepository {
if (exerciseTypeId != prevExerciseTypeId || prevDate != exerciseDate) {
ExerciseType? exerciseType = Cache().getExerciseTypeById(prevExercise.exerciseTypeId!);
String unit = exerciseType != null && exerciseType.unitQuantityUnit != null ? exerciseType.unitQuantityUnit! : prevExercise.unit!;
prevExercise.summary = summary + " " + unit;
prevExercise.summary = "$summary $unit";
exerciseLogList!.add(prevExercise);
//print("Log add " + exercise.toJson().toString());
summary = "";
@@ -508,7 +502,7 @@ class ExerciseRepository {
//print("exerciseType " + (exerciseType == null ? "NULL" : exerciseType.name) + " ID " + exercise.exerciseTypeId.toString());
if (exerciseType != null) {
if (exerciseType.unitQuantity == "1") {
summary += "x" + exercise.unitQuantity!.toStringAsFixed(0);
summary += "x${exercise.unitQuantity!.toStringAsFixed(0)}";
}
//print(" --- sum " + exerciseType.name + " $summary");
}
@@ -528,11 +522,11 @@ class ExerciseRepository {
if (allExercise == null) {
return list;
}
allExercise.forEach((element) {
for (var element in allExercise) {
if (element.exerciseTypeId == exerciseTypeId) {
list.add(element);
}
});
}
return list;
}
}
+4 -4
View File
@@ -11,15 +11,15 @@ class ExerciseTypeRepository with Logging {
List<ExerciseType> list = [];
List<ExerciseType>? exerciseTypes = Cache().getExerciseTypes();
if (exerciseTypes != null) {
exerciseTypes.forEach((exerciseType) {
for (var exerciseType in exerciseTypes) {
if (exerciseType.alternatives.isNotEmpty) {
exerciseType.alternatives.forEach((childId) {
for (var childId in exerciseType.alternatives) {
if (childId == exerciseTypeId) {
list.add(exerciseType);
}
});
}
}
});
}
}
return list;
}
+6 -8
View File
@@ -6,25 +6,23 @@ class PropertyRepository {
List<Property>? _properties;
Future<List<Property>?> getDBProperties() async {
this._properties = await PropertyApi().getProperties();
return this._properties;
_properties = await PropertyApi().getProperties();
return _properties;
}
List<Property>? getProperties() {
return this._properties;
return _properties;
}
Property? getPropertyByName(String name) {
Property? property;
if (_properties == null) {
_properties = Cache().getProperties();
}
_properties ??= Cache().getProperties();
if (_properties != null) {
this._properties!.forEach((element) {
for (var element in _properties!) {
if (name == element.propertyName) {
property = element;
}
});
}
}
return property;
}
@@ -10,13 +10,13 @@ class TrainingPlanDayRepository {
if (plans == null) {
return;
}
plans.forEach((plan) {
for (var plan in plans) {
if (plan.details != null) {
plan.details!.forEach((element) {
element.day = this.getNameById(element.dayId);
});
for (var element in plan.details!) {
element.day = getNameById(element.dayId);
}
}
});
}
}
String? getNameById(int? dayId) {
+13 -12
View File
@@ -11,8 +11,9 @@ import 'package:workouttest_util/repository/exercise_type_repository.dart';
import 'package:workouttest_util/repository/training_plan_day_repository.dart';
import 'package:workouttest_util/util/app_language.dart';
import 'package:workouttest_util/util/common.dart';
import 'package:workouttest_util/util/logging.dart';
class TrainingPlanRepository with Common {
class TrainingPlanRepository with Common, Logging {
ExerciseTree? parentTree;
List<TrainingPlan> getPlansByParent(String parent) {
final List<TrainingPlan> resultList = [];
@@ -44,7 +45,7 @@ class TrainingPlanRepository with Common {
/// 3. create new customer_training_plan
CustomerTrainingPlan? activateTrainingPlan(int trainingPlanId) {
print(" **** Activate Plan: $trainingPlanId");
log(" **** Activate Plan: $trainingPlanId");
// 1. deactivate
if (Cache().getCustomerTrainingPlans() != null) {
Cache().getCustomerTrainingPlans()!.forEach((plan) {
@@ -61,9 +62,9 @@ class TrainingPlanRepository with Common {
plan.active = true;
plan.status = "open";
plan.dateAdd = DateTime.now();
TrainingPlan? trainingPlan = this.getTrainingPlanById(trainingPlanId);
TrainingPlan? trainingPlan = getTrainingPlanById(trainingPlanId);
if (trainingPlan == null || trainingPlan.details == null) {
print("trainingPlan null");
log("trainingPlan null");
return null;
}
plan.name = trainingPlan.nameTranslations[AppLanguage().appLocal.toString()];
@@ -88,7 +89,7 @@ class TrainingPlanRepository with Common {
CustomerTrainingPlanDetails? getDetailById(CustomerTrainingPlan? plan, int customerTrainingPlanDetailsId) {
CustomerTrainingPlanDetails? foundDetail;
if (plan == null || plan.details.length == 0 || customerTrainingPlanDetailsId == 0) {
if (plan == null || plan.details.isEmpty || customerTrainingPlanDetailsId == 0) {
return foundDetail;
}
@@ -116,7 +117,7 @@ class TrainingPlanRepository with Common {
alternativeDetail.weight = 0;
}
} else if (elem.weight == -2) {
final CustomerTrainingPlanDetails calculated = this.isWeightCalculatedByExerciseType(elem.exerciseTypeId, alternativeDetail, plan);
final CustomerTrainingPlanDetails calculated = isWeightCalculatedByExerciseType(elem.exerciseTypeId, alternativeDetail, plan);
if (calculated.weight != -1) {
alternativeDetail.weight = calculated.weight;
} else {
@@ -140,7 +141,7 @@ class TrainingPlanRepository with Common {
detail.repeats = elem.repeats;
detail.set = elem.set;
detail.dayId = elem.dayId;
TrainingPlanDayRepository trainingPlanDayRepository = TrainingPlanDayRepository();
TrainingPlanDayRepository trainingPlanDayRepository = const TrainingPlanDayRepository();
detail.day = trainingPlanDayRepository.getNameById(elem.dayId);
detail.parallel = elem.parallel;
detail.restingTime = elem.restingTime;
@@ -153,7 +154,7 @@ class TrainingPlanRepository with Common {
detail.weight = 0;
}
} else if (elem.weight == -2) {
final CustomerTrainingPlanDetails calculated = this.isWeightCalculatedByExerciseType(elem.exerciseTypeId, detail, plan);
final CustomerTrainingPlanDetails calculated = isWeightCalculatedByExerciseType(elem.exerciseTypeId, detail, plan);
if (calculated.weight != -1) {
detail.weight = calculated.weight;
} else {
@@ -244,7 +245,7 @@ class TrainingPlanRepository with Common {
}
Exercise? lastExercise1RM;
DateTime dt = DateTime.now().subtract(Duration(days: 30));
DateTime dt = DateTime.now().subtract(const Duration(days: 30));
List<Exercise> exercises = Cache().getExercises()!;
exercises.sort((a, b) {
// reverse
@@ -352,7 +353,7 @@ class TrainingPlanRepository with Common {
detail.weight = Common.calculateWeigthByChangedQuantity(detailWithData.weight!, detailWithData.repeats!.toDouble(), originalRepeats.toDouble());
detail.weight = Common.roundWeight(detail.weight!);
print("Recalculated weight: ${detail.weight}");
log("Recalculated weight: ${detail.weight}");
detail.repeats = originalRepeats;
return detail;
}
@@ -379,7 +380,7 @@ class TrainingPlanRepository with Common {
// 2 get recalculated repeats
recalculatedDetail.weight = Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
recalculatedDetail.weight = Common.roundWeight(recalculatedDetail.weight!);
print("recalculated repeats for $originalRepeats: ${recalculatedDetail.weight}");
log("recalculated repeats for $originalRepeats: ${recalculatedDetail.weight}");
//recalculatedDetail.repeats = originalRepeats;
return recalculatedDetail;
@@ -435,7 +436,7 @@ class TrainingPlanRepository with Common {
}
}
print("Generated plan $trainingPlanId fitness ${Cache().userLoggedIn!.fitnessLevel} - ${FitnessState.beginner}");
log("Generated plan $trainingPlanId fitness ${Cache().userLoggedIn!.fitnessLevel} - ${FitnessState.beginner}");
if (trainingPlanId != null) {
CustomerTrainingPlan? customerTrainingPlan = activateTrainingPlan(trainingPlanId);
+27 -27
View File
@@ -10,23 +10,23 @@ class UserRepository with Logging {
late User user;
UserRepository() {
this.createNewUser();
createNewUser();
}
setEmail(String email) {
this.user.email = email;
user.email = email;
}
setPassword(String password) {
this.user.password = password;
user.password = password;
}
createNewUser() {
this.user = User();
user = User();
}
Future<void> addUser() async {
final User modelUser = this.user;
final User modelUser = user;
try {
String rc = await FirebaseApi().registerEmail(modelUser.email!, modelUser.password!);
if (rc == FirebaseApi.SIGN_IN_OK) {
@@ -38,19 +38,19 @@ class UserRepository with Logging {
log(message);
if (message.contains("CERT_ALREADY_IN_HASH_TABLE")) {
} else {
throw new Exception(e);
throw Exception(e);
}
}
}
Future<void> addUserFB() async {
final User modelUser = this.user;
final User modelUser = user;
try {
Map<String, dynamic> userData = await FirebaseApi().registerWithFacebook();
modelUser.email = userData['email'];
if (modelUser.email == null) {
throw new Exception("Facebook signup was not successful. Please try another method");
throw Exception("Facebook signup was not successful. Please try another method");
}
modelUser.password = Cache().firebaseUid;
modelUser.firebaseUid = Cache().firebaseUid;
@@ -66,7 +66,7 @@ class UserRepository with Logging {
log(e.code);
throw Exception("The account exists with different credential");
} else {
print(e.code);
log(e.code);
throw Exception(e);
}
} on WorkoutTestException catch (ex) {
@@ -75,19 +75,19 @@ class UserRepository with Logging {
throw Exception("The email address has been registered already");
}
} on Exception catch (ex) {
log("FB exception: " + ex.toString());
log("FB exception: $ex");
throw Exception("Facebook Sign In failed");
}
}
Future<void> addUserGoogle() async {
final User modelUser = this.user;
final User modelUser = user;
try {
Map<String, dynamic> userData = await FirebaseApi().registerWithGoogle();
modelUser.email = userData['email'];
if (modelUser.email == null) {
throw new Exception("Google signup was not successful. Please try another method");
throw Exception("Google signup was not successful. Please try another method");
}
modelUser.password = Cache().firebaseUid;
modelUser.firebaseUid = Cache().firebaseUid;
@@ -105,19 +105,19 @@ class UserRepository with Logging {
throw Exception("The email address has been registered already");
}
} on Exception catch (ex) {
log("Google exception: " + ex.toString());
log("Google exception: $ex");
throw Exception("Google Sign In failed");
}
}
Future<void> addUserApple() async {
final User modelUser = this.user;
final User modelUser = user;
try {
Map<String, dynamic> userData = await FirebaseApi().registerWithApple();
modelUser.email = userData['email'];
if (modelUser.email == null) {
throw new Exception("Apple signup was not successful. Please try another method");
throw Exception("Apple signup was not successful. Please try another method");
}
modelUser.password = Cache().firebaseUid;
modelUser.firebaseUid = Cache().firebaseUid;
@@ -133,13 +133,13 @@ class UserRepository with Logging {
throw Exception("The email address has been registered already");
}
} on Exception catch (ex) {
log("Apple exception: " + ex.toString());
log("Apple exception: $ex");
throw Exception(ex);
}
}
Future<void> getUserByFB() async {
final User modelUser = this.user;
final User modelUser = user;
try {
Map<String, dynamic> userData = await FirebaseApi().signInWithFacebook();
modelUser.email = userData['email'];
@@ -160,49 +160,49 @@ class UserRepository with Logging {
}
} */
on NotFoundException catch (ex) {
log("FB exception: " + ex.toString());
log("FB exception: $ex");
throw Exception("Customer does not exist or the password is wrong");
} on Exception catch (e) {
log(e.toString());
throw new Exception(e);
throw Exception(e);
}
}
Future<void> getUserByGoogle() async {
final User modelUser = this.user;
final User modelUser = user;
try {
Map<String, dynamic> userData = await FirebaseApi().signInWithGoogle();
if (userData['email'] == null) {
throw new Exception("Google login was not successful");
throw Exception("Google login was not successful");
}
modelUser.email = userData['email'];
await CustomerApi().getUserByEmail(modelUser.email!);
await Cache().afterFirebaseLogin();
} on Exception catch (ex) {
log("Google exception: " + ex.toString());
log("Google exception: $ex");
throw Exception(ex);
}
}
Future<void> getUserByApple() async {
final User modelUser = this.user;
final User modelUser = user;
Map<String, dynamic> userData = await FirebaseApi().signInWithApple();
if (userData['email'] == null) {
throw new Exception("Apple login was not successful");
throw Exception("Apple login was not successful");
}
modelUser.email = userData['email'];
try {
await CustomerApi().getUserByEmail(modelUser.email!);
await Cache().afterFirebaseLogin();
} on Exception catch (ex) {
log("Apple exception: " + ex.toString());
log("Apple exception: $ex");
throw Exception("Customer does not exist or the password is wrong");
}
}
Future<void> getUser() async {
final User modelUser = this.user;
final User modelUser = user;
String rc = await FirebaseApi().signInEmail(modelUser.email, modelUser.password);
try {
if (rc == FirebaseApi.SIGN_IN_OK) {
@@ -218,7 +218,7 @@ class UserRepository with Logging {
}
Future<void> resetPassword() async {
final User modelUser = this.user;
final User modelUser = user;
await FirebaseApi().resetPassword(modelUser.email!);
}
}