/**
 * Copyright 2019  The Hyve B.V.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */ import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { HttpHelper } from 'app/utilities/http-helper' ; import { AppConfig } from '../../config/app.config' ; import { CohortRepresentation } from '../../models/gb-backend-models/cohort-representation' ; import { Observable } from 'rxjs' ; @ Injectable ( { providedIn : 'root' } ) export class GbBackendHttpService { private httpHelper : HttpHelper ; private _endpointUrl : string ; constructor ( private appConfig , httpClient ) { if ( this . appConfig . isLoaded ) { this . endpointUrl = `${ this . appConfig . getConfig ( 'gb-backend-url' ) }` ; this . httpHelper = new HttpHelper ( this . endpointUrl , httpClient ) ; } } get endpointUrl ( ) : string { return this . _endpointUrl ; } set endpointUrl ( value ) { this . _endpointUrl = value ; } returns { Observable < Query [ ] > } getQueries ( ) { const urlPart = `queries` ; const responseField = 'queries' ; return this . httpHelper . getCall ( urlPart , responseField ) ; } param { CohortRepresentation } query returns { Observable < CohortRepresentation > } saveQuery ( query ) { const urlPart = `queries` ; return this . httpHelper . postCall ( urlPart , query , null ) ; } param { string } queryId param { Object } queryBody returns { Observable < Query > } updateQuery ( queryId , queryBody ) { const urlPart = `queries/${ queryId }` ; return this . httpHelper . putCall ( urlPart , queryBody ) ; } param { string } queryId returns { Observable < any > } deleteQuery ( queryId ) { const urlPart = `queries/${ queryId }` ; return this . httpHelper . deleteCall ( urlPart ) ; } param { string } queryId returns { Observable < object [ ] > } diffQuery ( queryId ) { const urlPart = `queries/${ queryId }/sets` ; const responseField = 'querySets' ; return this . httpHelper . getCall ( urlPart , responseField ) ; } }