diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php new file mode 100644 index 0000000..ed8a6b0 --- /dev/null +++ b/app/Http/Controllers/ProductController.php @@ -0,0 +1,28 @@ +orderByDesc('id') + ->get(); + + return response()->json([ + 'data' => $products, + ]); + } + + public function show(int $id) + { + $product = Product::query()->findOrFail($id); + + return response()->json([ + 'data' => $product, + ]); + } +} \ No newline at end of file diff --git a/app/Models/Product.php b/app/Models/Product.php new file mode 100644 index 0000000..a122968 --- /dev/null +++ b/app/Models/Product.php @@ -0,0 +1,18 @@ + 'integer', + ]; +} \ No newline at end of file diff --git a/database/migrations/2026_01_28_134245_create_products_table.php b/database/migrations/2026_01_28_134245_create_products_table.php new file mode 100644 index 0000000..085b7ec --- /dev/null +++ b/database/migrations/2026_01_28_134245_create_products_table.php @@ -0,0 +1,26 @@ +id(); + $table->string('name', 180); + $table->text('description')->nullable(); + $table->unsignedInteger('price'); + $table->string('image_url', 500)->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('products'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php new file mode 100644 index 0000000..c77250d --- /dev/null +++ b/database/seeders/DatabaseSeeder.php @@ -0,0 +1,15 @@ +call([ + ProductSeeder::class, + ]); + } +} \ No newline at end of file diff --git a/database/seeders/ProductSeeder.php b/database/seeders/ProductSeeder.php new file mode 100644 index 0000000..a352ffc --- /dev/null +++ b/database/seeders/ProductSeeder.php @@ -0,0 +1,49 @@ + 'CloudShopt Hoodie', + 'description' => 'Comfort hoodie with CloudShopt logo.', + 'price' => 4990, + 'image_url' => null, + ], + [ + 'name' => 'CloudShopt T-Shirt', + 'description' => 'Basic tee for everyday wear.', + 'price' => 1990, + 'image_url' => null, + ], + [ + 'name' => 'Sticker Pack', + 'description' => 'Set of 10 vinyl stickers.', + 'price' => 590, + 'image_url' => null, + ], + [ + 'name' => 'Coffee Mug', + 'description' => 'Ceramic mug 330ml.', + 'price' => 1290, + 'image_url' => null, + ], + [ + 'name' => 'Notebook', + 'description' => 'A5 dotted notebook.', + 'price' => 990, + 'image_url' => null, + ], + ]; + + foreach ($items as $item) { + Product::query()->create($item); + } + } +} \ No newline at end of file diff --git a/docs/openapi.yaml b/docs/openapi.yaml new file mode 100644 index 0000000..7d00ea5 --- /dev/null +++ b/docs/openapi.yaml @@ -0,0 +1,102 @@ +openapi: 3.0.3 +info: + title: CloudShopt Product Service API + version: 0.1.0 + description: API for product catalog +servers: + - url: /api +tags: + - name: meta + - name: products + +paths: + /info: + get: + tags: [meta] + summary: Service info (test endpoint) + responses: + "200": + description: OK + content: + application/json: + schema: + type: object + properties: + service: + type: string + example: product-service + status: + type: string + example: ok + + /health: + get: + tags: [meta] + summary: Health check + responses: + "200": + description: Healthy + content: + application/json: + schema: + type: object + properties: + ok: + type: boolean + example: true + + /products: + get: + tags: [products] + summary: List products (test placeholder) + responses: + "200": + description: OK + content: + application/json: + schema: + type: object + properties: + data: + type: array + items: + $ref: "#/components/schemas/Product" + "500": + $ref: "#/components/responses/ServerError" + +components: + responses: + ServerError: + description: Server error + content: + application/json: + schema: + $ref: "#/components/schemas/ErrorResponse" + + schemas: + Product: + type: object + properties: + id: + type: integer + example: 1 + name: + type: string + example: "T-Shirt" + price: + type: number + format: float + example: 19.99 + + ErrorResponse: + type: object + properties: + message: + type: string + example: "Internal Server Error" + code: + type: string + example: "SERVER_ERROR" + details: + type: object + additionalProperties: true \ No newline at end of file diff --git a/resources/views/swagger.blade.php b/resources/views/swagger.blade.php new file mode 100644 index 0000000..34fe766 --- /dev/null +++ b/resources/views/swagger.blade.php @@ -0,0 +1,22 @@ + + +
+ + +