Compare commits
10 Commits
391551f57b
...
7e3d99b9a3
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7e3d99b9a3 | ||
![]() |
3bc2b74f74 | ||
![]() |
a0108baffd | ||
![]() |
eda8ea7d6a | ||
![]() |
14731c5ee7 | ||
![]() |
7e4934f15e | ||
![]() |
adddf41a01 | ||
![]() |
928396112a | ||
![]() |
16603f00bd | ||
![]() |
652104b403 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -28,5 +28,5 @@ migrate_working_dir/
|
|||||||
.packages
|
.packages
|
||||||
build/
|
build/
|
||||||
.dart_tool/
|
.dart_tool/
|
||||||
/.flutter-plugins
|
.flutter-plugins
|
||||||
/.flutter-plugins-dependencies
|
.flutter-plugins-dependencies
|
28
README.md
28
README.md
@ -1,5 +1,33 @@
|
|||||||
Workout Test and Diet 4 You Common Util Functions
|
Workout Test and Diet 4 You Common Util Functions
|
||||||
|
|
||||||
|
### Version 1.1.4
|
||||||
|
- customer.getPropertyDate
|
||||||
|
|
||||||
|
### Version 1.1.3
|
||||||
|
- CupertinoPicker error in Flutter 3.10 stable
|
||||||
|
|
||||||
|
### Version 1.1.2
|
||||||
|
- Flutter SDK < 4.0.0
|
||||||
|
|
||||||
|
### Version 1.1.1
|
||||||
|
- pub.dev dependencies for Flutter 3.10
|
||||||
|
|
||||||
|
### Version 1.1.0
|
||||||
|
|
||||||
|
- Flutter 3.10, dart fix
|
||||||
|
|
||||||
|
### Version 1.0.29
|
||||||
|
|
||||||
|
- gpt4 model
|
||||||
|
|
||||||
|
### Version 1.0.28
|
||||||
|
|
||||||
|
- api isWeb
|
||||||
|
|
||||||
|
### Version 1.0.27
|
||||||
|
|
||||||
|
- customer_membership end_date
|
||||||
|
|
||||||
### Version 1.0.25
|
### Version 1.0.25
|
||||||
|
|
||||||
- http get utf8
|
- http get utf8
|
||||||
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
import 'package:workouttest_util/service/customer_service.dart';
|
import 'package:workouttest_util/service/customer_service.dart';
|
||||||
import 'package:workouttest_util/service/openai_service.dart';
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
@ -481,7 +481,7 @@ class Cache with Logging {
|
|||||||
_exercisesTrainee = null;
|
_exercisesTrainee = null;
|
||||||
_traineeExercisePlan = null;
|
_traineeExercisePlan = null;
|
||||||
_exercises = [];
|
_exercises = [];
|
||||||
_myExercisesPlanDetails = LinkedHashMap();
|
_myExercisesPlanDetails = LinkedHashMap<int, ExercisePlanDetail>();
|
||||||
log("Trainees is null? ${_trainee == null}");
|
log("Trainees is null? ${_trainee == null}");
|
||||||
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
|
||||||
await setPreferences(prefs, SharePrefsChange.logout, 0, "");
|
await setPreferences(prefs, SharePrefsChange.logout, 0, "");
|
||||||
@ -637,7 +637,7 @@ class Cache with Logging {
|
|||||||
|
|
||||||
void initBadges() {
|
void initBadges() {
|
||||||
CustomerRepository customerRepository = CustomerRepository();
|
CustomerRepository customerRepository = CustomerRepository();
|
||||||
_badges = LinkedHashMap();
|
_badges = LinkedHashMap<String, int>();
|
||||||
if (userLoggedIn == null) {
|
if (userLoggedIn == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,18 @@ class Customer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getPropertyDate(String propertyName) {
|
||||||
|
if (properties[propertyName] == null) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
if (properties[propertyName]!.dateAdd == null) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return DateFormat('yyyy-MM-dd').format(properties[propertyName]!.dateAdd!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setProperty(String propertyName, double value) {
|
setProperty(String propertyName, double value) {
|
||||||
properties[propertyName]!.propertyValue = value;
|
properties[propertyName]!.propertyValue = value;
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,20 @@ class CustomerMembership {
|
|||||||
late int membershipId;
|
late int membershipId;
|
||||||
int? customerId;
|
int? customerId;
|
||||||
DateTime? startDate;
|
DateTime? startDate;
|
||||||
|
DateTime? endDate;
|
||||||
|
|
||||||
CustomerMembership.fromJson(Map json) {
|
CustomerMembership.fromJson(Map json) {
|
||||||
membershipId = json['membershipId'];
|
membershipId = json['membershipId'];
|
||||||
customerId = json['customerId'] ?? 0;
|
customerId = json['customerId'] ?? 0;
|
||||||
startDate = json['startDate'] == null ? null : DateTime.parse(json['startDate']);
|
startDate = json['startDate'] == null ? null : DateTime.parse(json['startDate']);
|
||||||
|
endDate = json['endDate'] == null ? null : DateTime.parse(json['endDate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
"membershipId": membershipId,
|
"membershipId": membershipId,
|
||||||
"customerId": customerId ?? 0,
|
"customerId": customerId ?? 0,
|
||||||
"startDate": startDate == null ? "" : DateFormat('yyyy-MM-dd HH:mm:ss').format(startDate!),
|
"startDate": startDate == null ? "" : DateFormat('yyyy-MM-dd HH:mm:ss').format(startDate!),
|
||||||
|
"endDate": startDate == null ? "" : DateFormat('yyyy-MM-dd HH:mm:ss').format(endDate!),
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,36 +1,51 @@
|
|||||||
|
enum DurationType { free, subscription, lifetime, limited }
|
||||||
|
|
||||||
|
extension DurationTypeExt on DurationType {
|
||||||
|
String enumToString() => toString().split(".").last;
|
||||||
|
DurationType getType(String type) => DurationType.values.firstWhere((e) => e.enumToString() == type);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DurationUnit { day, week, month, year }
|
||||||
|
|
||||||
|
extension DurationUnitExt on DurationUnit {
|
||||||
|
String enumToString() => toString().split(".").last;
|
||||||
|
DurationUnit getType(String type) => DurationUnit.values.firstWhere((e) => e.enumToString() == type);
|
||||||
|
}
|
||||||
|
|
||||||
class Membership {
|
class Membership {
|
||||||
late int membershipId;
|
late int membershipId;
|
||||||
late String name;
|
late String name;
|
||||||
String? description;
|
String? description;
|
||||||
late int duration;
|
late int duration;
|
||||||
late String durationType;
|
late DurationType durationType;
|
||||||
late String durationUnit;
|
late DurationUnit durationUnit;
|
||||||
int? trainingPlanId;
|
int? trainingPlanId;
|
||||||
String? trainingPlanDayIds;
|
String? trainingPlanDayIds;
|
||||||
|
|
||||||
|
Membership();
|
||||||
|
|
||||||
Membership.fromJson(Map json) {
|
Membership.fromJson(Map json) {
|
||||||
membershipId = json['membershipId'];
|
membershipId = json['membershipId'];
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
description = json['description'] ?? "";
|
description = json['description'] ?? "";
|
||||||
duration = json['duration'];
|
duration = json['duration'];
|
||||||
durationUnit = json['durationUnit'];
|
durationType = DurationType.free.getType(json['durationType']);
|
||||||
durationType = json['durationType'];
|
durationUnit = DurationUnit.day.getType(json['durationUnit']);
|
||||||
trainingPlanId = json['trainingPlanId'] ?? 0;
|
trainingPlanId = json['trainingPlanId'] ?? 0;
|
||||||
trainingPlanDayIds = json['trainingPlanDayIds'] ?? "";
|
trainingPlanDayIds = json['trainingPlanDayIds'] ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
"membershipId": membershipId,
|
"membershipId": membershipId,
|
||||||
"name": name,
|
"name": name,
|
||||||
"description": description,
|
"description": description,
|
||||||
"duration": duration,
|
"duration": duration,
|
||||||
"durationUnit": durationUnit,
|
'durationType': durationType.enumToString(),
|
||||||
"durationType": durationType,
|
'durationUnit': durationUnit.enumToString(),
|
||||||
"trainingPlanId": trainingPlanId,
|
"trainingPlanId": trainingPlanId,
|
||||||
"trainingPlanDayIds": trainingPlanDayIds,
|
"trainingPlanDayIds": trainingPlanDayIds,
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => toJson().toString();
|
String toString() => toJson().toString();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ class ExerciseDeviceRepository {
|
|||||||
List<ExerciseDevice> _devices = [];
|
List<ExerciseDevice> _devices = [];
|
||||||
|
|
||||||
List<ExerciseDevice> getDevices() {
|
List<ExerciseDevice> getDevices() {
|
||||||
return this._devices;
|
return _devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDevices(List<ExerciseDevice> list) {
|
void setDevices(List<ExerciseDevice> list) {
|
||||||
@ -14,15 +14,15 @@ class ExerciseDeviceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<List<ExerciseDevice>> getDBDevices() async {
|
Future<List<ExerciseDevice>> getDBDevices() async {
|
||||||
this._devices = await ExerciseDeviceApi().getDevices();
|
_devices = await ExerciseDeviceApi().getDevices();
|
||||||
return this._devices;
|
return _devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGym(int deviceId) {
|
bool isGym(int deviceId) {
|
||||||
bool isGym = false;
|
bool isGym = false;
|
||||||
_devices.forEach((element) {
|
for (var element in _devices) {
|
||||||
isGym = isGymElement(element.name);
|
isGym = isGymElement(element.name);
|
||||||
});
|
}
|
||||||
return isGym;
|
return isGym;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,11 +42,11 @@ class ExerciseDeviceRepository {
|
|||||||
if (_devices.isEmpty) {
|
if (_devices.isEmpty) {
|
||||||
_devices = Cache().getDevices()!;
|
_devices = Cache().getDevices()!;
|
||||||
}
|
}
|
||||||
_devices.forEach((element) {
|
for (var element in _devices) {
|
||||||
if (isGymElement(element.name)) {
|
if (isGymElement(element.name)) {
|
||||||
gymDevices.add(element);
|
gymDevices.add(element);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return gymDevices;
|
return gymDevices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,21 +20,21 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
final List<ExerciseTree>? exerciseTree = Cache().getExerciseTree();
|
final List<ExerciseTree>? exerciseTree = Cache().getExerciseTree();
|
||||||
int? parentId;
|
int? parentId;
|
||||||
if (exerciseTree != null) {
|
if (exerciseTree != null) {
|
||||||
exerciseTree.forEach((element) {
|
for (var element in exerciseTree) {
|
||||||
if (element.internalName == parent) {
|
if (element.internalName == parent) {
|
||||||
parentId = element.treeId;
|
parentId = element.treeId;
|
||||||
parentTree = element;
|
parentTree = element;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<TrainingPlan>? plans = Cache().getTrainingPlans();
|
final List<TrainingPlan>? plans = Cache().getTrainingPlans();
|
||||||
if (plans != null && parentId != null) {
|
if (plans != null && parentId != null) {
|
||||||
plans.forEach((element) {
|
for (var element in plans) {
|
||||||
if (element.treeId == parentId) {
|
if (element.treeId == parentId) {
|
||||||
resultList.add(element);
|
resultList.add(element);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
}
|
||||||
@ -48,12 +48,12 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
log(" **** Activate Plan: $trainingPlanId");
|
log(" **** Activate Plan: $trainingPlanId");
|
||||||
// 1. deactivate
|
// 1. deactivate
|
||||||
if (Cache().getCustomerTrainingPlans() != null) {
|
if (Cache().getCustomerTrainingPlans() != null) {
|
||||||
Cache().getCustomerTrainingPlans()!.forEach((plan) {
|
for (var plan in Cache().getCustomerTrainingPlans()!) {
|
||||||
plan.active = false;
|
plan.active = false;
|
||||||
if (plan.customerTrainingPlanId != null) {
|
if (plan.customerTrainingPlanId != null) {
|
||||||
//TrainingPlanApi().updateCustomerTrainingPlan(plan, plan.customerTrainingPlanId!);
|
//TrainingPlanApi().updateCustomerTrainingPlan(plan, plan.customerTrainingPlanId!);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomerTrainingPlan plan = CustomerTrainingPlan();
|
CustomerTrainingPlan plan = CustomerTrainingPlan();
|
||||||
@ -72,14 +72,14 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
// 3 calculate weights
|
// 3 calculate weights
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int exerciseTypeIdOrig = 0;
|
int exerciseTypeIdOrig = 0;
|
||||||
trainingPlan.details!.forEach((elem) {
|
for (var elem in trainingPlan.details!) {
|
||||||
List<CustomerTrainingPlanDetails> list = createDetail(plan, elem, exerciseTypeIdOrig, index);
|
List<CustomerTrainingPlanDetails> list = createDetail(plan, elem, exerciseTypeIdOrig, index);
|
||||||
exerciseTypeIdOrig = elem.exerciseTypeId;
|
exerciseTypeIdOrig = elem.exerciseTypeId;
|
||||||
list.forEach((element) {
|
for (var element in list) {
|
||||||
plan.details.add(element);
|
plan.details.add(element);
|
||||||
index++;
|
index++;
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
Cache().myTrainingPlan = plan;
|
Cache().myTrainingPlan = plan;
|
||||||
|
|
||||||
@ -251,21 +251,21 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
// reverse
|
// reverse
|
||||||
return a.dateAdd!.compareTo(b.dateAdd!);
|
return a.dateAdd!.compareTo(b.dateAdd!);
|
||||||
});
|
});
|
||||||
exercises.forEach((exercise) {
|
for (var exercise in exercises) {
|
||||||
if (exercise.exerciseTypeId == exerciseTypeId && exercise.dateAdd!.compareTo(dt) >= 0) {
|
if (exercise.exerciseTypeId == exerciseTypeId && exercise.dateAdd!.compareTo(dt) >= 0) {
|
||||||
detail.weight = weight;
|
detail.weight = weight;
|
||||||
lastExercise1RM = exercise;
|
lastExercise1RM = exercise;
|
||||||
//print("last exercise: $exercise");
|
//print("last exercise: $exercise");
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (lastExercise1RM == null || lastExercise1RM!.unitQuantity == null) {
|
if (lastExercise1RM == null || lastExercise1RM.unitQuantity == null) {
|
||||||
detail.weight = weight;
|
detail.weight = weight;
|
||||||
detail.isTest = true;
|
detail.isTest = true;
|
||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
double oneRepMax = calculateMax1RMSameDay(lastExercise1RM!);
|
double oneRepMax = calculateMax1RMSameDay(lastExercise1RM);
|
||||||
// Common.calculate1RM(lastExercise1RM!.unitQuantity!, lastExercise1RM!.quantity!);
|
// Common.calculate1RM(lastExercise1RM!.unitQuantity!, lastExercise1RM!.quantity!);
|
||||||
//print("Exercise $exerciseTypeId - 1RM : $oneRepMax");
|
//print("Exercise $exerciseTypeId - 1RM : $oneRepMax");
|
||||||
weight = oneRepMax * Common.get1RMPercent(detail.repeats!);
|
weight = oneRepMax * Common.get1RMPercent(detail.repeats!);
|
||||||
@ -286,7 +286,7 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
List<Exercise> exercises = Cache().getExercises()!;
|
List<Exercise> exercises = Cache().getExercises()!;
|
||||||
double max1RM = 0.0;
|
double max1RM = 0.0;
|
||||||
|
|
||||||
exercises.forEach((exercise) {
|
for (var exercise in exercises) {
|
||||||
if (actual.exerciseTypeId == exercise.exerciseTypeId &&
|
if (actual.exerciseTypeId == exercise.exerciseTypeId &&
|
||||||
actual.dateAdd!.year == exercise.dateAdd!.year &&
|
actual.dateAdd!.year == exercise.dateAdd!.year &&
|
||||||
actual.dateAdd!.month == exercise.dateAdd!.month &&
|
actual.dateAdd!.month == exercise.dateAdd!.month &&
|
||||||
@ -296,7 +296,7 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
max1RM = oneRepMax;
|
max1RM = oneRepMax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return max1RM;
|
return max1RM;
|
||||||
}
|
}
|
||||||
@ -307,11 +307,11 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int originalRepeats = 0;
|
int originalRepeats = 0;
|
||||||
plan.details!.forEach((element) {
|
for (var element in plan.details!) {
|
||||||
if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) {
|
if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) {
|
||||||
originalRepeats = element.repeats ?? 0;
|
originalRepeats = element.repeats ?? 0;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return originalRepeats;
|
return originalRepeats;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,11 +321,11 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
double originalWeight = 0;
|
double originalWeight = 0;
|
||||||
plan.details!.forEach((element) {
|
for (var element in plan.details!) {
|
||||||
if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) {
|
if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) {
|
||||||
originalWeight = element.weight ?? 0;
|
originalWeight = element.weight ?? 0;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return originalWeight;
|
return originalWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,11 +371,11 @@ class TrainingPlanRepository with Common, Logging {
|
|||||||
|
|
||||||
// 1.b get the original detail's repeat
|
// 1.b get the original detail's repeat
|
||||||
int originalRepeats = detail.repeats!;
|
int originalRepeats = detail.repeats!;
|
||||||
plan.details!.forEach((element) {
|
for (var element in plan.details!) {
|
||||||
if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) {
|
if (element.trainingPlanDetailId == detail.trainingPlanDetailsId) {
|
||||||
originalRepeats = element.repeats ?? 0;
|
originalRepeats = element.repeats ?? 0;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// 2 get recalculated repeats
|
// 2 get recalculated repeats
|
||||||
recalculatedDetail.weight = Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
|
recalculatedDetail.weight = Common.calculateWeigthByChangedQuantity(detail.weight!, detail.repeats!.toDouble(), originalRepeats.toDouble());
|
||||||
|
@ -21,7 +21,7 @@ class APIClient with Common, Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dynamic authenticateUser(String email, String password) async {
|
dynamic authenticateUser(String email, String password) async {
|
||||||
if ( kIsWeb ) {
|
if (kIsWeb) {
|
||||||
APIWebClient webClient = APIWebClient();
|
APIWebClient webClient = APIWebClient();
|
||||||
return webClient.authenticateUser(email, password);
|
return webClient.authenticateUser(email, password);
|
||||||
}
|
}
|
||||||
@ -31,15 +31,12 @@ class APIClient with Common, Logging {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
var uri = Uri.parse(url);
|
var uri = Uri.parse(url);
|
||||||
HttpClient client = HttpClient();
|
HttpClient client = HttpClient();
|
||||||
final HttpClientRequest request = await client.postUrl(uri);
|
final HttpClientRequest request = await client.postUrl(uri);
|
||||||
request.headers.contentType = ContentType('application', 'json', charset: 'utf-8');
|
request.headers.contentType = ContentType('application', 'json', charset: 'utf-8');
|
||||||
request.headers.set('Authorization', '1');
|
request.headers.set('Authorization', '1');
|
||||||
|
|
||||||
final body = jsonEncode(<String, String>{
|
final body = jsonEncode(<String, String>{'username': email, 'password': password});
|
||||||
'username': email,
|
|
||||||
'password': password
|
|
||||||
});
|
|
||||||
|
|
||||||
request.write(body);
|
request.write(body);
|
||||||
HttpClientResponse result = await request.close();
|
HttpClientResponse result = await request.close();
|
||||||
@ -48,7 +45,7 @@ class APIClient with Common, Logging {
|
|||||||
log("authentication response: ${result.statusCode} with URL: $url");
|
log("authentication response: ${result.statusCode} with URL: $url");
|
||||||
throw Exception("Authentication error: ${result.statusCode}");
|
throw Exception("Authentication error: ${result.statusCode}");
|
||||||
}
|
}
|
||||||
|
|
||||||
String response = await result.transform(utf8.decoder).join();
|
String response = await result.transform(utf8.decoder).join();
|
||||||
log("Authentication status: ${result.statusCode}, response: $response");
|
log("Authentication status: ${result.statusCode}, response: $response");
|
||||||
final data = jsonDecode(response);
|
final data = jsonDecode(response);
|
||||||
@ -66,7 +63,7 @@ class APIClient with Common, Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<String> post(String endPoint, String body) async {
|
Future<String> post(String endPoint, String body) async {
|
||||||
if ( kIsWeb ) {
|
if (kIsWeb) {
|
||||||
APIWebClient webClient = APIWebClient();
|
APIWebClient webClient = APIWebClient();
|
||||||
return webClient.post(endPoint, body);
|
return webClient.post(endPoint, body);
|
||||||
}
|
}
|
||||||
@ -99,7 +96,7 @@ class APIClient with Common, Logging {
|
|||||||
} else {
|
} else {
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
} on NotFoundException catch(e) {
|
} on NotFoundException catch (e) {
|
||||||
throw NotFoundException(message: "Not Found ${e.message}");
|
throw NotFoundException(message: "Not Found ${e.message}");
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
log("Post Exception: $e");
|
log("Post Exception: $e");
|
||||||
@ -109,7 +106,7 @@ class APIClient with Common, Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<String> get(String endPoint, String param) async {
|
Future<String> get(String endPoint, String param) async {
|
||||||
if ( kIsWeb ) {
|
if (kIsWeb) {
|
||||||
APIWebClient webClient = APIWebClient();
|
APIWebClient webClient = APIWebClient();
|
||||||
return webClient.get(endPoint, param);
|
return webClient.get(endPoint, param);
|
||||||
}
|
}
|
||||||
@ -140,7 +137,7 @@ class APIClient with Common, Logging {
|
|||||||
} else {
|
} else {
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
} on NotFoundException catch(e) {
|
} on NotFoundException catch (e) {
|
||||||
throw NotFoundException(message: "Not Found ${e.message}");
|
throw NotFoundException(message: "Not Found ${e.message}");
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
log("Post Exception: $e");
|
log("Post Exception: $e");
|
||||||
|
@ -35,7 +35,7 @@ class CustomerApi with Logging {
|
|||||||
Future<void> deactivateCustomer(int customerId) async {
|
Future<void> deactivateCustomer(int customerId) async {
|
||||||
log(" ===== deactivate : $customerId");
|
log(" ===== deactivate : $customerId");
|
||||||
await _client.post("customers/deactivate/$customerId", "");
|
await _client.post("customers/deactivate/$customerId", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> addCustomer(Customer customer) async {
|
Future<void> addCustomer(Customer customer) async {
|
||||||
customer.dateAdd = DateTime.now();
|
customer.dateAdd = DateTime.now();
|
||||||
@ -85,7 +85,7 @@ class CustomerApi with Logging {
|
|||||||
final String responseBody = await _client.get("customers/find_by_email/$email", "");
|
final String responseBody = await _client.get("customers/find_by_email/$email", "");
|
||||||
Customer customer;
|
Customer customer;
|
||||||
try {
|
try {
|
||||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||||
if (customer.firebaseUid == null) {
|
if (customer.firebaseUid == null) {
|
||||||
await updateFirebaseUid(customer.customerId!, Cache().firebaseUid!);
|
await updateFirebaseUid(customer.customerId!, Cache().firebaseUid!);
|
||||||
}
|
}
|
||||||
@ -128,32 +128,32 @@ class CustomerApi with Logging {
|
|||||||
|
|
||||||
if (properties != null) {
|
if (properties != null) {
|
||||||
// reset Properties
|
// reset Properties
|
||||||
properties.forEach((property) {
|
for (var property in properties) {
|
||||||
CustomerProperty customerProperty =
|
CustomerProperty customerProperty =
|
||||||
CustomerProperty(propertyId: property.propertyId, customerId: customer.customerId!, dateAdd: DateTime.now(), propertyValue: 0);
|
CustomerProperty(propertyId: property.propertyId, customerId: customer.customerId!, dateAdd: DateTime.now(), propertyValue: 0);
|
||||||
customer.properties[property.propertyName] = customerProperty;
|
customer.properties[property.propertyName] = customerProperty;
|
||||||
});
|
}
|
||||||
|
|
||||||
customerProperties!.forEach((customerProperty) {
|
for (var customerProperty in customerProperties!) {
|
||||||
properties.forEach((property) {
|
for (var property in properties) {
|
||||||
if (customerProperty.propertyId == property.propertyId) {
|
if (customerProperty.propertyId == property.propertyId) {
|
||||||
customer.properties[property.propertyName] = customerProperty;
|
customer.properties[property.propertyName] = customerProperty;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Customer> getTrainee(int customerId) async {
|
Future<Customer> getTrainee(int customerId) async {
|
||||||
String body = "";
|
String body = "";
|
||||||
Customer customer;
|
Customer customer;
|
||||||
log(" ===== get Trainee customer by id: " + customerId.toString());
|
log(" ===== get Trainee customer by id: $customerId");
|
||||||
try {
|
try {
|
||||||
final String responseBody = await _client.get("customers/" + customerId.toString(), body);
|
final String responseBody = await _client.get("customers/$customerId", body);
|
||||||
customer = Customer.fromJson(jsonDecode(responseBody));
|
customer = Customer.fromJson(jsonDecode(responseBody));
|
||||||
log(" --- Trainee: " + customer.toJson().toString());
|
log(" --- Trainee: ${customer.toJson()}");
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
log("Exception: " + exception.toString());
|
log("Exception: $exception");
|
||||||
throw Exception(exception);
|
throw Exception(exception);
|
||||||
}
|
}
|
||||||
return customer;
|
return customer;
|
||||||
@ -164,11 +164,11 @@ class CustomerApi with Logging {
|
|||||||
log("Get trainees list");
|
log("Get trainees list");
|
||||||
try {
|
try {
|
||||||
String body = "";
|
String body = "";
|
||||||
final String responseBody = await _client.get("customers/trainees/" + trainerId.toString(), body);
|
final String responseBody = await _client.get("customers/trainees/$trainerId", body);
|
||||||
final Iterable json = jsonDecode(responseBody);
|
final Iterable json = jsonDecode(responseBody);
|
||||||
trainees = json.map((customer) => Customer.fromJson(customer)).toList();
|
trainees = json.map((customer) => Customer.fromJson(customer)).toList();
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
log("Exception: " + exception.toString());
|
log("Exception: $exception");
|
||||||
throw Exception(exception);
|
throw Exception(exception);
|
||||||
}
|
}
|
||||||
return trainees;
|
return trainees;
|
||||||
@ -195,45 +195,45 @@ class CustomerApi with Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<CustomerProperty> addProperty(CustomerProperty property) async {
|
Future<CustomerProperty> addProperty(CustomerProperty property) async {
|
||||||
String body = JsonEncoder().convert(property.toJson());
|
String body = const JsonEncoder().convert(property.toJson());
|
||||||
log(" ===== add new customer property: " + body);
|
log(" ===== add new customer property: $body");
|
||||||
CustomerProperty customerProperty;
|
CustomerProperty customerProperty;
|
||||||
String? responseBody;
|
String? responseBody;
|
||||||
try {
|
try {
|
||||||
responseBody = await _client.post("customer_property", body);
|
responseBody = await _client.post("customer_property", body);
|
||||||
log(" responseBody: " + responseBody);
|
log(" responseBody: $responseBody");
|
||||||
int? status = jsonDecode(responseBody)['status'];
|
int? status = jsonDecode(responseBody)['status'];
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
throw new Exception(jsonDecode(responseBody)['error']);
|
throw Exception(jsonDecode(responseBody)['error']);
|
||||||
} else {
|
} else {
|
||||||
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
||||||
}
|
}
|
||||||
} on FormatException {
|
} on FormatException {
|
||||||
throw new Exception(responseBody);
|
throw Exception(responseBody);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
throw new Exception(e);
|
throw Exception(e);
|
||||||
}
|
}
|
||||||
return customerProperty;
|
return customerProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CustomerProperty> updateProperty(CustomerProperty property) async {
|
Future<CustomerProperty> updateProperty(CustomerProperty property) async {
|
||||||
String body = JsonEncoder().convert(property.toJson());
|
String body = const JsonEncoder().convert(property.toJson());
|
||||||
CustomerProperty? customerProperty;
|
CustomerProperty? customerProperty;
|
||||||
log(" ===== update customer property: " + body);
|
log(" ===== update customer property: $body");
|
||||||
String? responseBody;
|
String? responseBody;
|
||||||
try {
|
try {
|
||||||
responseBody = await _client.post("customer_property/update/" + property.customerPropertyId.toString(), body);
|
responseBody = await _client.post("customer_property/update/${property.customerPropertyId}", body);
|
||||||
log(" responseBody: " + responseBody);
|
log(" responseBody: $responseBody");
|
||||||
int? status = jsonDecode(responseBody)['status'];
|
int? status = jsonDecode(responseBody)['status'];
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
throw new Exception(jsonDecode(responseBody)['error']);
|
throw Exception(jsonDecode(responseBody)['error']);
|
||||||
} else {
|
} else {
|
||||||
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
customerProperty = CustomerProperty.fromJson(jsonDecode(responseBody));
|
||||||
}
|
}
|
||||||
} on FormatException {
|
} on FormatException {
|
||||||
throw new Exception(responseBody);
|
throw Exception(responseBody);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
throw new Exception(e);
|
throw Exception(e);
|
||||||
}
|
}
|
||||||
return customerProperty;
|
return customerProperty;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ class ExerciseTreeApi with Logging {
|
|||||||
int treeIndex = 0;
|
int treeIndex = 0;
|
||||||
copyList.forEach((element) async {
|
copyList.forEach((element) async {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
exerciseTreeParents.forEach((parent) {
|
for (var parent in exerciseTreeParents) {
|
||||||
if (parent.exerciseTreeChildId == element.treeId) {
|
if (parent.exerciseTreeChildId == element.treeId) {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
ExerciseTree newElement = element.copy(parent.exerciseTreeParentId);
|
ExerciseTree newElement = element.copy(parent.exerciseTreeParentId);
|
||||||
@ -64,7 +64,7 @@ class ExerciseTreeApi with Logging {
|
|||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
treeIndex++;
|
treeIndex++;
|
||||||
});
|
});
|
||||||
return exerciseTree;
|
return exerciseTree;
|
||||||
|
@ -9,7 +9,7 @@ import 'package:workouttest_util/util/logging.dart';
|
|||||||
class OpenAIApi with Logging {
|
class OpenAIApi with Logging {
|
||||||
final String modelDavinci = "text-davinci-003";
|
final String modelDavinci = "text-davinci-003";
|
||||||
final String modelGpt35 = "gpt-3.5-turbo";
|
final String modelGpt35 = "gpt-3.5-turbo";
|
||||||
final String modelGpt4 = "gpt-4-32k";
|
final String modelGpt4 = "gpt-4";
|
||||||
final String modelAda = "text-embedding-ada-002";
|
final String modelAda = "text-embedding-ada-002";
|
||||||
final APIClient _client = APIClient();
|
final APIClient _client = APIClient();
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ class PackageApi {
|
|||||||
int treeIndex = 0;
|
int treeIndex = 0;
|
||||||
copyList.forEach((element) async {
|
copyList.forEach((element) async {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
exerciseTreeParents.forEach((parent) {
|
for (var parent in exerciseTreeParents) {
|
||||||
if (parent.exerciseTreeChildId == element.treeId) {
|
if (parent.exerciseTreeChildId == element.treeId) {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
ExerciseTree newElement = element.copy(parent.exerciseTreeParentId);
|
ExerciseTree newElement = element.copy(parent.exerciseTreeParentId);
|
||||||
@ -148,7 +148,7 @@ class PackageApi {
|
|||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
treeIndex++;
|
treeIndex++;
|
||||||
});
|
});
|
||||||
|
@ -67,7 +67,7 @@ class NumberPickerWidgetState extends State<NumberPickerWidget> {
|
|||||||
scrollController: _scrollController,
|
scrollController: _scrollController,
|
||||||
useMagnifier: true,
|
useMagnifier: true,
|
||||||
magnification: 1.2,
|
magnification: 1.2,
|
||||||
diameterRatio: widget.diameterRatio!,
|
//diameterRatio: widget.diameterRatio!,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
selectionOverlay: Container(),
|
selectionOverlay: Container(),
|
||||||
onSelectedItemChanged: (x) {
|
onSelectedItemChanged: (x) {
|
||||||
@ -80,10 +80,8 @@ class NumberPickerWidgetState extends State<NumberPickerWidget> {
|
|||||||
widget.onChange(value);
|
widget.onChange(value);
|
||||||
},
|
},
|
||||||
itemExtent: widget.itemExtent!,
|
itemExtent: widget.itemExtent!,
|
||||||
children: List.generate(
|
children: List.generate(widget.maxValue,
|
||||||
widget.maxValue,
|
(index) => Text('$index ${widget.unit}', style: TextStyle(color: widget.color, fontSize: widget.fontSize, fontWeight: widget.fontWeight))),
|
||||||
(index) => Text('$index ${widget.unit}',
|
|
||||||
style: TextStyle(color: widget.color, fontSize: widget.fontSize, fontWeight: widget.fontWeight))),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
pubspec.yaml
28
pubspec.yaml
@ -1,9 +1,9 @@
|
|||||||
name: workouttest_util
|
name: workouttest_util
|
||||||
description: Workout Test app and web functions.
|
description: Workout Test app and web functions.
|
||||||
version: 1.0.25
|
version: 1.1.4
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.18.6 <3.0.0"
|
sdk: ">=2.18.6 <4.0.0"
|
||||||
flutter: ">=1.17.0"
|
flutter: ">=1.17.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -12,24 +12,24 @@ dependencies:
|
|||||||
|
|
||||||
crypto: ^3.0.2
|
crypto: ^3.0.2
|
||||||
|
|
||||||
firebase_auth: ^4.3.0
|
firebase_auth: ^4.6.0
|
||||||
firebase_analytics: ^10.1.6
|
firebase_analytics: ^10.4.0
|
||||||
firebase_core: ^2.8.0
|
firebase_core: ^2.12.0
|
||||||
firebase_messaging: ^14.3.0
|
firebase_messaging: ^14.6.0
|
||||||
firebase_remote_config: ^3.0.15
|
firebase_remote_config: ^4.2.0
|
||||||
flutter_facebook_auth: ^5.0.7
|
flutter_facebook_auth: ^5.0.11
|
||||||
flutter_dotenv: ^5.0.2
|
flutter_dotenv: ^5.0.2
|
||||||
google_sign_in: ^6.0.2
|
google_sign_in: ^6.1.0
|
||||||
|
|
||||||
http: ^0.13.5
|
http: ^0.13.6
|
||||||
|
|
||||||
intl: ^0.17.0
|
intl: ^0.18.0
|
||||||
|
|
||||||
sign_in_with_apple: ^4.3.0
|
sign_in_with_apple: ^4.3.0
|
||||||
|
|
||||||
matomo_tracker: ^2.0.0
|
matomo_tracker: ^3.1.0
|
||||||
|
|
||||||
package_info_plus: ^3.0.2
|
package_info_plus: ^3.1.2
|
||||||
|
|
||||||
sentry_flutter: ^7.3.0
|
sentry_flutter: ^7.3.0
|
||||||
shared_preferences: ^2.0.20
|
shared_preferences: ^2.0.20
|
||||||
@ -42,7 +42,7 @@ dependencies:
|
|||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_lints: ^2.0.0
|
flutter_lints: ^2.0.1
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
assets:
|
assets:
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
import 'package:workouttest_util/model/customer.dart';
|
import 'package:workouttest_util/model/customer.dart';
|
||||||
|
import 'package:workouttest_util/model/customer_property.dart';
|
||||||
import 'package:workouttest_util/model/property.dart';
|
import 'package:workouttest_util/model/property.dart';
|
||||||
import 'package:workouttest_util/repository/customer_repository.dart';
|
import 'package:workouttest_util/repository/customer_repository.dart';
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
setUp(() {
|
setUp(() async {
|
||||||
|
await dotenv.load(fileName: "assets/.env");
|
||||||
String propertyJson = '''
|
String propertyJson = '''
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -113,4 +116,27 @@ main() {
|
|||||||
expect(customer.getProperty("Weight"), 66);
|
expect(customer.getProperty("Weight"), 66);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getPropertyDate', () {
|
||||||
|
var customer = Customer();
|
||||||
|
var propertyName = 'testDate';
|
||||||
|
|
||||||
|
var testDate = DateTime.now();
|
||||||
|
var expectedDate = DateFormat('yyyy-MM-dd').format(testDate);
|
||||||
|
|
||||||
|
String json = '''{
|
||||||
|
"customerPropertyId": 41,
|
||||||
|
"propertyId": 1,
|
||||||
|
"propertyValue": 82.0,
|
||||||
|
"dateAdd": "$expectedDate",
|
||||||
|
"goal": false
|
||||||
|
}''';
|
||||||
|
|
||||||
|
CustomerProperty property = CustomerProperty.fromJson(jsonDecode(json));
|
||||||
|
customer.properties[propertyName] = property;
|
||||||
|
|
||||||
|
var actualDate = customer.getPropertyDate(propertyName);
|
||||||
|
|
||||||
|
expect(actualDate, equals(expectedDate));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
50
test/model/membership_test.dart
Normal file
50
test/model/membership_test.dart
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:workouttest_util/model/membership.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('Membership', () {
|
||||||
|
test('fromJson() correctly sets properties', () {
|
||||||
|
final json = {
|
||||||
|
'membershipId': 1,
|
||||||
|
'name': 'Basic Membership',
|
||||||
|
'description': 'This is a basic membership',
|
||||||
|
'duration': 30,
|
||||||
|
'durationType': 'subscription',
|
||||||
|
'durationUnit': 'day',
|
||||||
|
'trainingPlanId': null,
|
||||||
|
'trainingPlanDayIds': null,
|
||||||
|
};
|
||||||
|
final membership = Membership.fromJson(json);
|
||||||
|
expect(membership.membershipId, 1);
|
||||||
|
expect(membership.name, 'Basic Membership');
|
||||||
|
expect(membership.description, 'This is a basic membership');
|
||||||
|
expect(membership.duration, 30);
|
||||||
|
expect(membership.durationType, DurationType.subscription);
|
||||||
|
expect(membership.durationUnit, DurationUnit.day);
|
||||||
|
expect(membership.trainingPlanId, 0);
|
||||||
|
expect(membership.trainingPlanDayIds, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('toJson() correctly returns a Map', () {
|
||||||
|
final membership = Membership()
|
||||||
|
..membershipId = 1
|
||||||
|
..name = 'Basic Membership'
|
||||||
|
..description = 'This is a basic membership'
|
||||||
|
..duration = 30
|
||||||
|
..durationType = DurationType.subscription
|
||||||
|
..durationUnit = DurationUnit.day
|
||||||
|
..trainingPlanId = null
|
||||||
|
..trainingPlanDayIds = null;
|
||||||
|
|
||||||
|
final json = membership.toJson();
|
||||||
|
expect(json['membershipId'], 1);
|
||||||
|
expect(json['name'], 'Basic Membership');
|
||||||
|
expect(json['description'], 'This is a basic membership');
|
||||||
|
expect(json['duration'], 30);
|
||||||
|
expect(json['durationType'], 'subscription');
|
||||||
|
expect(json['durationUnit'], 'day');
|
||||||
|
expect(json['trainingPlanId'], null);
|
||||||
|
expect(json['trainingPlanDayIds'], null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user