Skip to content

Commit

Permalink
feat: adding artifacts for shopping cart
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <enjoyjava@gmail.com>
  • Loading branch information
raymondfeng committed Aug 16, 2018
1 parent d92fb37 commit 570b5e7
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 4 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@
"src"
],
"dependencies": {
"@loopback/context": "^0.12.2",
"@loopback/boot": "^0.12.2",
"@loopback/context": "^0.12.2",
"@loopback/core": "^0.11.2",
"@loopback/dist-util": "^0.3.5",
"@loopback/repository": "^0.14.2",
"@loopback/openapi-v3": "^0.12.2",
"@loopback/repository": "^0.15.0",
"@loopback/rest": "^0.19.2",
"@loopback/openapi-v3": "^0.12.2"
"loopback-connector-kv-redis": "^3.0.0"
},
"devDependencies": {
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.1",
"@commitlint/travis-cli": "^7.0.0",
"@loopback/build": "^0.6.13",
"@loopback/build": "^0.7.0",
"@loopback/testlab": "^0.11.2",
"@types/mocha": "^5.0.0",
"@types/node": "^10.1.1",
Expand Down
1 change: 1 addition & 0 deletions src/datasources/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './redis.datasource';
8 changes: 8 additions & 0 deletions src/datasources/redis.datasource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "redis",
"connector": "kv-redis",
"host": "127.0.0.1",
"port": 6379,
"password": "",
"db": "shoppingcart"
}
14 changes: 14 additions & 0 deletions src/datasources/redis.datasource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {inject} from '@loopback/core';
import {juggler, AnyObject} from '@loopback/repository';
const config = require('./redis.datasource.json');

export class RedisDataSource extends juggler.DataSource {
static dataSourceName = 'redis';

constructor(
@inject('datasources.config.redis', {optional: true})
dsConfig: AnyObject = config,
) {
super(dsConfig);
}
}
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './shopping-cart.model';
33 changes: 33 additions & 0 deletions src/models/shopping-cart.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Entity, model, property} from '@loopback/repository';

@model()
export class ShoppingCart extends Entity {
@property({
type: 'number',
id: true,
required: true,
})
id: number;

@property({
type: 'string',
required: true,
})
userId: string;

@property({
type: 'array',
itemType: 'object',
})
items?: ShoppingCartItem[];

constructor(data?: Partial<ShoppingCart>) {
super(data);
}
}

export class ShoppingCartItem {
productId: string;
quantity: number;
price: number;
}
11 changes: 11 additions & 0 deletions src/repositories/shopping-cart.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {DefaultKeyValueRepository} from '@loopback/repository';
import {ShoppingCart} from '../models/shopping-cart.model';
import {RedisDataSource} from '../datasources/redis.datasource';

export class ShoppingCartRepository extends DefaultKeyValueRepository<
ShoppingCart
> {
constructor() {
super(ShoppingCart, new RedisDataSource());
}
}

0 comments on commit 570b5e7

Please sign in to comment.