v1.0.12 customer properties and membership
This commit is contained in:
parent
6ac35b67ab
commit
31717c6c5e
6
.gitignore
vendored
6
.gitignore
vendored
@ -25,8 +25,8 @@ migrate_working_dir/
|
|||||||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||||
/pubspec.lock
|
/pubspec.lock
|
||||||
**/doc/api/
|
**/doc/api/
|
||||||
.dart_tool/
|
|
||||||
.packages
|
.packages
|
||||||
build/
|
build/
|
||||||
.flutter-plugins-dependencies
|
.dart_tool/
|
||||||
.flutter-plugins
|
.flutter-plugins
|
||||||
|
.flutter-plugins-dependencies
|
9
.vscode/settings.json
vendored
Normal file
9
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"dart.lineLength": 150,
|
||||||
|
"[dart]": {
|
||||||
|
"editor.rulers": [
|
||||||
|
150
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
Workout Test and Diet 4 You Common Util Functions
|
Workout Test and Diet 4 You Common Util Functions
|
||||||
|
|
||||||
|
Version 1.0.12
|
||||||
|
CustomerProperty and CustomerMembership fromJson
|
||||||
|
|
||||||
Version 1.0.11
|
Version 1.0.11
|
||||||
Sentry and logging only in debugMode
|
Sentry and logging only in debugMode
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:workouttest_util/model/customer_membership.dart';
|
||||||
|
|
||||||
import 'customer_property.dart';
|
import 'customer_property.dart';
|
||||||
|
|
||||||
@ -31,6 +32,8 @@ class Customer {
|
|||||||
int? lifeLong;
|
int? lifeLong;
|
||||||
|
|
||||||
LinkedHashMap<String, CustomerProperty> properties = LinkedHashMap();
|
LinkedHashMap<String, CustomerProperty> properties = LinkedHashMap();
|
||||||
|
List<CustomerProperty> customerProperties = [];
|
||||||
|
List<CustomerMembership> memberships = [];
|
||||||
|
|
||||||
Customer(
|
Customer(
|
||||||
{customerId,
|
{customerId,
|
||||||
@ -83,6 +86,14 @@ class Customer {
|
|||||||
|
|
||||||
dateAdd = json['dateAdd'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateAdd']);
|
dateAdd = json['dateAdd'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateAdd']);
|
||||||
dateChange = json['dateChange'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateChange']);
|
dateChange = json['dateChange'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateChange']);
|
||||||
|
|
||||||
|
if (json['properties'] != null && json['properties'].length > 0) {
|
||||||
|
customerProperties = json['properties'].map<CustomerProperty>((detail) => CustomerProperty.fromJson(detail)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json['memberships'] != null && json['memberships'].length > 0) {
|
||||||
|
memberships = json['memberships'].map<CustomerMembership>((detail) => CustomerMembership.fromJson(detail)).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class CustomerMembership {
|
class CustomerMembership {
|
||||||
late int membershipId;
|
late int membershipId;
|
||||||
late int customerId;
|
int? customerId;
|
||||||
late DateTime startDate;
|
DateTime? startDate;
|
||||||
|
|
||||||
|
|
||||||
CustomerMembership.fromJson(Map json) {
|
CustomerMembership.fromJson(Map json) {
|
||||||
membershipId = json['membershipId'];
|
membershipId = json['membershipId'];
|
||||||
customerId = json['customerId'];
|
customerId = json['customerId'] ?? 0;
|
||||||
startDate = json['startDate'];
|
startDate = json['startDate'] == null ? null : DateTime.parse(json['startDate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
"membershipId": membershipId,
|
"membershipId": membershipId,
|
||||||
"customerId": customerId,
|
"customerId": customerId ?? 0,
|
||||||
"startDate": startDate,
|
"startDate": startDate == null ? "" : DateFormat('yyyy-MM-dd HH:mm:ss').format(startDate!),
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => toJson().toString();
|
String toString() => toJson().toString();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import '../util/logging.dart';
|
|||||||
class CustomerProperty with Logging {
|
class CustomerProperty with Logging {
|
||||||
int? customerPropertyId;
|
int? customerPropertyId;
|
||||||
late int propertyId;
|
late int propertyId;
|
||||||
late int customerId;
|
int? customerId;
|
||||||
DateTime? dateAdd;
|
DateTime? dateAdd;
|
||||||
String? dateYmd;
|
String? dateYmd;
|
||||||
String? dateYm;
|
String? dateYm;
|
||||||
@ -12,16 +12,12 @@ class CustomerProperty with Logging {
|
|||||||
late double propertyValue;
|
late double propertyValue;
|
||||||
bool newData = false;
|
bool newData = false;
|
||||||
|
|
||||||
CustomerProperty(
|
CustomerProperty({required propertyId, required customerId, required dateAdd, required propertyValue});
|
||||||
{required propertyId,
|
|
||||||
required customerId,
|
|
||||||
required dateAdd,
|
|
||||||
required propertyValue});
|
|
||||||
|
|
||||||
CustomerProperty.fromJson(Map json) {
|
CustomerProperty.fromJson(Map json) {
|
||||||
customerPropertyId = json['customerPropertyId'];
|
customerPropertyId = json['customerPropertyId'];
|
||||||
propertyId = json['propertyId'];
|
propertyId = json['propertyId'];
|
||||||
customerId = json['customerId'];
|
customerId = json['customerId'] ?? 0;
|
||||||
dateAdd = DateTime.parse(json['dateAdd']);
|
dateAdd = DateTime.parse(json['dateAdd']);
|
||||||
|
|
||||||
if (dateAdd != null) {
|
if (dateAdd != null) {
|
||||||
@ -40,14 +36,14 @@ class CustomerProperty with Logging {
|
|||||||
return {
|
return {
|
||||||
"customerPropertyId": customerPropertyId,
|
"customerPropertyId": customerPropertyId,
|
||||||
"propertyId": propertyId,
|
"propertyId": propertyId,
|
||||||
"customerId": customerId,
|
"customerId": customerId ?? 0,
|
||||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
|
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
|
||||||
"propertyValue": propertyValue
|
"propertyValue": propertyValue
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
"propertyId": propertyId,
|
"propertyId": propertyId,
|
||||||
"customerId": customerId,
|
"customerId": customerId ?? 0,
|
||||||
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
|
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
|
||||||
"propertyValue": propertyValue
|
"propertyValue": propertyValue
|
||||||
};
|
};
|
||||||
|
@ -566,4 +566,34 @@ class CustomerRepository with Logging {
|
|||||||
}
|
}
|
||||||
return allProperties;
|
return allProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initCustomerProperties() {
|
||||||
|
List<Property>? properties = Cache().getProperties();
|
||||||
|
Customer? customer = Cache().userLoggedIn;
|
||||||
|
if (customer == null || customer.customerProperties.isEmpty || properties == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var property in properties) {
|
||||||
|
CustomerProperty? customerProperty = getCustomerPropertyById(property.propertyId);
|
||||||
|
if (customerProperty != null) {
|
||||||
|
customer.properties[property.propertyName] = customerProperty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomerProperty? getCustomerPropertyById(int id) {
|
||||||
|
CustomerProperty? property;
|
||||||
|
Customer? customer = Cache().userLoggedIn;
|
||||||
|
if (customer == null) {
|
||||||
|
return property;
|
||||||
|
}
|
||||||
|
for (var customerProperty in customer.customerProperties) {
|
||||||
|
if (customerProperty.propertyId == id) {
|
||||||
|
property = customerProperty;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return property;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: workouttest_util
|
name: workouttest_util
|
||||||
description: Workout Test app and web functions.
|
description: Workout Test app and web functions.
|
||||||
version: 1.0.10
|
version: 1.0.12
|
||||||
homepage:
|
homepage:
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
118
test/customer_test.dart
Normal file
118
test/customer_test.dart
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
|
import 'package:workouttest_util/model/customer.dart';
|
||||||
|
import 'package:workouttest_util/model/property.dart';
|
||||||
|
import 'package:workouttest_util/repository/customer_repository.dart';
|
||||||
|
import 'dart:collection';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
main() {
|
||||||
|
setUp(() {
|
||||||
|
String propertyJson = '''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"propertyId": 1,
|
||||||
|
"propertyName": "Weight",
|
||||||
|
"propertyUnit": "kg",
|
||||||
|
"translations": [
|
||||||
|
{
|
||||||
|
"translationId": 11,
|
||||||
|
"languageCode": "hu",
|
||||||
|
"propertyName": "Tömeg"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"propertyId": 2,
|
||||||
|
"propertyName": "Height",
|
||||||
|
"propertyUnit": "cm",
|
||||||
|
"translations": [
|
||||||
|
{
|
||||||
|
"translationId": 12,
|
||||||
|
"languageCode": "hu",
|
||||||
|
"propertyName": "Magasság"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"propertyId": 3,
|
||||||
|
"propertyName": "Chest",
|
||||||
|
"propertyUnit": "cm",
|
||||||
|
"translations": [
|
||||||
|
{
|
||||||
|
"translationId": 13,
|
||||||
|
"languageCode": "hu",
|
||||||
|
"propertyName": "Mell"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
''';
|
||||||
|
Iterable json = jsonDecode(propertyJson);
|
||||||
|
final List<Property> properties = json.map((property) => Property.fromJson(property)).toList();
|
||||||
|
Cache().setProperties(properties);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('customer', () {
|
||||||
|
test('decode from json successful', () async {
|
||||||
|
String json = '''{
|
||||||
|
"name": "",
|
||||||
|
"firstname": "Andi",
|
||||||
|
"email": "mr@aitrainer.app",
|
||||||
|
"age": 0,
|
||||||
|
"sex": "m",
|
||||||
|
"active": "Y",
|
||||||
|
"dateAdd": "2023-02-25 11:19:30",
|
||||||
|
"dataPolicyAllowed": 1,
|
||||||
|
"password": "2a10O5HXhhb29LC8pNiv1uBIoOFRGOmDMtdeMJtVkfhzAjB/ejrO9D486",
|
||||||
|
"birthYear": 1974,
|
||||||
|
"goal": "health_keep",
|
||||||
|
"fitnessLevel": "intermediate",
|
||||||
|
"firebaseUid": "ih74dupj2ncyROAaeyK8oAXYOWk2",
|
||||||
|
"emailSubscription": 0,
|
||||||
|
"firebaseRegToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjE1YzJiNDBhYTJmMzIyNzk4NjY2YTZiMzMyYWFhMDNhNjc3MzAxOWIiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZGlldDR5b3UtY2I1NDAiLCJhdWQiOiJkaWV0NHlvdS1jYjU0MCIsImF1dGhfdGltZSI6MTY3NzMyMDM3MSwidXNlcl9pZCI6ImloNzRkdXBqMm5jeVJPQWFleUs4b0FYWU9XazIiLCJzdWIiOiJpaDc0ZHVwajJuY3lST0FhZXlLOG9BWFlPV2syIiwiaWF0IjoxNjc3MzIwMzcxLCJleHAiOjE2NzczMjM5NzEsImVtYWlsIjoibXJAYWl0cmFpbmVyLmFwcCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJtckBhaXRyYWluZXIuYXBwIl19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifX0.yds_4NSc1m7U7q6y1jdHy61Z1Y_4weOWfC_mbvzQsGLqsuOuP_SM6OvhqQOjywAWGhvm709mydm9nWdhhPNDNTcC5pn8Xl770GYoMF_8tLPae8Mrw-9ppFvXNHXg0kKpl2uIirjMhZM19fq4HBLJPAReQ8-8FCHfodXRd5TH5EWSZnZ-TzdwvKaitfjn_-2w4tA1WepH4XhCwP908NG-U6IUwBOsi_aoQpQwSJWL9HwW1pTsYSE0DubfKOmsMBH3WaVkkJfcL1IOGBR4TK-vimkfmP2VnU3F88GF583b1FKw-JZ6ovOBy4jHnL02k_yAQksMwHXeaSGMwulWdjxqHQ",
|
||||||
|
"customerId": 56,
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"customerPropertyId": 3,
|
||||||
|
"propertyId": 1,
|
||||||
|
"propertyValue": 66.0,
|
||||||
|
"dateAdd": "2023-02-25 11:19:30",
|
||||||
|
"goal": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"customerPropertyId": 4,
|
||||||
|
"propertyId": 2,
|
||||||
|
"propertyValue": 178.0,
|
||||||
|
"dateAdd": "2023-02-25 11:19:30",
|
||||||
|
"goal": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"memberships": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"membershipId": 2,
|
||||||
|
"startDate": "2023-02-25 11:19:30"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}''';
|
||||||
|
|
||||||
|
Customer customer = Customer.fromJson(jsonDecode(json));
|
||||||
|
expect(customer.customerId, 56);
|
||||||
|
expect(customer.customerProperties.length, 2);
|
||||||
|
expect(customer.customerProperties[0].propertyValue, 66);
|
||||||
|
expect(customer.customerProperties[1].propertyId, 2);
|
||||||
|
expect(customer.memberships.length, 1);
|
||||||
|
expect(customer.memberships[0].membershipId, 2);
|
||||||
|
Cache().userLoggedIn = customer;
|
||||||
|
CustomerRepository repository = CustomerRepository();
|
||||||
|
repository.initCustomerProperties();
|
||||||
|
|
||||||
|
customer = Cache().userLoggedIn!;
|
||||||
|
expect(customer.properties.length, 2);
|
||||||
|
expect(customer.getProperty("Weight"), 66);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user