64387: HAL endpoint refactoring

This commit is contained in:
Kristof De Langhe
2019-08-21 17:31:24 +02:00
committed by Marie Verdonck
parent ee140e623a
commit aed4db6289
3 changed files with 18 additions and 2 deletions

View File

@@ -6,6 +6,8 @@ import { ObjectCacheService } from '../cache/object-cache.service';
import { CommunityDataService } from './community-data.service'; import { CommunityDataService } from './community-data.service';
import { DataService } from './data.service'; import { DataService } from './data.service';
import { PaginatedList } from './paginated-list';
import { RemoteData } from './remote-data';
import { FindListOptions, FindByIDRequest } from './request.models'; import { FindListOptions, FindByIDRequest } from './request.models';
import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointService } from '../shared/hal-endpoint.service';
import { getResponseFromEntry } from '../shared/operators'; import { getResponseFromEntry } from '../shared/operators';
@@ -57,4 +59,8 @@ export abstract class ComColDataService<T extends CacheableObject> extends DataS
return observableMerge(errorResponses, successResponses).pipe(distinctUntilChanged(), share()); return observableMerge(errorResponses, successResponses).pipe(distinctUntilChanged(), share());
} }
} }
public findByParentCommunity(parentUUID: string): Observable<RemoteData<PaginatedList<T>>> {
this.halService.getEndpoint(`communities/${parentUUID}/collections`)
}
} }

View File

@@ -247,4 +247,14 @@ export class ItemDataService extends DataService<Item> {
map((request: RequestEntry) => request.response) map((request: RequestEntry) => request.response)
); );
} }
/**
* Get the endpoint for an item's bitstreams
* @param itemId
*/
public getBitstreamsEndpoint(itemId: string): Observable<string> {
return this.halService.getEndpoint(this.linkPath).pipe(
switchMap((url: string) => this.halService.getEndpoint('bitstreams', `${url}/${itemId}`))
);
}
} }

View File

@@ -43,8 +43,8 @@ export class HALEndpointService {
); );
} }
public getEndpoint(linkPath: string): Observable<string> { public getEndpoint(linkPath: string, startHref?: string): Observable<string> {
return this.getEndpointAt(this.getRootHref(), ...linkPath.split('/')); return this.getEndpointAt(startHref || this.getRootHref(), ...linkPath.split('/'));
} }
/** /**