diff --git a/lib/client.dart b/lib/client.dart index d66630e..409183c 100644 --- a/lib/client.dart +++ b/lib/client.dart @@ -14,8 +14,20 @@ class Client { UserApi _userApi; UserApi get userApi => _userApi; - ValuesApi _valuesApi; - ValuesApi get valuesApi => _valuesApi; + GroupApi _groupApi; + GroupApi get groupApi => _groupApi; + + DeviceApi _deviceApi; + DeviceApi get deviceApi => _deviceApi; + + AutomationApi _automationApi; + AutomationApi get automationApi => _automationApi; + + ProviderApi _providerApi; + ProviderApi get providerApi => _providerApi; + + RoomApi _roomApi; + RoomApi get roomApi => _roomApi; Client() { _apiClient = ApiClient( @@ -24,6 +36,10 @@ class Client { _tokenApi = TokenApi(_apiClient); _authenticationApi = AuthenticationApi(_apiClient); _userApi = UserApi(_apiClient); - _valuesApi = ValuesApi(_apiClient); + _groupApi = GroupApi(_apiClient); + _deviceApi = DeviceApi(_apiClient); + _automationApi = AutomationApi(_apiClient); + _providerApi = ProviderApi(_apiClient); + _roomApi = RoomApi(_apiClient); } } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 64560eb..eb3dec2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -85,15 +85,55 @@ class _MyHomePageState extends State { void authenticateTRY() async { print("try auth.. "); - LoginDTO loginDTO = new LoginDTO(email: "test@email.be", password: "kljqsdkljqsd"); - var user2 = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); - print("USER ??"); - print(user2); - // TODO Call authenticationAuthenticateWithJson to retrieve token and set apiclient bearer token with the result + var isError = true; + try { + LoginDTO loginDTO = new LoginDTO(email: "test@email.be", password: "kljqsdkljqsd"); + TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); + print("Token ??"); + print(token.accessToken); + setAccessToken(token.accessToken); + isError = false; + } + catch (e) { + print("error auth"); + } - var user23 = await clientAPI.userApi.userGet("604a33639b4a377a413045b9"); - print("user2 values ??"); - print(user23.email); + if (!isError) { + UserInfoDetailDTO user = await clientAPI.userApi.userGet("604a33639b4a377a413045b9"); + print("user values ??"); + print(user.email); + print(user.id); + + List rooms = await clientAPI.roomApi.roomGetAll(user.id); + print("number of rooms " + rooms.length.toString()); + rooms.forEach((element) { + print(element); + }); + + List providers = await clientAPI.providerApi.providerGetAll(user.id); + print("number of providers " + providers.length.toString()); + providers.forEach((element) { + print(element); + }); + + List devices = await clientAPI.deviceApi.deviceGetAll(user.id); + print("number of devices " + devices.length.toString()); + /*devices.forEach((element) { + print(element); + });*/ + + List automations = await clientAPI.automationApi.automationGetAll(user.id); + print("number of automations " + automations.length.toString()); + automations.forEach((element) { + print(element); + }); + + List groups = await clientAPI.groupApi.groupGetAll(user.id); + print("number of groups " + groups.length.toString()); + groups.forEach((element) { + print(element); + }); + } } // connection succeeded @@ -107,6 +147,14 @@ class _MyHomePageState extends State { });*/ } + void setAccessToken(String accessToken) { + clientAPI.apiApi.authentications.forEach((key, auth) { + if (auth is OAuth) { + auth.accessToken = accessToken; + } + }); + } + // unconnected void onDisconnected() { print('Disconnected'); diff --git a/mycore_api/lib/api/automation_api.dart b/mycore_api/lib/api/automation_api.dart index db42f23..ef6cf41 100644 --- a/mycore_api/lib/api/automation_api.dart +++ b/mycore_api/lib/api/automation_api.dart @@ -284,7 +284,7 @@ class AutomationApi { /// /// * [String] userId (required): /// Id of user - Future> automationGetAll(String userId) async { + Future> automationGetAll(String userId) async { final response = await automationGetAllWithHttpInfo(userId); if (response.statusCode >= HttpStatus.badRequest) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); @@ -293,11 +293,11 @@ class AutomationApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List) - .cast() + return (apiClient.deserialize(_decodeBodyBytes(response), 'List') as List) + .cast() .toList(growable: false); } - return Future>.value(null); + return Future>.value(null); } /// Get detail info of a specified automation