gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
Untitled conversation
- User
{description:develope a product insert api, accetp alll theses values from user, { "name": "string", "description": "string", "price": "number", "sizes": ["S", "M", "L"], "colors": ["red", "blue"], "images": ["url1", "url2"], "stock": "number", "rating": "number" } api functions name createProduct response with created product details and total product count }
Analyse above object generate source code for description and send response as only a json_object{ "name": "prompt_name", "schema": { "type": "string", "code":"genarted code" } } make sure response json object doesn't have any errors
- Assistant
Here’s a generated JSON object containing the source code for the product insert API as per your description:
{ "name": "createProduct", "schema": { "type": "string", "code": "const express = require('express');\nconst app = express();\nconst bodyParser = require('body-parser');\n\napp.use(bodyParser.json());\n\nlet products = []; // To hold products\n\napp.post('/api/products', (req, res) => {\n const { name, description, price, sizes, colors, images, stock, rating } = req.body;\n \n // Basic validation\n if (!name || !description || !price || !sizes || !colors || !images || stock === undefined || rating === undefined) {\n return res.status(400).json({ error: 'All fields are required.' });\n }\n \n // Create the product\n const newProduct = {\n id: products.length + 1,\n name,\n description,\n price,\n sizes,\n colors,\n images,\n stock,\n rating\n };\n \n products.push(newProduct);\n \n res.status(201).json({ product: newProduct, totalProducts: products.length });\n});\n\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n console.log(`Server is running on port ${PORT}`);\n});" } }