diff --git a/README.md b/README.md index 32e6351..ffceeae 100644 --- a/README.md +++ b/README.md @@ -1,64 +1,89 @@ Workout Test and Diet 4 You Common Util Functions -Version 1.0.19 +### Version 1.0.20 + +webapi CORS + +### Version 1.0.19 + dotenv logging test -Version 1.0.18 +### Version 1.0.18 + debug by dotenv -Version 1.0.17 +### Version 1.0.17 + Webapi remove http.get utf8 decode -Version 1.0.16 +### Version 1.0.16 + Webapi utf8 decode -Version 1.0.15 +### Version 1.0.15 + AppText and translations -Version 1.0.14 +### Version 1.0.14 + OpenAI chat completion extension fix -Version 1.0.13 +### Version 1.0.13 + OpenAI chat completion extension -Version 1.0.12 +### Version 1.0.12 + CustomerProperty and CustomerMembership fromJson -Version 1.0.11 +### Version 1.0.11 + No FCM on Web -Version 1.0.11 +### Version 1.0.11 + Sentry and logging only in debugMode -Version 1.0.10 +### Version 1.0.10 + Firebase FCM for web -Version 1.0.9 +### Version 1.0.9 + Firebase web config -Version 1.0.8 +### Version 1.0.8 + mombership model error fix -Version 1.0.7 +### Version 1.0.7 + openai with model name and temperature -Version 1.0.6 +### Version 1.0.6 + membership, customer_membership -Version 1.0.5 +### Version 1.0.5 + number picker widget -Version 1.0.4 +### Version 1.0.4 + webapi client fixes -Version 1.0.3 +### Version 1.0.3 + Warning fixes, webapi client -Version 1.0.2 +### Version 1.0.2 + Open AI API support -Version 1.0.1 +### Version 1.0.1 + changes from aitrainer_app 1.1.29 working copy -Version 1.0.0 +### Version 1.0.0 + outsourced from aitrainer_app 1.1.28 diff --git a/assets/.env b/assets/.env index a9b22cf..8d957e6 100644 --- a/assets/.env +++ b/assets/.env @@ -1,2 +1,2 @@ dotenv=1 -debug=2 \ No newline at end of file +debug=1 \ No newline at end of file diff --git a/lib/service/webapi.dart b/lib/service/webapi.dart index 59c7db5..6c9d8dd 100644 --- a/lib/service/webapi.dart +++ b/lib/service/webapi.dart @@ -27,6 +27,7 @@ class APIWebClient with Common, Logging { final body = jsonEncode({'username': email, 'password': password}); var uri = Uri.parse(url); var result = await http.post(uri, body: body, headers: { + "Access-Control-Allow-Origin": 'https://*.diet4you.eu, https://*.diet4you.hu', "Content-Type": "application/json", "Authorization": "1", }); @@ -64,6 +65,7 @@ class APIWebClient with Common, Logging { } var uri = Uri.parse(url); var result = await http.post(uri, body: body, headers: { + "Access-Control-Allow-Origin": 'https://*.diet4you.eu, https://*.diet4you.hu', "Content-Type": "application/json", "Authorization": 'Bearer $authToken', }); @@ -97,7 +99,7 @@ class APIWebClient with Common, Logging { var uri = Uri.parse(url); var result = await http.get(uri, headers: { "Content-Type": "application/json", - //"Accept-Charset": 'utf-8', + "Access-Control-Allow-Origin": 'https://*.diet4you.eu, https://*.diet4you.hu', "Authorization": 'Bearer $authToken', }); diff --git a/pubspec.yaml b/pubspec.yaml index 076d992..378fe83 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: workouttest_util description: Workout Test app and web functions. -version: 1.0.19 +version: 1.0.20 environment: sdk: ">=2.18.6 <3.0.0" diff --git a/test/webapi_test.dart b/test/webapi_test.dart new file mode 100644 index 0000000..7ccf56a --- /dev/null +++ b/test/webapi_test.dart @@ -0,0 +1,44 @@ +import 'dart:convert'; + +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:workouttest_util/model/cache.dart'; +import 'package:workouttest_util/service/webapi.dart'; +import 'package:workouttest_util/util/logging.dart'; + +class LoggingTest with Logging {} + +main() { + late LoggingTest mockLogging; + setUp(() async { + mockLogging = LoggingTest(); + await dotenv.load(fileName: "assets/.env"); + Cache().setDietTestBaseUrl(); + }); + + group('api', () { + test('connect webapi auth successfully', () async { + var api = APIWebClient(); + var responseJson = await api.authenticateUser("bosi", "andio2009"); + print(responseJson); + Cache().authToken = responseJson['token']; + final body = await api.get("customers/72", ""); + print(body); + }); + + test('test customer conversation in utf8', () async { + var api = APIWebClient(); + var responseJson = await api.authenticateUser("bosi", "andio2009"); + print(responseJson); + Cache().authToken = responseJson['token']; + final body = await api.get("customer_conversation/72", ""); + + List bytes3 = base64.decode(body); + String decodedString = utf8.decode(bytes3); + print(decodedString); + + final body2 = await api.get("meal/21", ""); + print(body2); + }); + }); +}