From adfe881a817aae1a32b644848e30a7553e338b70 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Wed, 16 Oct 2019 13:12:33 +0200 Subject: [PATCH] add findByParent method to ComColDataService --- src/app/core/data/collection-data.service.ts | 8 +++++++- src/app/core/data/comcol-data.service.ts | 21 ++++++++++++++++---- src/app/core/data/community-data.service.ts | 16 +++++++++++---- src/app/core/data/data.service.ts | 8 ++++---- src/app/core/data/request.models.ts | 2 +- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index 88cc80a9a8..2e1eac9e9c 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; -import { distinctUntilChanged, filter, map, take } from 'rxjs/operators'; +import { distinctUntilChanged, filter, map, switchMap, take } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; @@ -136,4 +136,10 @@ export class CollectionDataService extends ComColDataService { return this.rdbService.buildList(href$); } + protected getFindByParentHref(parentUUID: string): Observable { + return this.halService.getEndpoint('communities').pipe( + switchMap((communityEndpointHref: string) => + this.halService.getEndpoint('collections', `${communityEndpointHref}/${parentUUID}`)), + ); + } } diff --git a/src/app/core/data/comcol-data.service.ts b/src/app/core/data/comcol-data.service.ts index 49c5c908ef..867ee24fc1 100644 --- a/src/app/core/data/comcol-data.service.ts +++ b/src/app/core/data/comcol-data.service.ts @@ -1,6 +1,15 @@ -import { distinctUntilChanged, filter, map, mergeMap, share, take, tap } from 'rxjs/operators'; +import { + distinctUntilChanged, + filter, first, + map, + mergeMap, + share, + switchMap, + take, + tap +} from 'rxjs/operators'; import { merge as observableMerge, Observable, throwError as observableThrowError } from 'rxjs'; -import { isEmpty, isNotEmpty } from '../../shared/empty.util'; +import { hasValue, isEmpty, isNotEmpty } from '../../shared/empty.util'; import { NormalizedCommunity } from '../cache/models/normalized-community.model'; import { ObjectCacheService } from '../cache/object-cache.service'; import { CommunityDataService } from './community-data.service'; @@ -60,7 +69,11 @@ export abstract class ComColDataService extends DataS } } - public findByParentCommunity(parentUUID: string): Observable>> { - this.halService.getEndpoint(`communities/${parentUUID}/collections`) + protected abstract getFindByParentHref(parentUUID: string): Observable; + + public findByParent(parentUUID: string, options: FindListOptions = {}): Observable>> { + const href$ = this.buildHrefFromFindOptions(this.getFindByParentHref(parentUUID), [], options); + return this.findList(href$, options); } + } diff --git a/src/app/core/data/community-data.service.ts b/src/app/core/data/community-data.service.ts index 7368d30202..d28c975122 100644 --- a/src/app/core/data/community-data.service.ts +++ b/src/app/core/data/community-data.service.ts @@ -1,4 +1,4 @@ -import { filter, take } from 'rxjs/operators'; +import { filter, switchMap, take } from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { Store } from '@ngrx/store'; @@ -9,7 +9,7 @@ import { Community } from '../shared/community.model'; import { ComColDataService } from './comcol-data.service'; import { RequestService } from './request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; -import { FindListOptions, FindAllRequest } from './request.models'; +import { FindListOptions, FindListRequest } from './request.models'; import { RemoteData } from './remote-data'; import { hasValue } from '../../shared/empty.util'; import { Observable } from 'rxjs'; @@ -50,7 +50,7 @@ export class CommunityDataService extends ComColDataService { filter((href: string) => hasValue(href)), take(1)) .subscribe((href: string) => { - const request = new FindAllRequest(this.requestService.generateRequestId(), href, options); + const request = new FindListRequest(this.requestService.generateRequestId(), href, options); this.requestService.configure(request); }); @@ -64,10 +64,18 @@ export class CommunityDataService extends ComColDataService { filter((href: string) => hasValue(href)), take(1)) .subscribe((href: string) => { - const request = new FindAllRequest(this.requestService.generateRequestId(), href, options); + const request = new FindListRequest(this.requestService.generateRequestId(), href, options); this.requestService.configure(request); }); return this.rdbService.buildList(hrefObs) as Observable>>; } + + protected getFindByParentHref(parentUUID: string): Observable { + return this.halService.getEndpoint(this.linkPath).pipe( + switchMap((communityEndpointHref: string) => + this.halService.getEndpoint('subcommunities', `${communityEndpointHref}/${parentUUID}`)) + ); + } + } diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 69b2cdfcb5..2518de9a7b 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -15,7 +15,7 @@ import { CreateRequest, DeleteByIDRequest, FindListOptions, - FindAllRequest, + FindListRequest, FindByIDRequest, GetRequest } from './request.models'; @@ -133,7 +133,7 @@ export abstract class DataService { hrefObs.pipe( first((href: string) => hasValue(href))) .subscribe((href: string) => { - const request = new FindAllRequest(this.requestService.generateRequestId(), href, options); + const request = new FindListRequest(this.requestService.generateRequestId(), href, options); if (hasValue(this.responseMsToLive)) { request.responseMsToLive = this.responseMsToLive; } @@ -191,7 +191,7 @@ export abstract class DataService { } /** - * Make a new FindAllRequest with given search method + * Make a new FindListRequest with given search method * * @param searchMethod The search method for the object * @param options The [[FindListOptions]] object @@ -205,7 +205,7 @@ export abstract class DataService { hrefObs.pipe( first((href: string) => hasValue(href))) .subscribe((href: string) => { - const request = new FindAllRequest(this.requestService.generateRequestId(), href, options); + const request = new FindListRequest(this.requestService.generateRequestId(), href, options); request.responseMsToLive = 10 * 1000; this.requestService.configure(request); }); diff --git a/src/app/core/data/request.models.ts b/src/app/core/data/request.models.ts index 6396d7a374..ca864f99de 100644 --- a/src/app/core/data/request.models.ts +++ b/src/app/core/data/request.models.ts @@ -147,7 +147,7 @@ export class FindListOptions { startsWith?: string; } -export class FindAllRequest extends GetRequest { +export class FindListRequest extends GetRequest { constructor( uuid: string, href: string,