From 4b84b8c000d86da85bef126b5cb0c8b84cc07ca1 Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:17:52 +0900 Subject: [PATCH 01/11] Add NestJS AppModule --- kakasoo/app.module.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 kakasoo/app.module.ts diff --git a/kakasoo/app.module.ts b/kakasoo/app.module.ts new file mode 100644 index 00000000000..106b857a704 --- /dev/null +++ b/kakasoo/app.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { AppController } from './app.controller'; +import { AppService } from './app.service'; + +@Module({ + imports: [], + controllers: [AppController], + providers: [AppService], +}) +export class AppModule {} \ No newline at end of file From 358f21a6520fb8a3010b8cc3a2d0f5b734566abe Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:20:46 +0900 Subject: [PATCH 02/11] Add product creation API example --- kakasoo/app.controller.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 kakasoo/app.controller.ts diff --git a/kakasoo/app.controller.ts b/kakasoo/app.controller.ts new file mode 100644 index 00000000000..83441ba67d0 --- /dev/null +++ b/kakasoo/app.controller.ts @@ -0,0 +1,10 @@ +import { Controller, Post } from '@nestjs/common'; + +@Controller('products') +export class AppController { + @Post() + createProduct() { + // This is a placeholder for creating a product + return { message: 'Product created successfully' }; + } +} \ No newline at end of file From 5ead95c0037803eaa971b9c939510f61af7eea7b Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:21:49 +0900 Subject: [PATCH 03/11] Update product creation API with Prisma integration --- kakasoo/app.controller.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kakasoo/app.controller.ts b/kakasoo/app.controller.ts index 83441ba67d0..eea10b484c9 100644 --- a/kakasoo/app.controller.ts +++ b/kakasoo/app.controller.ts @@ -1,10 +1,15 @@ -import { Controller, Post } from '@nestjs/common'; +import { Controller, Post, Body } from '@nestjs/common'; +import { PrismaClient, Product } from '@prisma/client'; + +const prisma = new PrismaClient(); @Controller('products') export class AppController { @Post() - createProduct() { - // This is a placeholder for creating a product - return { message: 'Product created successfully' }; + async createProduct(@Body() productData: Omit) { + const product = await prisma.product.create({ + data: productData, + }); + return product; } } \ No newline at end of file From 3c7b0a94d1af3d548810312cbe7ae43a488f0cd3 Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:23:24 +0900 Subject: [PATCH 04/11] Initialize basic product creation API From 7f919bf40a3140c760652bf2e914e2ce56d473e6 Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:23:31 +0900 Subject: [PATCH 05/11] Add error handling to product creation API --- kakasoo/app.controller.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kakasoo/app.controller.ts b/kakasoo/app.controller.ts index eea10b484c9..0bb11293dcf 100644 --- a/kakasoo/app.controller.ts +++ b/kakasoo/app.controller.ts @@ -7,9 +7,13 @@ const prisma = new PrismaClient(); export class AppController { @Post() async createProduct(@Body() productData: Omit) { - const product = await prisma.product.create({ - data: productData, - }); - return product; + try { + const product = await prisma.product.create({ + data: productData, + }); + return product; + } catch (error) { + throw new Error('Error creating product'); + } } } \ No newline at end of file From 0fc2c04deefb8cea2fd9f121d9d02a40a5c7fdf8 Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:23:38 +0900 Subject: [PATCH 06/11] Improve error response structure in product creation API --- kakasoo/app.controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kakasoo/app.controller.ts b/kakasoo/app.controller.ts index 0bb11293dcf..5c97165976f 100644 --- a/kakasoo/app.controller.ts +++ b/kakasoo/app.controller.ts @@ -11,9 +11,9 @@ export class AppController { const product = await prisma.product.create({ data: productData, }); - return product; + return { status: 'success', product }; } catch (error) { - throw new Error('Error creating product'); + return { status: 'error', message: 'Error creating product' }; } } } \ No newline at end of file From 6cc958713bcdec7f06fad757264c7baac611f3ff Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:23:45 +0900 Subject: [PATCH 07/11] Return detailed error message from product creation API --- kakasoo/app.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kakasoo/app.controller.ts b/kakasoo/app.controller.ts index 5c97165976f..33571f75651 100644 --- a/kakasoo/app.controller.ts +++ b/kakasoo/app.controller.ts @@ -13,7 +13,7 @@ export class AppController { }); return { status: 'success', product }; } catch (error) { - return { status: 'error', message: 'Error creating product' }; + return { status: 'error', message: error.message }; } } } \ No newline at end of file From 39c99b738d80aa74a87c5654d206f691245a4a48 Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:23:52 +0900 Subject: [PATCH 08/11] Include error details in the response for product creation API --- kakasoo/app.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kakasoo/app.controller.ts b/kakasoo/app.controller.ts index 33571f75651..06b7c5387d2 100644 --- a/kakasoo/app.controller.ts +++ b/kakasoo/app.controller.ts @@ -13,7 +13,7 @@ export class AppController { }); return { status: 'success', product }; } catch (error) { - return { status: 'error', message: error.message }; + return { status: 'error', message: error.message, details: error }; } } } \ No newline at end of file From 389e993b96878164d9bf68af46fb937df5c77d2c Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:23:59 +0900 Subject: [PATCH 09/11] Include error details in the response for product creation API From 66c76a1293348f818532162bc7bff4565651e96e Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:24:07 +0900 Subject: [PATCH 10/11] Refactor product creation API to improve error handling From 00ed51e53b5ee5e18acd4bb1fee39a9f61811b0d Mon Sep 17 00:00:00 2001 From: studio-pro Date: Thu, 19 Sep 2024 11:37:48 +0900 Subject: [PATCH 11/11] Refactor product creation API with enhanced error handling --- kakasoo/app.controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kakasoo/app.controller.ts b/kakasoo/app.controller.ts index 06b7c5387d2..2a0310d87e9 100644 --- a/kakasoo/app.controller.ts +++ b/kakasoo/app.controller.ts @@ -11,9 +11,9 @@ export class AppController { const product = await prisma.product.create({ data: productData, }); - return { status: 'success', product }; + return { success: true, data: product }; } catch (error) { - return { status: 'error', message: error.message, details: error }; + return { success: false, error: error.message }; } } } \ No newline at end of file