information-system-gui/src/main/webapp/app/services/restypes.service.ts

42 lines
1.5 KiB
TypeScript

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { IResource} from './i-resource';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { IResourceType } from './i-resource-type';
@Injectable({
providedIn: 'root',
})
export class RestypesService {
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
constructor(private http: HttpClient, private applicationConfigService: ApplicationConfigService){}
//TODO: pipe per gestione errori
fetchAll(): Observable<IResource[]> {
const resourceUrl = this.applicationConfigService.getEndpointFor('api/is/resourcetypes');
return this.http.get<IResource[]>(resourceUrl);
}
fetchOne(name:string): Observable<IResourceType> {
const resourceUrl = this.applicationConfigService.getEndpointFor('api/is/resourcetype');
let queryParams = new HttpParams();
queryParams = queryParams.append("typeName",name);
return this.http.get<IResourceType>(resourceUrl,{params:queryParams});
}
fetchRawJson(name:string): Observable<string> {
const resourceUrl = this.applicationConfigService.getEndpointFor('api/is/resourcetypejson');
let queryParams = new HttpParams();
queryParams = queryParams.append("typeName",name);
return this.http.get<string>(resourceUrl,{params:queryParams});
}
}