From cab7f7e6eeb85440b6f2f00a249231bb0b5a47c3 Mon Sep 17 00:00:00 2001 From: Willy Xiao Date: Tue, 17 Sep 2024 13:14:21 -0400 Subject: [PATCH 1/4] first commit --- packages/tsoa/README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tsoa/README.MD b/packages/tsoa/README.MD index 81295b201..e1d783bad 100644 --- a/packages/tsoa/README.MD +++ b/packages/tsoa/README.MD @@ -11,7 +11,7 @@ OpenAPI-compliant REST APIs using TypeScript and Node -## Goal +## Goal (this is a test willy) - TypeScript controllers and models as the single source of truth for your API - A valid OpenAPI (formerly Swagger) spec (2.0 or 3.0 if you choose 😍) is generated from your controllers and models, including: From a7bd8816cdd25fa81a11b853ade2b9d3520f7ba2 Mon Sep 17 00:00:00 2001 From: Willy Xiao Date: Tue, 17 Sep 2024 13:49:15 -0400 Subject: [PATCH 2/4] second commit --- packages/runtime/src/swagger/swagger.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/runtime/src/swagger/swagger.ts b/packages/runtime/src/swagger/swagger.ts index e9b2594d5..c49c849d7 100644 --- a/packages/runtime/src/swagger/swagger.ts +++ b/packages/runtime/src/swagger/swagger.ts @@ -89,18 +89,6 @@ export namespace Swagger { description?: string; } - export interface BaseParameter extends BaseSchema { - name: string; - in: 'query' | 'header' | 'path' | 'formData' | 'body'; - required?: boolean; - description?: string; - example?: unknown; - examples?: { [name: string]: Example3 | string }; - schema: Schema; - type: DataType; - format?: DataFormat; - deprecated?: boolean; - } export interface BodyParameter extends BaseParameter { in: 'body'; From e64059e62bd824f454d8f8bd1c5c3b415edbb01f Mon Sep 17 00:00:00 2001 From: Willy Xiao Date: Tue, 17 Sep 2024 13:51:25 -0400 Subject: [PATCH 3/4] third commit --- packages/runtime/src/swagger/swagger.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/runtime/src/swagger/swagger.ts b/packages/runtime/src/swagger/swagger.ts index c49c849d7..34a403cac 100644 --- a/packages/runtime/src/swagger/swagger.ts +++ b/packages/runtime/src/swagger/swagger.ts @@ -89,6 +89,21 @@ export namespace Swagger { description?: string; } + function isPalindrome(str: string): boolean { + const cleanedStr = str.replace(/[^A-Za-z0-9]/g, '').toLowerCase(); + return cleanedStr === cleanedStr.split('').reverse().join(''); +} + + +function removeDuplicates(arr: number[]): number[] { + return Array.from(new Set(arr)); +} + +console.log(removeDuplicates([1, 2, 2, 3, 4, 4, 5])); // Output: [1, 2, 3, 4, 5] + + +console.log(isPalindrome("A man, a plan, a canal, Panama")); // Output: true + export interface BodyParameter extends BaseParameter { in: 'body'; From b6afa8344008d78bf9784c83e30633a824f3a6f0 Mon Sep 17 00:00:00 2001 From: Willy Xiao Date: Tue, 17 Sep 2024 13:52:54 -0400 Subject: [PATCH 4/4] fourth commit --- packages/runtime/src/swagger/swagger.ts | 89 ++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 8 deletions(-) diff --git a/packages/runtime/src/swagger/swagger.ts b/packages/runtime/src/swagger/swagger.ts index 34a403cac..2816a0739 100644 --- a/packages/runtime/src/swagger/swagger.ts +++ b/packages/runtime/src/swagger/swagger.ts @@ -89,20 +89,93 @@ export namespace Swagger { description?: string; } - function isPalindrome(str: string): boolean { - const cleanedStr = str.replace(/[^A-Za-z0-9]/g, '').toLowerCase(); - return cleanedStr === cleanedStr.split('').reverse().join(''); + interface Item { + id: number; + name: string; + quantity: number; + price: number; } - -function removeDuplicates(arr: number[]): number[] { - return Array.from(new Set(arr)); +class Inventory { + private items: Item[] = []; + private nextId: number = 1; + + addItem(name: string, quantity: number, price: number): void { + const newItem: Item = { + id: this.nextId++, + name, + quantity, + price + }; + this.items.push(newItem); + console.log(`Item added: ${JSON.stringify(newItem)}`); + } + + updateItem(id: number, name?: string, quantity?: number, price?: number): void { + const item = this.items.find(item => item.id === id); + if (item) { + if (name !== undefined) item.name = name; + if (quantity !== undefined) item.quantity = quantity; + if (price !== undefined) item.price = price; + console.log(`Item updated: ${JSON.stringify(item)}`); + } else { + console.log(`Item with ID ${id} not found.`); + } + } + + deleteItem(id: number): void { + const index = this.items.findIndex(item => item.id === id); + if (index !== -1) { + const deletedItem = this.items.splice(index, 1)[0]; + console.log(`Item deleted: ${JSON.stringify(deletedItem)}`); + } else { + console.log(`Item with ID ${id} not found.`); + } + } + + searchItem(name: string): Item[] { + const foundItems = this.items.filter(item => item.name.toLowerCase().includes(name.toLowerCase())); + console.log(`Items found: ${JSON.stringify(foundItems)}`); + return foundItems; + } + + listItems(): void { + console.log('Inventory List:'); + this.items.forEach(item => { + console.log(`ID: ${item.id}, Name: ${item.name}, Quantity: ${item.quantity}, Price: ${item.price}`); + }); + } } -console.log(removeDuplicates([1, 2, 2, 3, 4, 4, 5])); // Output: [1, 2, 3, 4, 5] +// Example Usage +const inventory = new Inventory(); + +// Add items +inventory.addItem('Apple', 100, 1.0); +inventory.addItem('Banana', 150, 0.5); +inventory.addItem('Orange', 200, 0.8); + +// List all items +inventory.listItems(); +console.log('---'); + +// Update an item +inventory.updateItem(2, 'Banana', 180, 0.55); + +// List all items +inventory.listItems(); +console.log('---'); + +// Delete an item +inventory.deleteItem(3); + +// List all items +inventory.listItems(); +console.log('---'); +// Search for items +inventory.searchItem('app'); -console.log(isPalindrome("A man, a plan, a canal, Panama")); // Output: true export interface BodyParameter extends BaseParameter {