Skip to content

Commit

Permalink
added items table
Browse files Browse the repository at this point in the history
  • Loading branch information
koljagralla committed Jan 26, 2024
1 parent 4fa5c9e commit 8743116
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/stacks/my-stack/database/items/create-items-dynamodb.ts
@@ -0,0 +1,16 @@
import { RemovalPolicy } from 'aws-cdk-lib';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import { Construct } from 'constructs';

export function createItemsDynamoDB(scope: Construct): dynamodb.Table {
const table = new dynamodb.Table(scope, 'turbogate-example-items', {
tableName: 'items',
partitionKey: {
name: "id",
type: dynamodb.AttributeType.STRING,
},
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: RemovalPolicy.DESTROY,
});
return table;
}
17 changes: 17 additions & 0 deletions lib/stacks/my-stack/database/items/item-record.ts
@@ -0,0 +1,17 @@
import z from "zod";

export const zItemRecord = z
.strictObject({
id: z.string().uuid().openapi({ description: 'The ID of the item. Generated by the backend upon creation.' }),
name: z.string().min(5).max(20).openapi({
description: 'The name of the item. Does not have to be unique and can be changed at any given time.',
example: 'Excellent Item',
}),
description: z.string().optional().openapi({
description: 'The description of the item. Can be changed at any given time.',
example: 'This item is of exceptional excellence.',
}),
})
.openapi('Item', { description: 'An item.' });

export type ItemRecord = z.infer<typeof zItemRecord>;
3 changes: 3 additions & 0 deletions lib/stacks/my-stack/index.ts
@@ -1,8 +1,11 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { createItemsDynamoDB } from './database/items/create-items-dynamodb';

export class MyStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const itemsTable = createItemsDynamoDB(this);
}
}

0 comments on commit 8743116

Please sign in to comment.