Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contact): support in-memory backend delegate #3183

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading