Skip to content

Commit 06f29ef

Browse files
authored
feat(contact): support in-memory backend delegate (#3183)
1 parent 3cd0c1f commit 06f29ef

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME = 'contact';

libs/contact/driver/in-memory/src/contact.service.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
provideHttpClientTesting,
88
} from '@angular/common/http/testing';
99
import { TestBed } from '@angular/core/testing';
10+
import { InMemoryBackendConfig } from 'angular-in-memory-web-api';
1011

1112
import { DaffContactUnion } from '@daffodil/contact';
1213

@@ -21,6 +22,12 @@ describe('The DaffInMemoryContactService', () => {
2122
imports: [],
2223
providers: [
2324
DaffInMemoryContactService,
25+
{
26+
provide: InMemoryBackendConfig,
27+
useValue: {
28+
apiBase: 'api',
29+
},
30+
},
2431
provideHttpClient(withInterceptorsFromDi()),
2532
provideHttpClientTesting(),
2633
],

libs/contact/driver/in-memory/src/contact.service.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import { HttpClient } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
3+
import { InMemoryBackendConfig } from 'angular-in-memory-web-api';
34
import { Observable } from 'rxjs';
45

56
import { DaffContactUnion } from '@daffodil/contact';
67
import { DaffContactServiceInterface } from '@daffodil/contact/driver';
8+
import { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';
9+
10+
import { DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME } from './collection-name.const';
711

812
/**
913
* @inheritdoc
1014
*/
1115
@Injectable({
1216
providedIn: 'root',
1317
})
14-
export class DaffInMemoryContactService implements DaffContactServiceInterface<DaffContactUnion, DaffContactUnion>{
15-
16-
url = '/api/contact';
17-
constructor(private http: HttpClient) {}
18+
export class DaffInMemoryContactService extends DaffInMemoryDriverBase implements DaffContactServiceInterface<DaffContactUnion, DaffContactUnion>{
19+
constructor(
20+
private http: HttpClient,
21+
config: InMemoryBackendConfig,
22+
) {
23+
super(config, DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME);
24+
}
1825

1926
send(payload: DaffContactUnion): Observable<DaffContactUnion> {
2027
return this.http.post<DaffContactUnion>(this.url, payload);

libs/contact/driver/in-memory/src/in-memory-backend/contact-in-memory-backend.service.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ import {
77
import { of } from 'rxjs';
88

99
import { DaffContactUnion } from '@daffodil/contact';
10+
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
11+
12+
import { DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const';
1013

1114
@Injectable({
1215
providedIn: 'root',
1316
})
14-
export class DaffInMemoryBackendContactService implements InMemoryDbService {
17+
export class DaffInMemoryBackendContactService implements InMemoryDbService, DaffInMemorySingleRouteableBackend {
18+
readonly collectionName = DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME;
19+
1520
forums: DaffContactUnion[] = [];
1621

1722
parseRequestUrl(url: string, utils: RequestInfoUtilities): ParsedRequestUrl {

libs/contact/driver/in-memory/src/in-memory.module.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
} from '@angular/core';
66

77
import { DaffContactDriver } from '@daffodil/contact/driver';
8+
import { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory';
89

910
import { DaffInMemoryContactService } from './contact.service';
11+
import { DaffInMemoryBackendContactService } from './in-memory-backend/contact-in-memory-backend.service';
1012

1113
@NgModule({
1214
imports: [CommonModule],
@@ -20,6 +22,7 @@ export class DaffContactInMemoryDriverModule {
2022
provide: DaffContactDriver,
2123
useClass: DaffInMemoryContactService,
2224
},
25+
provideDaffInMemoryBackends(DaffInMemoryBackendContactService),
2326
],
2427
};
2528
}

0 commit comments

Comments
 (0)