mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-05 13:02:54 +00:00
refactor: remove inheritance from daia provider
This commit is contained in:
@@ -102,10 +102,10 @@ describe('DaiaAvailabilityComponent', () => {
|
||||
beforeEach(async () => {
|
||||
dataProvider = TestBed.get(DaiaDataProvider);
|
||||
const workingDAIAurl = 'https://daia.hebis.de/DAIA2/UB_Frankfurt';
|
||||
dataProvider.backendUrl = workingDAIAurl;
|
||||
dataProvider.daiaServiceUrl = workingDAIAurl;
|
||||
translateService = TestBed.get(TranslateService);
|
||||
refresher = jasmine.createSpyObj('refresher', ['complete']);
|
||||
spyOn(dataProvider, 'get' as any).and.returnValue(
|
||||
spyOn(dataProvider, 'getAvailability' as any).and.returnValue(
|
||||
Promise.resolve(sampleThing),
|
||||
);
|
||||
spyOn(
|
||||
|
||||
@@ -13,15 +13,11 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Client} from '@openstapps/api/lib/client';
|
||||
import {SCDaiaAvailabilityResponse, SCDaiaHoldings} 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 {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {ConfigProvider} from '../config/config.provider';
|
||||
import {SCFeatureConfiguration} from '@openstapps/core';
|
||||
import {environment} from '../../../environments/environment';
|
||||
import {NGXLogger} from 'ngx-logger';
|
||||
|
||||
/**
|
||||
@@ -33,7 +29,7 @@ import {NGXLogger} from 'ngx-logger';
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DaiaDataProvider extends DataProvider {
|
||||
export class DaiaDataProvider {
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@@ -43,43 +39,41 @@ export class DaiaDataProvider extends DataProvider {
|
||||
|
||||
configProvider: ConfigProvider;
|
||||
|
||||
backendUrl = environment.backend_url;
|
||||
daiaServiceUrl: string | undefined;
|
||||
|
||||
clientHeaders = new HttpHeaders();
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @param stAppsWebHttpClient TODO
|
||||
* @param storageProvider TODO
|
||||
* @param httpClient TODO
|
||||
* @param configProvider TODO
|
||||
* @param logger TODO
|
||||
*/
|
||||
constructor(
|
||||
stAppsWebHttpClient: StAppsWebHttpClient,
|
||||
storageProvider: StorageProvider,
|
||||
httpClient: HttpClient,
|
||||
configProvider: ConfigProvider,
|
||||
private readonly logger: NGXLogger,
|
||||
) {
|
||||
super(stAppsWebHttpClient, storageProvider);
|
||||
this.storageProvider = storageProvider;
|
||||
this.httpClient = httpClient;
|
||||
this.configProvider = configProvider;
|
||||
this.client = new Client(
|
||||
stAppsWebHttpClient,
|
||||
this.backendUrl,
|
||||
this.appVersion,
|
||||
this.clientHeaders = this.clientHeaders.set(
|
||||
'Content-Type',
|
||||
'application/json',
|
||||
);
|
||||
}
|
||||
|
||||
async getAvailability(id: string): Promise<SCDaiaHoldings[] | undefined> {
|
||||
if (this.backendUrl === environment.backend_url) {
|
||||
if (typeof this.daiaServiceUrl === 'undefined') {
|
||||
try {
|
||||
const features = (await this.configProvider.getValue(
|
||||
'features',
|
||||
)) as SCFeatureConfiguration;
|
||||
if (features.extern?.daia?.url) {
|
||||
this.backendUrl = features.extern?.daia?.url;
|
||||
this.daiaServiceUrl = features.extern?.daia?.url;
|
||||
} else {
|
||||
this.logger.error('Daia service url undefined');
|
||||
return undefined;
|
||||
@@ -89,9 +83,11 @@ export class DaiaDataProvider extends DataProvider {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise(resolve =>
|
||||
this.httpClient
|
||||
.get<SCDaiaAvailabilityResponse>(this.backendUrl, {params: {id}})
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
.get<SCDaiaAvailabilityResponse>(this.daiaServiceUrl!, {params: {id}})
|
||||
.subscribe(
|
||||
(response: SCDaiaAvailabilityResponse) => {
|
||||
const holdings: SCDaiaHoldings[] = [];
|
||||
|
||||
Reference in New Issue
Block a user