Skip to content

Commit a8360df

Browse files
authored
feat(cart)!: support in-memory backend delegate (#3180)
BREAKING CHANGE: `COLLECTION_NAMES` has been removed. Use `canHandle` to check backend routing capabilities
1 parent 1959c96 commit a8360df

File tree

40 files changed

+446
-299
lines changed

40 files changed

+446
-299
lines changed

apps/demo/src/app/drivers/in-memory/backend/backend.service.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('@daffodil/demo | DemoInMemoryBackendService', () => {
4949
returnedValue,
5050
);
5151
reqInfo = {
52-
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
52+
collectionName: 'cart',
5353
};
5454

5555
result = service.post(reqInfo);
@@ -160,7 +160,7 @@ describe('@daffodil/demo | DemoInMemoryBackendService', () => {
160160
returnedValue = 'returnedValue';
161161
spyOn(service['cartTestingService'], 'get').and.returnValue(returnedValue);
162162
reqInfo = {
163-
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
163+
collectionName: 'cart',
164164
};
165165

166166
result = service.get(reqInfo);
@@ -195,7 +195,7 @@ describe('@daffodil/demo | DemoInMemoryBackendService', () => {
195195
returnedValue,
196196
);
197197
reqInfo = {
198-
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
198+
collectionName: 'cart',
199199
};
200200

201201
result = service.put(reqInfo);
@@ -231,7 +231,7 @@ describe('@daffodil/demo | DemoInMemoryBackendService', () => {
231231
returnedValue,
232232
);
233233
reqInfo = {
234-
collectionName: DaffInMemoryBackendCartRootService.COLLECTION_NAMES[0],
234+
collectionName: 'cart',
235235
};
236236

237237
result = service.delete(reqInfo);

apps/demo/src/app/drivers/in-memory/backend/backend.service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class DemoInMemoryBackendService implements InMemoryDbService {
3636

3737
post(reqInfo: any) {
3838
const collectionName = reqInfo.collectionName;
39-
if (DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
39+
if (this.cartTestingService.canHandle(collectionName)) {
4040
return this.cartTestingService.post(reqInfo);
4141
} else if (collectionName === 'auth') {
4242
return this.authTestingService.post(reqInfo);
@@ -51,7 +51,7 @@ export class DemoInMemoryBackendService implements InMemoryDbService {
5151
return this.productTestingService.get(reqInfo);
5252
} else if (collectionName === 'navigation') {
5353
return this.navigationTestingService.get(reqInfo);
54-
} else if (DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
54+
} else if (this.cartTestingService.canHandle(collectionName)) {
5555
return this.cartTestingService.get(reqInfo);
5656
} else if (collectionName === 'countries') {
5757
return this.geographyTestingService.get(reqInfo);
@@ -62,14 +62,14 @@ export class DemoInMemoryBackendService implements InMemoryDbService {
6262

6363
put(reqInfo: any) {
6464
const collectionName = reqInfo.collectionName;
65-
if(DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
65+
if(this.cartTestingService.canHandle(collectionName)) {
6666
return this.cartTestingService.put(reqInfo);
6767
}
6868
}
6969

7070
delete(reqInfo: any) {
7171
const collectionName = reqInfo.collectionName;
72-
if(DaffInMemoryBackendCartRootService.COLLECTION_NAMES.indexOf(collectionName) > -1) {
72+
if(this.cartTestingService.canHandle(collectionName)) {
7373
return this.cartTestingService.delete(reqInfo);
7474
}
7575
}

libs/cart/driver/in-memory/src/backend/cart-address/cart-address.service.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import {
88
} from 'angular-in-memory-web-api';
99

1010
import { DaffCart } from '@daffodil/cart';
11-
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
11+
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
1212

13+
import { DAFF_CART_IN_MEMORY_CART_ADDRESS_COLLECTION_NAME } from '../../collection-names';
1314
import {
1415
DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
1516
DaffCartInMemoryExtraAttributesHook,
@@ -21,7 +22,9 @@ import {
2122
@Injectable({
2223
providedIn: 'root',
2324
})
24-
export class DaffInMemoryBackendCartAddressService implements DaffInMemoryDataServiceInterface {
25+
export class DaffInMemoryBackendCartAddressService implements DaffInMemorySingleRouteableBackend {
26+
readonly collectionName = DAFF_CART_IN_MEMORY_CART_ADDRESS_COLLECTION_NAME;
27+
2528
constructor(
2629
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
2730
) {}

libs/cart/driver/in-memory/src/backend/cart-billing-address/cart-billing-address.service.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import {
1111
DaffCart,
1212
DaffCartAddress,
1313
} from '@daffodil/cart';
14-
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
14+
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
1515

16+
import { DAFF_CART_IN_MEMORY_CART_BILLING_ADDRESS_COLLECTION_NAME } from '../../collection-names';
1617
import {
1718
DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
1819
DaffCartInMemoryExtraAttributesHook,
@@ -24,7 +25,9 @@ import {
2425
@Injectable({
2526
providedIn: 'root',
2627
})
27-
export class DaffInMemoryBackendCartBillingAddressService implements DaffInMemoryDataServiceInterface {
28+
export class DaffInMemoryBackendCartBillingAddressService implements DaffInMemorySingleRouteableBackend {
29+
readonly collectionName = DAFF_CART_IN_MEMORY_CART_BILLING_ADDRESS_COLLECTION_NAME;
30+
2831
constructor(
2932
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
3033
) {}

libs/cart/driver/in-memory/src/backend/cart-coupon/cart-coupon.service.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import {
1111
DaffCart,
1212
DaffCartCoupon,
1313
} from '@daffodil/cart';
14-
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
14+
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
1515

16+
import { DAFF_CART_IN_MEMORY_CART_COUPON_COLLECTION_NAME } from '../../collection-names';
1617
import {
1718
DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
1819
DaffCartInMemoryExtraAttributesHook,
@@ -24,7 +25,9 @@ import {
2425
@Injectable({
2526
providedIn: 'root',
2627
})
27-
export class DaffInMemoryBackendCartCouponService implements DaffInMemoryDataServiceInterface {
28+
export class DaffInMemoryBackendCartCouponService implements DaffInMemorySingleRouteableBackend {
29+
readonly collectionName = DAFF_CART_IN_MEMORY_CART_COUPON_COLLECTION_NAME;
30+
2831
constructor(
2932
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
3033
) {}

libs/cart/driver/in-memory/src/backend/cart-items/cart-items.service.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import {
1313
DaffCartItemInput,
1414
} from '@daffodil/cart';
1515
import { DaffCartItemFactory } from '@daffodil/cart/testing';
16-
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
16+
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
1717
import { DaffInMemoryBackendProductService } from '@daffodil/product/driver/in-memory';
1818

19+
import { DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME } from '../../collection-names';
1920
import { daffCartInMemoryComputeCartItemPrices } from '../../helpers/compute-cart-item-prices';
2021
import { daffCartInMemoryComputeCartTotals } from '../../helpers/compute-cart-totals';
2122
import {
@@ -29,7 +30,9 @@ import {
2930
@Injectable({
3031
providedIn: 'root',
3132
})
32-
export class DaffInMemoryBackendCartItemsService implements DaffInMemoryDataServiceInterface {
33+
export class DaffInMemoryBackendCartItemsService implements DaffInMemorySingleRouteableBackend {
34+
readonly collectionName = DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME;
35+
3336
constructor(
3437
private cartItemFactory: DaffCartItemFactory,
3538
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,

libs/cart/driver/in-memory/src/backend/cart-order/cart-order.service.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import {
55
} from 'angular-in-memory-web-api';
66

77
import { DaffCartOrderResult } from '@daffodil/cart';
8-
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
8+
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
9+
10+
import { DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME } from '../../collection-names';
911

1012
/**
1113
* @inheritdoc
1214
*/
1315
@Injectable({
1416
providedIn: 'root',
1517
})
16-
export class DaffInMemoryBackendCartOrderService implements DaffInMemoryDataServiceInterface {
18+
export class DaffInMemoryBackendCartOrderService implements DaffInMemorySingleRouteableBackend {
19+
readonly collectionName = DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME;
20+
1721
post(reqInfo: RequestInfo) {
1822
return reqInfo.utils.createResponse$(() => ({
1923
body: this.placeOrder(reqInfo),

libs/cart/driver/in-memory/src/backend/cart-payment-methods/cart-payment-methods.service.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ import {
88
DaffCart,
99
DaffCartPaymentMethod,
1010
} from '@daffodil/cart';
11-
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
11+
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
12+
13+
import { DAFF_CART_IN_MEMORY_CART_PAYMENT_METHODS_COLLECTION_NAME } from '../../collection-names';
1214

1315
/**
1416
* @inheritdoc
1517
*/
1618
@Injectable({
1719
providedIn: 'root',
1820
})
19-
export class DaffInMemoryBackendCartPaymentMethodsService implements DaffInMemoryDataServiceInterface {
21+
export class DaffInMemoryBackendCartPaymentMethodsService implements DaffInMemorySingleRouteableBackend {
22+
readonly collectionName = DAFF_CART_IN_MEMORY_CART_PAYMENT_METHODS_COLLECTION_NAME;
23+
2024
get(reqInfo: RequestInfo) {
2125
return reqInfo.utils.createResponse$(() => ({
2226
body: this.listPaymentMethods(reqInfo),

libs/cart/driver/in-memory/src/backend/cart-payment/cart-payment.service.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import {
1111
DaffCart,
1212
DaffCartPaymentMethod,
1313
} from '@daffodil/cart';
14-
import { DaffInMemoryDataServiceInterface } from '@daffodil/driver/in-memory';
14+
import { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';
1515

16+
import { DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME } from '../../collection-names';
1617
import {
1718
DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
1819
DaffCartInMemoryExtraAttributesHook,
@@ -24,7 +25,9 @@ import {
2425
@Injectable({
2526
providedIn: 'root',
2627
})
27-
export class DaffInMemoryBackendCartPaymentService implements DaffInMemoryDataServiceInterface {
28+
export class DaffInMemoryBackendCartPaymentService implements DaffInMemorySingleRouteableBackend {
29+
readonly collectionName = DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME;
30+
2831
constructor(
2932
@Inject(DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK) private extraFieldsHook: DaffCartInMemoryExtraAttributesHook,
3033
) {}

0 commit comments

Comments
 (0)