Skip to content

Commit

Permalink
Merge pull request #453 from chrisvpeters/AUS-4265
Browse files Browse the repository at this point in the history
AUS-4265
  • Loading branch information
vjf authored Nov 20, 2024
2 parents 62b89c5 + 8f5544a commit 96b6e07
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/app/services/api/auscope-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interface ApiResponse<T> {
function apiData<T>(response: ApiResponse<T>): Observable<T> {
// Convert a VGL error into an Observable error
if (!response.success) {
console.log('API response error: ' + JSON.stringify(response));
return throwError(response.msg);
}

Expand Down Expand Up @@ -54,12 +53,26 @@ export class AuscopeApiService {
return this.http.post<ApiResponse<T>>(url, body, opts).pipe(switchMap(apiData));
}

private apiPostJson<T>(endpoint: string, params = {}, options = {}): Observable<T> {
const url = environment.portalProxyUrl + endpoint;
const body = params;
const opts: { observe: 'body' } = { ...options, observe: 'body' };

return this.http.post<ApiResponse<T>>(url, body, opts).pipe(switchMap(apiData));
}

private apiGet<T>(endpoint: string, params = {}, options?): Observable<T> {
const url = environment.portalProxyUrl + endpoint;
const opts: { observe: 'body' } = { ...options, observe: 'body', params: params };
return this.http.get<ApiResponse<T>>(url, opts).pipe(switchMap(apiData));
}

private apiDelete<T>(endpoint: string, params = {}, options?): Observable<T> {
const url = environment.portalProxyUrl + endpoint;
const opts: { observe: 'body' } = { ...options, observe: 'body', params: params };
return this.http.delete<ApiResponse<T>>(url, opts).pipe(switchMap(apiData));
}

public getWmsCapabilities(serviceUrl: string, version: string): Observable<any> {
if (serviceUrl.indexOf('?') !== -1) {
serviceUrl = serviceUrl.substring(0, serviceUrl.indexOf('?'));
Expand Down Expand Up @@ -90,28 +103,21 @@ export class AuscopeApiService {

// Add bookmark to database
public addBookmark(layerId: string): Observable<number> {
const options = {
params: {
const params = {
fileIdentifier: layerId,
serviceId: ''
}
};
return this.apiRequest('secure/addBookMark.do', options);
return this.apiPostJson('bookmarks', params);
}

// Remove bookmark information from database
public removeBookmark(bookmarkId: number) {
const options = {
params: {
id: bookmarkId.toString()
}
};
return this.apiRequest('secure/deleteBookMark.do', options);
return this.apiDelete('bookmarks/'+bookmarkId.toString());
}

// Get list of bookmarks for a user
public getBookmarks(): Observable<Bookmark[]> {
return this.apiRequest('secure/getBookMarks.do');
return this.apiRequest('bookmarks');
}

/**
Expand Down

0 comments on commit 96b6e07

Please sign in to comment.