Skip to content
Snippets Groups Projects
collection-data.effects.ts 1.34 KiB
Newer Older
Art Lowel's avatar
Art Lowel committed
import { Injectable } from "@angular/core";
import { DataEffects } from "./data.effects";
import { Serializer } from "../serializer";
import { Collection } from "../shared/collection.model";
import { DSpaceRESTv2Serializer } from "../dspace-rest-v2/dspace-rest-v2.serializer";
Art Lowel's avatar
Art Lowel committed
import { ObjectCacheService } from "../cache/object-cache.service";
Art Lowel's avatar
Art Lowel committed
import { DSpaceRESTv2Service } from "../dspace-rest-v2/dspace-rest-v2.service";
import { Actions, Effect } from "@ngrx/effects";
Art Lowel's avatar
Art Lowel committed
import { FindAllRequestCacheAction, FindByIDRequestCacheAction } from "../cache/request-cache.actions";
Art Lowel's avatar
Art Lowel committed
import { CollectionDataService } from "./collection-data.service";

@Injectable()
export class CollectionDataEffects extends DataEffects<Collection> {
  constructor(
    actions$: Actions,
    restApi: DSpaceRESTv2Service,
Art Lowel's avatar
Art Lowel committed
    cache: ObjectCacheService,
Art Lowel's avatar
Art Lowel committed
    dataService: CollectionDataService
  ) {
    super(actions$, restApi, cache, dataService);
  }

Art Lowel's avatar
Art Lowel committed
  protected getFindAllEndpoint(action: FindAllRequestCacheAction): string {
Art Lowel's avatar
Art Lowel committed
    return '/collections';
  }

Art Lowel's avatar
Art Lowel committed
  protected getFindByIdEndpoint(action: FindByIDRequestCacheAction): string {
Art Lowel's avatar
Art Lowel committed
    return `/collections/${action.payload.resourceID}`;
  }

  protected getSerializer(): Serializer<Collection> {
    return new DSpaceRESTv2Serializer(Collection);
  }

  @Effect() findAll$ = this.findAll;

  @Effect() findById$ = this.findById;
}