WT1.1.2f Purchase, Product, Property, BMR, BMI, Sizes

This commit is contained in:
bossanyit
2020-11-16 15:42:40 +01:00
parent 5fa5382e3f
commit e28f1edf50
48 changed files with 2631 additions and 1441 deletions
+79 -19
View File
@@ -1,9 +1,13 @@
import 'dart:collection';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/customer.dart';
import 'package:aitrainer_app/model/customer_property.dart';
import 'package:aitrainer_app/repository/property_repository.dart';
import 'package:aitrainer_app/service/customer_service.dart';
class GenderItem {
GenderItem(this.dbValue,this.name);
GenderItem(this.dbValue, this.name);
final String dbValue;
String name;
}
@@ -12,6 +16,8 @@ class CustomerRepository {
Customer customer;
Customer _trainee;
List<Customer> _trainees;
List<CustomerProperty> _allProperties;
final PropertyRepository propertyRepository = PropertyRepository();
//List<CustomerRepository> customerList = List<CustomerRepository>();
bool visibleDetails = false;
@@ -76,11 +82,12 @@ class CustomerRepository {
setName(String name) {
this.customer.name = name;
}
setFirstName(String firstName) {
this.customer.firstname = firstName;
}
setPassword( String password ) {
setPassword(String password) {
this.customer.password = password;
}
@@ -88,24 +95,58 @@ class CustomerRepository {
this.customer.email = email;
}
setSex(String sex) {
this.customer.sex = sex;
}
setWeight( int weight) {
this.customer.weight = weight;
setWeight(int weight) {
final propertyName = "Weight";
this.setCustomerProperty(propertyName, weight.toDouble());
}
setBirthYear( int birthYear ) {
setHeight(int height) {
final propertyName = "Height";
this.setCustomerProperty(propertyName, height.toDouble());
}
setCustomerProperty(String propertyName, double value) {
if (this.customer.properties[propertyName] == null) {
this.customer.properties[propertyName] = CustomerProperty(
propertyId: propertyRepository.getPropertyByName("Height").propertyId,
customerId: this.customer.customerId,
propertyValue: value);
} else {
this.customer.properties[propertyName].propertyValue = value;
}
this.customer.properties[propertyName].dateAdd = DateTime.now();
this.customer.properties[propertyName].newData = true;
}
double getWeight() {
return getCustomerProperty("Weight");
}
double getHeight() {
return getCustomerProperty("Height");
}
double getCustomerProperty(String propertyName) {
if (this.customer.properties[propertyName] == null) {
return 0.0;
} else {
return this.customer.properties[propertyName].propertyValue;
}
}
setBirthYear(int birthYear) {
this.customer.birthYear = birthYear;
}
setFitnessLevel( String level ) {
setFitnessLevel(String level) {
this.customer.fitnessLevel = level;
}
setGoal( String goal ) {
setGoal(String goal) {
this.customer.goal = goal;
}
@@ -121,7 +162,7 @@ class CustomerRepository {
return this.customer;
}
void setCustomer ( Customer customer ) {
void setCustomer(Customer customer) {
this.customer = customer;
}
@@ -133,32 +174,51 @@ class CustomerRepository {
Future<void> saveCustomer() async {
final Customer modelCustomer = customer;
await CustomerApi().saveCustomer(modelCustomer);
await this.saveProperties(modelCustomer.properties);
}
Future<void> saveProperties(LinkedHashMap<String, CustomerProperty> properties) async {
properties.forEach((propertyName, property) async {
if (property.newData == true) {
await CustomerApi().addProperty(property);
property.newData = false;
}
});
}
Future<Customer> getTraineeAsCustomer() async {
this._trainee = await CustomerApi().getTrainee(
Cache().userLoggedIn.customerId
);
this._trainee = await CustomerApi().getTrainee(Cache().userLoggedIn.customerId);
return _trainee;
}
Future<List<Customer>> getTrainees() async {
Future<List<Customer>> getTrainees() async {
int trainerId = Cache().userLoggedIn.customerId;
final results = await CustomerApi().getTrainees(trainerId);
final results = await CustomerApi().getTrainees(trainerId);
this._trainees = results;
return results;
}
}
Future<List<CustomerProperty>> getAllCustomerProperties() async {
int customerId = Cache().userLoggedIn.customerId;
final results = await CustomerApi().getAllProperties(customerId);
this._allProperties = results;
return results;
}
List<CustomerProperty> getAllProperties() {
return this._allProperties;
}
List<Customer> getTraineesList() {
return _trainees;
}
void setTrainee(int traineeId ) {
if ( _trainees == null ) {
void setTrainee(int traineeId) {
if (_trainees == null) {
return;
}
_trainees.forEach((element) {
if ( traineeId == element.customerId) {
if (traineeId == element.customerId) {
this._trainee = element;
}
});
@@ -178,7 +238,7 @@ class CustomerRepository {
return null;
}
_trainees.forEach((element) {
if ( customerId == element.customerId) {
if (customerId == element.customerId) {
this._trainee = element;
}
});
+3 -3
View File
@@ -34,13 +34,13 @@ class UserRepository {
Future<void> getUser() async {
final User modelUser = this.user;
String rc = await FirebaseApi().signInEmail(modelUser.email, modelUser.password);
if ( rc == FirebaseApi.SIGN_IN_NOT_FOUND ) {
rc = await FirebaseApi().registerEmail(modelUser.email, modelUser.password);
}
if ( rc == FirebaseApi.SIGN_IN_OK ) {
print("Firebase login ok");
await CustomerApi().getUserByEmail(modelUser.email);
Cache().afterFirebaseLogin();
} else {
throw Exception("Exception: Customer does not exist or the password is wrong");
}
}