Commit d817b5f5 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

APIService.get accepte un type de ressource et les paramètres.

parent 313ab1b8
......@@ -315,9 +315,10 @@ export interface APIService<API extends APIMeta> {
readonly repositories: APIRepositoryRegistry<API>;
/**
* Récupère une ressource par son IRI.
* Récupère une ressource par son IRI ou par son type et les paramètres de son IRI.
*/
get<R extends Resource>(iri: IRI<R>): Observable<R>;
get<R extends Resource>(iri: IRI<R>): Observable<R> ;
get<T extends keyof API>(type: T, parameters: API[T]['iriParameters']): Observable<API[T]['resource']> ;
/**
* Récupère des ressources par leurs IRIs.
......@@ -350,7 +351,19 @@ export abstract class AbstractAPIService<
private readonly client: HttpClient
) {}
public get<R extends Resource>(iri: IRI<R>): Observable<R> {
public get<R extends Resource>(iri: IRI<R>): Observable<R>;
public get<T extends keyof API>(type: T, parameters: API[T]['iriParameters']): Observable<API[T]['resource']>;
public get<T extends keyof API, R extends Resource = API[T]['resource']>(
typeOrIRI: T | IRI<R>,
parameters?: API[T]['iriParameters']
): Observable<R> {
let iri: IRI<R>;
if (this.metadata.has(typeOrIRI as string)) {
iri = this.metadata.get(typeOrIRI as string).generateIRI(parameters);
} else {
iri = typeOrIRI as IRI<R>;
}
return this.cache.get(iri, () => this.client.get<R>(iri as any));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment