Skip to content

Commit

Permalink
feat(contact): support in-memory backend delegate (graycoreio#3183)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored and gracetxgao committed Oct 24, 2024
1 parent 6759e5a commit 8e5c9db
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions libs/contact/driver/in-memory/src/collection-name.const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME = 'contact';
7 changes: 7 additions & 0 deletions libs/contact/driver/in-memory/src/contact.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -21,6 +22,12 @@ describe('The DaffInMemoryContactService', () => {
imports: [],
providers: [
DaffInMemoryContactService,
{
provide: InMemoryBackendConfig,
useValue: {
apiBase: 'api',
},
},
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
],
Expand Down
15 changes: 11 additions & 4 deletions libs/contact/driver/in-memory/src/contact.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
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
*/
@Injectable({
providedIn: 'root',
})
export class DaffInMemoryContactService implements DaffContactServiceInterface<DaffContactUnion, DaffContactUnion>{

url = '/api/contact';
constructor(private http: HttpClient) {}
export class DaffInMemoryContactService extends DaffInMemoryDriverBase implements DaffContactServiceInterface<DaffContactUnion, DaffContactUnion>{
constructor(
private http: HttpClient,
config: InMemoryBackendConfig,
) {
super(config, DAFF_CONTACT_IN_MEMORY_COLLECTION_NAME);
}

send(payload: DaffContactUnion): Observable<DaffContactUnion> {
return this.http.post<DaffContactUnion>(this.url, payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions libs/contact/driver/in-memory/src/in-memory.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -20,6 +22,7 @@ export class DaffContactInMemoryDriverModule {
provide: DaffContactDriver,
useClass: DaffInMemoryContactService,
},
provideDaffInMemoryBackends(DaffInMemoryBackendContactService),
],
};
}
Expand Down

0 comments on commit 8e5c9db

Please sign in to comment.