Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions README.md

This file was deleted.

Binary file removed UI-Screen-1.png
Binary file not shown.
34 changes: 0 additions & 34 deletions backend.md

This file was deleted.

2 changes: 2 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=3000
DB_CONNECT=mongodb://localhost:27017
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
126 changes: 126 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Help Center API

This is a RESTful API that allows users to manage "Help Center" cards. These cards represent different sections of a help center, such as "Branches," "Manage Your Account," "Manage Billing," etc. The API provides functionality to create, retrieve, and manage these cards.

## Project Setup

### Prerequisites

- Node.js
- MongoDB

### Installation

1. **Clone the repository:**

```bash
git clone https://github.com/omidhokate2002/help-center.git
```

2. **Navigate to the project directory:**

```bash
cd backend
```

3. **Install the dependencies:**

```bash
npm install
```

4. **Set up environment variables:**

- Create a `.env` file in the root directory with the following content:

```env
PORT=3000
DB_CONNECT=your_mongodb_connection_string
```

- Replace `your_mongodb_connection_string` with your actual MongoDB connection string.

5. **Start the server:**

```bash
node index.js
```

- The server will start on `http://localhost:3000`.

## API Endpoints

### Base URL

- `http://localhost:3000/api`

### Endpoints

1. **Ping the server**

- **URL:** `/ping`
- **Method:** `GET`
- **Description:** Check if the server is running.
- **Response:**
```json
"Server is running"
```

2. **Create a new card**

- **URL:** `/cards`
- **Method:** `POST`
- **Description:** Add a new card to the help center.
- **Request Body:**
```json
{
"title": "Branches",
"description": "Abstract Branches lets you manage, version, and document your designs in one place."
}
```
- **Response:**
```json
{
"_id": "60d9f8b5f1f2c9a4a4e8b7f8",
"title": "Branches",
"description": "Abstract Branches lets you manage, version, and document your designs in one place.",
"__v": 0
}
```

3. **Retrieve all cards**

- **URL:** `/cards`
- **Method:** `GET`
- **Description:** Get a list of all the cards in the help center.
- **Response:**
```json
[
{
"_id": "60d9f8b5f1f2c9a4a4e8b7f8",
"title": "Branches",
"description": "Abstract Branches lets you manage, version, and document your designs in one place."
}
// Other cards...
]
```

4. **Retrieve a specific card by title**

- **URL:** `/cards/:title`
- **Method:** `GET`
- **Description:** Get the details of a specific card by its title.
- **Response:**
```json
{
"_id": "60d9f8b5f1f2c9a4a4e8b7f8",
"title": "Branches",
"description": "Abstract Branches lets you manage, version, and document your designs in one place."
}
```

## Error Handling

- **404 Not Found:** Returned when trying to access a non-existent card.
- **400 Bad Request:** Returned when there is a validation error or incorrect request format.
- **500 Internal Server Error:** Returned when there is an issue on the server side.
33 changes: 33 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const cors = require("cors");
const cardRoutes = require("./routes/cards");

dotenv.config();

mongoose
.connect(process.env.DB_CONNECT, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Connected to MongoDB"))
.catch((err) => console.log(err));

app.use(express.json());
const corsOptions = {
origin: "*", // Allow all origins
methods: "GET,HEAD,PUT,PATCH,POST,DELETE", // Allow these HTTP methods
allowedHeaders: "Content-Type,Authorization", // Allow these headers
};

app.use(cors(corsOptions));
app.use("/api", cardRoutes);

app.get("/ping", (req, res) => {
res.send("Server is running");
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
15 changes: 15 additions & 0 deletions backend/models/Card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mongoose = require("mongoose");

const cardSchema = new mongoose.Schema({
title: {
type: String,
required: true,
unique: true,
},
description: {
type: String,
required: true,
},
});

module.exports = mongoose.model("Card", cardSchema);
Loading