This repository contains the backend Express server for the Questions & Answers service of a clothing e-commerce website. The service is responsible for handling user inquiries, allowing them to ask and answer questions about products available on the website.
Follow the instructions below to set up the backend server on your local machine.
Before you begin, ensure you have the following installed:
- Node.js (v14 or later)
- npm (Node Package Manager)
- PostgreSQL 15
- Clone this repository to your local machine using:
git clone https://github.com/your-username/questions-answers-backend.git
- Navigate to the project directory:
cd questions-answers-backend
- Install the required dependencies:
npm install
- Create a .env file in the root directory and provide the necessary environment variables. Here is an example:
PGUSER=postgres_user
PGHOST=postgres_host
PGPASSWORD=postgres_password
PGDATABASE=postgres_db
PGPORT=postgres_port
PORT=3001
- Start the server:
npm start
The server will run on the specified port (default: 3001).
The Questions & Answers service provides APIs for managing product-related questions and answers. You can integrate these APIs with your clothing e-commerce website frontend to allow users to ask and answer questions about products.
GET /api/questions
: Get a list questions for a given product id passed as a query param.GET /api/questions/:question_id/answers
: Get a list of answers for a given question id.POST /api/questions
: Add a question for a product id passed as a query param.POST /api/questions/:question_id/answers
: Adds an answer for a given question_id.PUT /api/questions/:question_id/helpful
: Marks a question as helpful by incrementing helpfulness count.PUT /api/questions/:question_id/report
: Updates question's "reported" field to true, marking the question as reported.PUT /api/answers/:answer_id/helpful
: Marks an answer as helpful by incrementing helpfulness count.PUT /api/answers/:answer_id/report
: Updates answer's "reported" field to true, marking the answer as reported.
This project uses PostgreSQL 15 as the database to store questions and answers. Ensure you have PostgreSQL set up and running before starting the server.
We welcome contributions to improve this backend server. To contribute, follow these steps:
- Fork the repository.
- Create a new branch for your feature/bugfix.
- Make your changes and test thoroughly.
- Create a pull request with a detailed description of your changes.
This project is licensed under the MIT License.