From 0f63c18b4d9685b0339983f738bb8eca8c4da5d4 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Sat, 19 Jun 2021 14:30:33 +0200 Subject: [PATCH] update service generation + update section order --- .../configuration_detail_screen.dart | 11 ++-- .../Configurations/section_reorderList.dart | 28 ++++----- manager_api/README.md | 1 + manager_api/doc/SectionApi.md | 44 +++++++++++++ manager_api/lib/api/section_api.dart | 63 +++++++++++++++++++ manager_api/swagger.yaml | 62 +++++++++++++++--- 6 files changed, 181 insertions(+), 28 deletions(-) diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index fd08772..08a3ece 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -1,17 +1,13 @@ -import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/painting.dart'; import 'package:manager_app/Components/color_picker_input_container.dart'; import 'package:manager_app/Components/confirmation_dialog.dart'; -import 'package:manager_app/Components/fetch_section_icon.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/multi_select_container.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/Models/managerContext.dart'; -import 'package:manager_app/Screens/Configurations/listView_card_section.dart'; -import 'package:manager_app/Screens/Configurations/new_section_popup.dart'; import 'package:manager_app/Screens/Configurations/section_reorderList.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/client.dart'; @@ -260,6 +256,13 @@ class _ConfigurationDetailScreenState extends State { child: SectionReorderList( sectionsIn: sections, configurationId: configurationDTO.id, + onChangedOrder: (List sectionsOut) async { + sections = sectionsOut; + + // Update section order + ManagerAppContext managerAppContext = appContext.getContext(); + var result = await managerAppContext.clientAPI.sectionApi.sectionUpdateOrder(sections); + }, ), ), ), diff --git a/lib/Screens/Configurations/section_reorderList.dart b/lib/Screens/Configurations/section_reorderList.dart index 69603a6..784c522 100644 --- a/lib/Screens/Configurations/section_reorderList.dart +++ b/lib/Screens/Configurations/section_reorderList.dart @@ -13,10 +13,12 @@ import 'package:provider/provider.dart'; class SectionReorderList extends StatefulWidget { final String configurationId; final List sectionsIn; + final ValueChanged> onChangedOrder; const SectionReorderList({ Key key, this.configurationId, this.sectionsIn, + this.onChangedOrder, }) : super(key: key); @override @@ -34,22 +36,20 @@ class _SectionReorderListState extends State { void _onReorder(int oldIndex, int newIndex) { setState( - () { - if (newIndex > oldIndex) { - newIndex -= 1; - } - final SectionDTO item = sections.removeAt(oldIndex); - sections.insert(newIndex, item); + () { + if (newIndex > oldIndex) { + newIndex -= 1; + } + final SectionDTO item = sections.removeAt(oldIndex); + sections.insert(newIndex, item); - var i = 0; - sections.forEach((section) { - section.order = i; - i++; - }); + var i = 0; + sections.forEach((section) { + section.order = i; + i++; + }); - // TODO SAVE SECTION ALSO WHEN SAVE CONFIG - // TODO call method in service (create new) - // List of {section.id, section.order} + widget.onChangedOrder(sections); }, ); } diff --git a/manager_api/README.md b/manager_api/README.md index 7be03b3..2c1a06d 100644 --- a/manager_api/README.md +++ b/manager_api/README.md @@ -96,6 +96,7 @@ Class | Method | HTTP request | Description *SectionApi* | [**sectionGetVideoDTO**](doc\/SectionApi.md#sectiongetvideodto) | **GET** /api/Section/VideoDTO | *SectionApi* | [**sectionGetWebDTO**](doc\/SectionApi.md#sectiongetwebdto) | **GET** /api/Section/WebDTO | *SectionApi* | [**sectionUpdate**](doc\/SectionApi.md#sectionupdate) | **PUT** /api/Section | +*SectionApi* | [**sectionUpdateOrder**](doc\/SectionApi.md#sectionupdateorder) | **PUT** /api/Section/order | *UserApi* | [**userCreateUser**](doc\/UserApi.md#usercreateuser) | **POST** /api/User | *UserApi* | [**userDeleteUser**](doc\/UserApi.md#userdeleteuser) | **DELETE** /api/User/{id} | *UserApi* | [**userGet**](doc\/UserApi.md#userget) | **GET** /api/User | diff --git a/manager_api/doc/SectionApi.md b/manager_api/doc/SectionApi.md index 92c7e9b..f65ea2e 100644 --- a/manager_api/doc/SectionApi.md +++ b/manager_api/doc/SectionApi.md @@ -22,6 +22,7 @@ Method | HTTP request | Description [**sectionGetVideoDTO**](SectionApi.md#sectiongetvideodto) | **GET** /api/Section/VideoDTO | [**sectionGetWebDTO**](SectionApi.md#sectiongetwebdto) | **GET** /api/Section/WebDTO | [**sectionUpdate**](SectionApi.md#sectionupdate) | **PUT** /api/Section | +[**sectionUpdateOrder**](SectionApi.md#sectionupdateorder) | **PUT** /api/Section/order | # **sectionCreate** @@ -559,3 +560,46 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **sectionUpdateOrder** +> String sectionUpdateOrder(sectionDTO) + + + +### Example +```dart +import 'package:managerapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: bearer +//defaultApiClient.getAuthentication('bearer').accessToken = 'YOUR_ACCESS_TOKEN'; + +final api_instance = SectionApi(); +final sectionDTO = [List()]; // List | + +try { + final result = api_instance.sectionUpdateOrder(sectionDTO); + print(result); +} catch (e) { + print('Exception when calling SectionApi->sectionUpdateOrder: $e\n'); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **sectionDTO** | [**List**](SectionDTO.md)| | + +### Return type + +**String** + +### Authorization + +[bearer](../README.md#bearer) + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/manager_api/lib/api/section_api.dart b/manager_api/lib/api/section_api.dart index 4bfe7e8..ace0a5f 100644 --- a/manager_api/lib/api/section_api.dart +++ b/manager_api/lib/api/section_api.dart @@ -778,4 +778,67 @@ class SectionApi { } return Future.value(null); } + + /// Performs an HTTP 'PUT /api/Section/order' operation and returns the [Response]. + /// Parameters: + /// + /// * [List] sectionDTO (required): + Future sectionUpdateOrderWithHttpInfo(List sectionDTO) async { + // Verify required params are set. + if (sectionDTO == null) { + throw ApiException(HttpStatus.badRequest, 'Missing required param: sectionDTO'); + } + + final path = r'/api/Section/order'; + + Object postBody = sectionDTO; + + final queryParams = []; + final headerParams = {}; + final formParams = {}; + + final contentTypes = ['application/json']; + final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; + final authNames = ['bearer']; + + if ( + nullableContentType != null && + nullableContentType.toLowerCase().startsWith('multipart/form-data') + ) { + bool hasFields = false; + final mp = MultipartRequest(null, null); + if (hasFields) { + postBody = mp; + } + } else { + } + + return await apiClient.invokeAPI( + path, + 'PUT', + queryParams, + postBody, + headerParams, + formParams, + nullableContentType, + authNames, + ); + } + + /// Parameters: + /// + /// * [List] sectionDTO (required): + Future sectionUpdateOrder(List sectionDTO) async { + final response = await sectionUpdateOrderWithHttpInfo(sectionDTO); + if (response.statusCode >= HttpStatus.badRequest) { + throw ApiException(response.statusCode, _decodeBodyBytes(response)); + } + // When a remote server returns no body with a status of 204, we shall not decode it. + // 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), 'String') as String; + } + return Future.value(null); + } } diff --git a/manager_api/swagger.yaml b/manager_api/swagger.yaml index cbdf2a3..35a6622 100644 --- a/manager_api/swagger.yaml +++ b/manager_api/swagger.yaml @@ -5,7 +5,7 @@ info: description: API Manager Service version: Version Alpha servers: - - url: 'http://192.168.31.96' + - url: http://192.168.31.96 paths: /api/Configuration: get: @@ -107,7 +107,7 @@ paths: type: string security: - bearer: [] - '/api/Configuration/{id}': + /api/Configuration/{id}: get: tags: - Configuration @@ -278,7 +278,7 @@ paths: type: string security: - bearer: [] - '/api/Device/{id}/detail': + /api/Device/{id}/detail: get: tags: - Device @@ -310,7 +310,7 @@ paths: application/json: schema: type: string - '/api/Device/{id}': + /api/Device/{id}: delete: tags: - Device @@ -450,7 +450,7 @@ paths: type: string security: - bearer: [] - '/api/Resource/{id}/detail': + /api/Resource/{id}/detail: get: tags: - Resource @@ -482,7 +482,7 @@ paths: application/json: schema: type: string - '/api/Resource/{id}': + /api/Resource/{id}: get: tags: - Resource @@ -689,7 +689,7 @@ paths: type: string security: - bearer: [] - '/api/Section/configuration/{id}': + /api/Section/configuration/{id}: get: tags: - Section @@ -758,7 +758,7 @@ paths: type: string security: - bearer: [] - '/api/Section/{id}/subsections': + /api/Section/{id}/subsections: get: tags: - Section @@ -793,7 +793,7 @@ paths: type: string security: - bearer: [] - '/api/Section/{id}': + /api/Section/{id}: get: tags: - Section @@ -864,6 +864,48 @@ paths: type: string security: - bearer: [] + /api/Section/order: + put: + tags: + - Section + operationId: Section_UpdateOrder + requestBody: + x-name: updatedSectionsOrder + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/SectionDTO' + required: true + x-position: 1 + responses: + '200': + description: '' + content: + application/json: + schema: + type: string + '400': + description: '' + content: + application/json: + schema: + type: string + '404': + description: '' + content: + application/json: + schema: + type: string + '500': + description: '' + content: + application/json: + schema: + type: string + security: + - bearer: [] /api/Section/MapDTO: get: tags: @@ -1032,7 +1074,7 @@ paths: type: string security: - bearer: [] - '/api/User/{id}': + /api/User/{id}: get: tags: - User