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