| 3 | import { Construct } from "constructs"; |
| 4 | |
| 5 | export class SwnDatabase extends Construct { |
| 6 | |
| 7 | public readonly productTable: ITable; |
| 8 | public readonly basketTable: ITable; |
| 9 | public readonly orderTable: ITable; |
| 10 | |
| 11 | constructor(scope: Construct, id: string) { |
| 12 | super(scope, id); |
| 13 | |
| 14 | //product table |
| 15 | this.productTable = this.createProductTable(); |
| 16 | //basket table |
| 17 | this.basketTable = this.createBasketTable(); |
| 18 | //order table |
| 19 | this.orderTable = this.createOrderTable(); |
| 20 | } |
| 21 | |
| 22 | // Product DynamoDb Table Creation |
| 23 | // product : PK: id -- name - description - imageFile - price - category |
| 24 | private createProductTable() : ITable { |
| 25 | const productTable = new Table(this, 'product', { |
| 26 | partitionKey: { |
| 27 | name: 'id', |
| 28 | type: AttributeType.STRING |
| 29 | }, |
| 30 | tableName: 'product', |
| 31 | removalPolicy: RemovalPolicy.DESTROY, |
| 32 | billingMode: BillingMode.PAY_PER_REQUEST |
| 33 | }); |
| 34 | return productTable; |
| 35 | } |
| 36 | |
| 37 | // Basket DynamoDb Table Creation |
| 38 | // basket : PK: userName -- items (SET-MAP object) |
| 39 | // item1 - { quantity - color - price - productId - productName } |
| 40 | // item2 - { quantity - color - price - productId - productName } |
| 41 | private createBasketTable() : ITable { |
| 42 | const basketTable = new Table(this, 'basket', { |
| 43 | partitionKey: { |
| 44 | name: 'userName', |
| 45 | type: AttributeType.STRING, |
| 46 | }, |
| 47 | tableName: 'basket', |
| 48 | removalPolicy: RemovalPolicy.DESTROY, |
| 49 | billingMode: BillingMode.PAY_PER_REQUEST |
| 50 | }); |
| 51 | return basketTable; |
| 52 | } |
| 53 | |
| 54 | // Order DynamoDb Table Creation |
| 55 | // order : PK: userName - SK: orderDate -- totalPrice - firstName - lastName - email - address - paymentMethod - cardInfo |
| 56 | private createOrderTable() : ITable { |
| 57 | const orderTable = new Table(this, 'order', { |
| 58 | partitionKey: { |
| 59 | name: 'userName', |
| 60 | type: AttributeType.STRING, |
| 61 | }, |
| 62 | sortKey: { |
nothing calls this directly
no outgoing calls
no test coverage detected