Skip to content

Commit 4e4d5f8

Browse files
author
Huaqiao Zhang
committed
refactor: the whole app svc service had been refactor
Signed-off-by: Huaqiao Zhang <huaqiaoz@vmware.com>
1 parent 3651550 commit 4e4d5f8

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

web/src/app/services/app-service.service.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
1+
/*******************************************************************************
2+
* Copyright © 2021-2022 VMware, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*
14+
* @author: Huaqiao Zhang, <huaqiaoz@vmware.com>
15+
*******************************************************************************/
16+
117
import { HttpClient, HttpHeaders } from '@angular/common/http';
218
import { Injectable } from '@angular/core';
319
import { Observable } from 'rxjs';
420
import { catchError } from 'rxjs/operators';
521
import { ErrorService } from './error.service';
6-
import { AppService } from '../contracts/v2/app-service/app-service';
22+
723

824
@Injectable({
925
providedIn: 'root'
1026
})
1127
export class AppServiceService {
1228

13-
endpoint: string = "/app-service";
29+
1430
version: string = "/api/v2";
1531

16-
appServiceUrl: string = `${this.endpoint}${this.version}`;
32+
appSvcDeployConfigUrl: string = `${this.version}/appsvc/deploy/servicekey`;
33+
appSvcGetConfigUrl: string = `${this.version}/appsvc/config/servicekey`;
1734

1835
httpPostOrPutJSONOptions = {
1936
headers: new HttpHeaders({
@@ -24,27 +41,16 @@ export class AppServiceService {
2441

2542
constructor(private http: HttpClient, private errorSvc: ErrorService) { }
2643

27-
getAppServiceConfig(): Observable<AppService> {
28-
let url = `${this.appServiceUrl}/config`;
29-
return this.http.get<AppService>(url).pipe(
30-
catchError(error => this.errorSvc.handleError(error))
31-
)
32-
}
33-
34-
downloadAppServiceConfig(serviceKey: string): Observable<any> {
35-
let url = `${this.version}/appservice/download/servicekey/`+ serviceKey;
36-
return this.http.get(url, {
37-
responseType: "blob",
38-
observe: 'response',
39-
headers: new HttpHeaders().append("Content-Type", "application/json")
40-
}).pipe(
44+
getAppSvcConfigBySvcKey(svcKey: string): Observable<any> {
45+
let url = `${this.appSvcGetConfigUrl}/${svcKey}`;
46+
return this.http.get(url).pipe(
4147
catchError(error => this.errorSvc.handleError(error))
4248
)
4349
}
4450

45-
deployToConsul(appServiceWritable: any,serviceKey: string): Observable<string> {
46-
let url = `${this.version}/appservice/deploy/servicekey/`+ serviceKey;
47-
return this.http.post<string>(url,JSON.stringify(appServiceWritable), this.httpPostOrPutJSONOptions)
51+
deployToConsul(appServiceWritable: any,svcKey: string): Observable<any> {
52+
let url = `${this.appSvcDeployConfigUrl}/${svcKey}`;
53+
return this.http.post(url,JSON.stringify(appServiceWritable), this.httpPostOrPutJSONOptions)
4854
.pipe(
4955
catchError(error => this.errorSvc.handleError(error))
5056
)

0 commit comments

Comments
 (0)