Add new code new version
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / networks / SoftwareProductNetworksActionHelper.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 import {actionTypes} from './SoftwareProductNetworksConstants.js';
22 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
23 import Configuration from 'sdc-app/config/Configuration.js';
24
25 function baseUrl(svpId) {
26         const restPrefix = Configuration.get('restPrefix');
27         return `${restPrefix}/v1.0/vendor-software-products/${svpId}/networks`;
28 }
29
30
31 function fetchNetworksList(softwareProductId, version) {
32         let versionQuery = version ? `?version=${version}` : '';
33         return RestAPIUtil.fetch(`${baseUrl(softwareProductId)}${versionQuery}`);
34 }
35
36 const SoftwareProductNetworksActionHelper = {
37         fetchNetworksList(dispatch, {softwareProductId, version}) {
38                 return fetchNetworksList(softwareProductId, version).then(response => {
39                         dispatch({
40                                 type: actionTypes.FETCH_SOFTWARE_PRODUCT_NETWORKS,
41                                 networksList: response.results
42                         });
43                 });
44         }
45 };
46
47 export  default SoftwareProductNetworksActionHelper;