feat: add HeBIS HDS search

This commit is contained in:
Andy Bastian
2022-01-27 14:11:35 +00:00
committed by Jovan Krunić
parent e4165901bb
commit 9a3241c42a
42 changed files with 2109 additions and 23 deletions

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2018-2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Injectable} from '@angular/core';
import {Client} from '@openstapps/api/lib/client';
import {SCHebisSearchRequest} from './protocol/request';
import {SCHebisSearchResponse} from './protocol/response';
import {StorageProvider} from '../storage/storage.provider';
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
import {HttpClient} from '@angular/common/http';
import {DataProvider} from '../data/data.provider';
import {SCHebisSearchRoute} from './protocol/route';
/**
* Generated class for the DataProvider provider.
*
* See https://angular.io/guide/dependency-injection for more info on providers
* and Angular DI.
*/
@Injectable({
providedIn: 'root',
})
export class HebisDataProvider extends DataProvider {
/**
* TODO
*/
storageProvider: StorageProvider;
httpClient: HttpClient;
/**
* Instance of hebis search request route
*/
private readonly hebisSearchRoute = new SCHebisSearchRoute();
/**
* TODO
*
* @param stAppsWebHttpClient TODO
* @param storageProvider TODO
* @param httpClient TODO
*/
constructor(
stAppsWebHttpClient: StAppsWebHttpClient,
storageProvider: StorageProvider,
httpClient: HttpClient,
) {
super(stAppsWebHttpClient, storageProvider);
this.storageProvider = storageProvider;
this.httpClient = httpClient;
this.client = new Client(
stAppsWebHttpClient,
this.backendUrl,
this.appVersion,
);
}
/**
* Send a search request to the backend
*
* All results will be returned if no size is set in the request.
*
* @param searchRequest Search request
*/
async hebisSearch(
searchRequest: SCHebisSearchRequest,
): Promise<SCHebisSearchResponse> {
let page: number | undefined = searchRequest.page;
if (typeof page === 'undefined') {
const preFlightResponse =
await this.client.invokeRoute<SCHebisSearchResponse>(
this.hebisSearchRoute,
undefined,
{
...searchRequest,
page: 0,
},
);
page = preFlightResponse.pagination.total;
}
return this.client.invokeRoute<SCHebisSearchResponse>(
this.hebisSearchRoute,
undefined,
{
...searchRequest,
page,
},
);
}
}