DeveloperGPT Guru | Coding Issues Resolution Prompt Template

ID: 2098Words in prompt: 319
1
-
Comments
This prompt is designed for developers and programmers who are seeking assistance with a wide range of coding issues, challenges, and problems. Whether you're dealing with a bug in your code, trying to optimize performance, grappling with a logic error, implementing a complex algorithm, or any other coding-related challenge, this versatile template is here to guide you through the process of finding a solution. By providing detailed context, code snippets, error messages, and your desired outcomes, you enable the AI (Artificial Intelligence) to better understand your problem and offer a tailored solution. The template covers different stages of problem-solving, from problem description to solution explanation, optimization tips, customization guidance, and comprehensive explanations. Whether you're a beginner or an experienced programmer, this template aims to assist you in resolving coding issues effectively. It encourages clear communication and problem framing, allowing the AI to provide meaningful assistance that aligns with your specific needs. Ultimately, this prompt template is a tool to enhance your coding journey by addressing challenges and facilitating learning in a dynamic and interactive manner.
Created: 2023-08-27
Powered by: ChatGPT Version: 3.5
In categories: Coding
-/5 (0)Use & rate
Comments (0)

Title: Coding Issue Resolution Template

Introduction: I'm here to assist you in solving your coding issues. Whether you're facing a bug in your application, need help optimizing a database query, or just need guidance on implementing a complex algorithm, I've got you covered. Please provide me with the necessary details so I can better understand the problem.

Problem Description: I'm currently working on a web application that's supposed to display a list of products based on user preferences. The issue I'm facing is that the product list is not being filtered correctly according to the selected categories. I'm using JavaScript and React for the frontend, and I have an API that returns the list of products from the backend. I'm passing an array of selected categories to the API, but the returned products include items from all categories, not just the selected ones.

Code Snippet: Here's the relevant part of my code where I'm making the API call:

javascript Copy code const selectedCategories = ["electronics", "clothing"]; fetch(/api/products?categories=${selectedCategories.join(",")}) .then(response => response.json()) .then(data => { // Code to update the UI with the fetched products }) .catch(error => { console.error("Error fetching products:", error); }); Error Message (if applicable): I'm not receiving any error messages. The API call is successful, but the returned products are not filtered correctly.

Troubleshooting Steps Taken: I've checked the network tab in my browser's developer tools to ensure that the correct categories are being sent to the API. It seems that the selected categories are indeed being included in the request URL.

Desired Outcome: I want the list of fetched products to only include items from the selected categories (in this case, "electronics" and "clothing").

Placeholder for Additional Context: I'm using React version 17.0.2, and the backend API is built with Node.js using Express. The API endpoint for fetching products is /api/products, and it accepts a comma-separated list of category names as a query parameter.

Solution: To resolve this issue, you need to make sure that the backend API properly filters the products based on the selected categories. Here's a modification you can make to your backend code:

javascript Copy code app.get('/api/products', (req, res) => { const selectedCategories = req.query.categories.split(","); // Assuming you have a function to fetch products from your data source const filteredProducts = fetchProductsByCategories(selectedCategories); res.json(filteredProducts); }); Optimization (if applicable): If your product list is extensive, you might consider adding pagination to your API to improve performance.

Customization: If you have additional filters or requirements, you can modify the backend filtering logic accordingly.

Comprehensive Explanation: By splitting the comma-separated category names from the query parameter, you're now correctly extracting the selected categories on the backend. Then, the fetchProductsByCategories function should retrieve products only from those categories, ensuring that the frontend receives the filtered list.

Conclusion: After implementing these changes to your backend code, your web application should display a list of products that are filtered based on the selected categories. If you have any more questions or encounter further issues, don't hesitate to ask for assistance!