diff --git a/libs/contact/driver/in-memory/src/collection-name.const.ts b/libs/contact/driver/in-memory/src/collection-name.const.ts new file mode 100644 index 0000000000..0d83ede56a --- /dev/null +++ b/libs/contact/driver/in-memory/src/collection-name.const.ts @@ -0,0 +1 @@ +export const DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME = 'contact'; diff --git a/libs/contact/driver/in-memory/src/contact.service.spec.ts b/libs/contact/driver/in-memory/src/contact.service.spec.ts index a391b4f59d..f5542f12c7 100644 --- a/libs/contact/driver/in-memory/src/contact.service.spec.ts +++ b/libs/contact/driver/in-memory/src/contact.service.spec.ts @@ -7,6 +7,7 @@ import { provideHttpClientTesting, } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; +import { InMemoryBackendConfig } from 'angular-in-memory-web-api'; import { DaffContactUnion } from '@daffodil/contact'; @@ -21,6 +22,12 @@ describe('The DaffInMemoryContactService', () => { imports: [], providers: [ DaffInMemoryContactService, + { + provide: InMemoryBackendConfig, + useValue: { + apiBase: 'api', + }, + }, provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), ], diff --git a/libs/contact/driver/in-memory/src/contact.service.ts b/libs/contact/driver/in-memory/src/contact.service.ts index bc2b0dd497..a0c236916c 100644 --- a/libs/contact/driver/in-memory/src/contact.service.ts +++ b/libs/contact/driver/in-memory/src/contact.service.ts @@ -1,9 +1,13 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { InMemoryBackendConfig } from 'angular-in-memory-web-api'; import { Observable } from 'rxjs'; import { DaffContactUnion } from '@daffodil/contact'; import { DaffContactServiceInterface } from '@daffodil/contact/driver'; +import { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory'; + +import { DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME } from './collection-name.const'; /** * @inheritdoc @@ -11,10 +15,13 @@ import { DaffContactServiceInterface } from '@daffodil/contact/driver'; @Injectable({ providedIn: 'root', }) -export class DaffInMemoryContactService implements DaffContactServiceInterface{ - - url = '/api/contact'; - constructor(private http: HttpClient) {} +export class DaffInMemoryContactService extends DaffInMemoryDriverBase implements DaffContactServiceInterface{ + constructor( + private http: HttpClient, + config: InMemoryBackendConfig, + ) { + super(config, DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME); + } send(payload: DaffContactUnion): Observable { return this.http.post(this.url, payload); diff --git a/libs/contact/driver/in-memory/src/in-memory-backend/contact-in-memory-backend.service.ts b/libs/contact/driver/in-memory/src/in-memory-backend/contact-in-memory-backend.service.ts index ab3b74c491..29e137276d 100644 --- a/libs/contact/driver/in-memory/src/in-memory-backend/contact-in-memory-backend.service.ts +++ b/libs/contact/driver/in-memory/src/in-memory-backend/contact-in-memory-backend.service.ts @@ -7,11 +7,16 @@ import { import { of } from 'rxjs'; import { DaffContactUnion } from '@daffodil/contact'; +import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory'; + +import { DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const'; @Injectable({ providedIn: 'root', }) -export class DaffInMemoryBackendContactService implements InMemoryDbService { +export class DaffInMemoryBackendContactService implements InMemoryDbService, DaffInMemorySingleRouteableBackend { + readonly collectionName = DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME; + forums: DaffContactUnion[] = []; parseRequestUrl(url: string, utils: RequestInfoUtilities): ParsedRequestUrl { diff --git a/libs/contact/driver/in-memory/src/in-memory.module.ts b/libs/contact/driver/in-memory/src/in-memory.module.ts index ce4b5e50df..04b3da8afb 100644 --- a/libs/contact/driver/in-memory/src/in-memory.module.ts +++ b/libs/contact/driver/in-memory/src/in-memory.module.ts @@ -5,8 +5,10 @@ import { } from '@angular/core'; import { DaffContactDriver } from '@daffodil/contact/driver'; +import { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory'; import { DaffInMemoryContactService } from './contact.service'; +import { DaffInMemoryBackendContactService } from './in-memory-backend/contact-in-memory-backend.service'; @NgModule({ imports: [CommonModule], @@ -20,6 +22,7 @@ export class DaffContactInMemoryDriverModule { provide: DaffContactDriver, useClass: DaffInMemoryContactService, }, + provideDaffInMemoryBackends(DaffInMemoryBackendContactService), ], }; }