Skip to content

Commit

Permalink
docs: changes to routes and new statuscodes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalCodes committed Sep 21, 2023
1 parent b0ec17b commit 37fbfa4
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 40 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ MONGO_URI=""
PORT="5000"

# YOU CAN PUT YOUR OWN SECRET RANDOM STRING HERE
JWT_SECRET= ""
JWT_SECRET="thiswillbeyourrandomkey"

# YOU CAN PUT YOUR OWN GOOGLE OAUTH CREDENTIALS HERE, OR RANDOM STRINGS IF YOU ARE NOT EXPLORING THE GOOGLE OAUTH FEATURE
# Else you might need to change the callback URL in YOUR google developer console

SECRET_KEY=""
CLIENT_ID=""
CLIENT_SECRET=""
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ body:
attributes:
label: "Checklist ✅"
options:
- label: "I checked and didn't find similar [issue](https://github.com/MilanCommunity/Milan/issues)"
- label: "I checked and didn't find similar [issue](https://github.com/MilanCommunity/Milan-Backend/issues)"
required: true

- label: "I have read the [Contributing Guidelines](https://github.com/MilanCommunity/Milan/blob/main/CONTRIBUTING.md)"
- label: "I have read the [Contributing Guidelines](https://github.com/MilanCommunity/Milan-Backend/blob/main/CONTRIBUTING.md)"
required: true

- label: "I am willing to work on this issue (blank for no)."
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ body:
attributes:
label: "Checklist ✅"
options:
- label: "I checked and didn't find similar [issue](https://github.com/MilanCommunity/Milan/issues)"
- label: "I checked and didn't find similar [issue](https://github.com/MilanCommunity/Milan-Backend/issues)"
required: true

- label: "I have read the [Contributing Guidelines](https://github.com/MilanCommunity/Milan/blob/main/CONTRIBUTING.md)"
- label: "I have read the [Contributing Guidelines](https://github.com/MilanCommunity/Milan-Backend/blob/main/CONTRIBUTING.md)"
required: true

- label: "I am willing to work on this issue (blank for no)"
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ body:
attributes:
label: "Checklist ✅"
options:
- label: "I checked and didn't find similar [issue](https://github.com/MilanCommunity/Milan/issues)"
- label: "I checked and didn't find similar [issue](https://github.com/MilanCommunity/Milan-Backend/issues)"
required: true

- label: "I have read the [Contributing Guidelines](https://github.com/MilanCommunity/Milan/blob/main/CONTRIBUTING.md)"
- label: "I have read the [Contributing Guidelines](https://github.com/MilanCommunity/Milan-Backend/blob/main/CONTRIBUTING.md)"
required: true

- label: "I am willing to work on this issue (blank for no)"
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/other.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ body:
attributes:
label: "Checklist ✅"
options:
- label: "I checked and didn't find similar [issue](https://github.com/MilanCommunity/Milan/issues)"
- label: "I checked and didn't find similar [issue](https://github.com/MilanCommunity/Milan-Backend/issues)"
required: true

- label: "I have read the [Contributing Guidelines](https://github.com/MilanCommunity/Milan/blob/main/CONTRIBUTING.md)"
- label: "I have read the [Contributing Guidelines](https://github.com/MilanCommunity/Milan-Backend/blob/main/CONTRIBUTING.md)"
required: true

- label: "I am willing to work on this issue (blank for no)"
Expand Down
68 changes: 66 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,66 @@
# Milan-Backend
This is the official repository for Milan's server side codes.
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/MilanCommunity/Milan-Backend)](https://github.com/MilanCommunity/Milan-Backend/releases) ![GitHub repo size](https://img.shields.io/github/repo-size/MilanCommunity/Milan-Backend)

# What is Milan ?

Milan is a hub to **connect** NGOs, Charities, and the world to **collaborate** and **build** a better tomorrow. Sign up as an organization/user and be a cause for change. Don't forget to drop a star ⭐.

<br/>



<div align="center" >

<div align="center" >
<a href="https://api.milanhub.org/"><img alt="C" src="https://img.shields.io/badge/Production%20Release-07C160?style=for-the-badge&logo=vercel&logoColor=white"></a> <a href="https://github.com/sponsors/tamalCodes"><img alt="Sponsor Tamal" src="https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#white"></a>


</div>

<img alt="Milan Readme Banner" src="./docs/pictures/MilanBanner.png" width="700px"/>

</div>

<br>

## Tech Stack(Backend) 💻

<p >
<a href="https://nodejs.org/it/docs"><img alt="C" src="https://img.shields.io/badge/node.js-%2343853D.svg?style=for-the-badge&logo=node.js&logoColor=white"></a>
<a href="https://expressjs.com/"><img alt="C" src="https://img.shields.io/badge/express.js-%23404d59.svg?style=for-the-badge"></a>
<a href="https://www.mongodb.com/docs/"><img alt="C" src="https://img.shields.io/badge/MongoDB-%234ea94b.svg?style=for-the-badge&logo=mongodb&logoColor=white"></a>
<a href="https://docs.github.com/en"><img alt="C" src="https://img.shields.io/badge/GitHub-%23121011.svg?style=for-the-badge&logo=github&logoColor=white"></a>
<a href="https://opensource.guide/how-to-contribute/"><img alt="C" src="https://img.shields.io/badge/Open%20Source-%23F05032.svg?style=for-the-badge&logo=open-source-initiative&logoColor=white"></a>
<a href="https://docs.github.com/en/actions"><img alt="C" src="https://img.shields.io/badge/GitHub%20Actions-%232671E5.svg?style=for-the-badge&logo=github-actions&logoColor=white"></a>
<a href="https://docs.github.com/en/actions"><img alt="C" src="https://img.shields.io/badge/Razorpay-02042B?style=for-the-badge&logo=razorpay&logoColor=3395FF"></a>

</p>

</br>

## Contributing to Milan 🔐

Remember, Good PR makes you a Good contributor !

We at Milan work hard to maintain the structure, and use conventional Pull request titles and commits. Without a proper template for the PR, not following the guidelines and spam might get the pull request closed, or banned.

### 1️⃣ Setting up the project locally

- [Forking + Cloning Guide](/docs/CloneSetup.md)
- [Setting up the Backend (current repo)](/docs/BackendSetup.md)
- [Setting up the Frontend](/docs/FrontendSetup.md)
- [Setting up with docker](/docs/DockerSetup.md)


### 2️⃣ Contributing guidelines & More

- [Proper API documentation](https://milan-server.onrender.com/docs/) for developers.
- [Contributing Guidelines](/CONTRIBUTING.md) to be followed.
- [Workflow Overview](/docs/Workflow.md) of our project.

## License 👮

Milan is Licensed under the <a href="./LICENSE">MIT License</a>. Please go through the License at least once before contributing.

## Support 🙏

**Don't forget to drop a star ⭐.** A heartfelt thank you to those who have contributed to this project. We are really grateful for your contribution. You all are amazing. Opensource for the win 🚀
4 changes: 2 additions & 2 deletions config/api.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
openapi: 3.0.0
info:
title: Milan API
description: Feel free to raise an issue or PR [here](https://github.com/tamalCodes/Milan/issues/new/choose).
description: Feel free to raise an issue or PR [here](https://github.com/MilanCommunity/Milan-Backend/issues/new/choose).
version: 1.0


servers:
- url: http://localhost:5000/
description: Local server
- url: https://test.com/
- url: https://api.milanhub.org/
description: Production server


Expand Down
57 changes: 57 additions & 0 deletions docs/BackendSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Backend Setup

Follow the below setup to setup the backend locally. We are using `npm` as the
package manager. So make sure you have `node` and `npm` installed in your
system.

**If not installed, please read
[installation guide](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).**

## Installing dependencies ⏳

- Open your terminal and navigate to the `Milan-Backend` directory.
- Type `npm install` to install all the dependencies.
- Once the installation is done, you can start the frontend server by typing
`npm start`.
- This should start the frontend server on `http://localhost:5000/`.

## Techstack overview 🌀

- We are currently using `ExpressJS v4` along with `MongoDB v6` as the backend
framework.
- We are using `Nodemon` for the hot reloading.
- List of all the other dependencies can be found in the `package.json` file.

## Setting up `.env`

We use a `.env` file using the `dotenv` package inside the root of the `server`
directory.

You must create a `.env` file similar to **[.env.example](../.env.example)** file, remember that if you are using your own database the data might vary.


### Setting up `razorpay api key` for `.env`
- Head on to [Razorpay API reference](https://razorpay.com/docs/api) and Sign Up to razor pay remember you don't need to KYC.
- Login after Signing Up then you will see this interface, you can use the test mode.

<img width="945" alt="image" src="https://github.com/tejaskh3/Milan/assets/98630752/2de85099-8167-4db2-9fc7-9d539c5bcf64">

- Then move to `Account & Settings` there you will get API keys option where you can generate the keys.

<img width="960" alt="image" src="https://github.com/tejaskh3/Milan/assets/98630752/b1feb58c-f71a-4820-b298-40f05d27146e">

- Generate and copy the key and its secret and paste it to `RAZORPAY_KEY_ID` and `RAZORPAY_KEY_SECRET` respectively and you are done setting up backend.

<img width="359" alt="image" src="https://github.com/tejaskh3/Milan/assets/98630752/5f08bde3-17fa-472d-9587-9524fa737dd5">

## Coding standards 🔐

- Make sure to follow proper latest coding practices.
- Maintain a good readable folder structure
- Incase adding an API, do document it.

## Next steps 🚀

So now you have the the frontend up and running locally. Now you can start working on the issues. Now follow the below steps to setup the frontend locally (if needed).

1. [Setting up the frontend locally](/docs/FrontendSetup.md)
24 changes: 24 additions & 0 deletions docs/CloneSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Getting started

## Forking 🍴

- There will be a `Fork` button on the top right corner of the repo. Click on it.
- This will create a copy of the repo in your GitHub account.

## Cloning 🌀

- After the fork is done, you will be redirected to your forked repo.
- The next step is to clone the repo to your local storage.
- Open your terminal and enter the following command and hit enter.

```bash
git clone https://github.com/MilanCommunity/Milan-Backend.git
```
- This will clone the repo to your local storage and you can start working on it.

## Next steps 🚀

So now you have the repo in your local storage. The next step is to setup the frontend and backend locally. You can refer to the following links to setup the frontend and backend locally.

1. [Setting up the backend (current repo)](/docs/BackendSetup.md)
2. [Setting up frontend locally](/docs/FrontendSetup.md)
36 changes: 36 additions & 0 deletions docs/FrontendSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Frontend Setup

Follow the below steps to setup the Frontend locally. We are using `npm` as the package manager. So make sure you have `node` and `npm` installed in your system.

**If not installed, please read [installation guide](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).**
## Installing dependencies ⏳

- Open your terminal and navigate to the `Milan` directory.
- Type `npm install` to install all the dependencies.
- Once the installation is done, you can start the frontend server by typing `npm run dev`.
- This should start the frontend server on `http://localhost:3000/`.

## Techstack overview 🌀

- We are currently using `ReactJS v18` along with `vite v3` as the frontend framework.
- We using `CSS (Bootstrap v5)` for the styling.
- We have also implemented `service workers` which might not run in the development environment but will be used in the production environment. Please clear your cache if you are facing any issues.
- To test service workers in development environment, you can run `npm run build` and then `serve dist` to serve the production build locally.
- Then you can navigate to `http://localhost:5000/` to see the production build running locally with service workers which can be found in `Application tab -> Service workers` in the dev tools.
- List of all the other dependencies can be found in the `package.json` file.


## Coding standards 🔐

- We are using `ESLint` and `Prettier` for linting and formatting.
- Maintain the same coding standards as the rest of the codebase.
- Follow good naming conventions for the files, variables and functions along with proper documentation (if needed).
- We also use `husky` and `lint-staged` to run the linter and formatter before every commit. Read about this in our [Contributing Guidelines](/CONTRIBUTING.md).
- Maintain a good folder structure, incase you use anu new components or pages make sure you put them in the right folder.
- If you are using any new dependencies, make sure you mention them in the PR.
- If you are using any new Image , compress it using [online tools]("https://www.iloveimg.com/compress-image") and then use it in the project.
- **Remember**, writing readable and clean code while following the coding standards is the best thing for any developer.

## Setting up the `.env` file

We use a `.env` file using the `dotenv` package inside the root of the directory. You must create a `.env` file similar to the **[.env.example](https://github.com/MilanCommunity/Milan/blob/main/.env.example)** file in the Frontend repo.
18 changes: 18 additions & 0 deletions docs/Workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Contribution Workflow 🏭

We at Milan believe in industry standards and super organized and clean workflow. Here's how your contributions will be handled.


## How we merge PRs

1. Follow [PR Guidelines](https://github.com/MilanCommunity/Milan/blob/main/CONTRIBUTING.md#creating-a-pull-request-) to raise a PR. We wait upto a month before considering it inactive/ready for review. Maintainers and contributors both have other works to do too.

2. Maintainers will review, request changes, and approve the PR accordingly. If changes are requested do click on the `Resolve Conversation` button to let the maintainers know that you have made the changes. Be paitent at all times.

3. Once the PR is approved, a label of https://github.com/MilanCommunity/Milan-Backend/labels/%F0%9F%A5%97%20status%3A%20ready%20for%20merge will be added and the PR will be merged.


## How we publish releases

- Once the changes are merged to `main` branch, a new `draft release` will be created.
- The release will be published in due time depending upon how important they are.
Binary file added docs/pictures/MilanBanner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,11 @@ app.get("/", (req, res) => {
res.send("HELLO FROM HOME");
});

//* user routes
app.use("/user", require("./routes/user/User"));

//* club routes
app.use("/clubs", require("./routes/club/Club"));

//* Display routes
app.use("/display", require("./routes/display/Display"));

//* Payment routes
app.use("/payment", require("./routes/payment/Payment"));

//* Product routes
app.use("/product", require("./routes/shop/Products"));

//* Google Auth routes
app.use("/auth", require("./routes/user/Auth"));

app.listen(port, () => console.log("API IS RUNNING 🚀 at port:", port));
23 changes: 14 additions & 9 deletions routes/user/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require("express");
const router = express.Router();
var jwt = require("jsonwebtoken");
const passport = require("passport");
const { StatusCodes, StatusMessages } = require("../../utils/StatusCodes");

//* Route 5 - google authentication
router.get("/google", (req, res) => {
Expand All @@ -16,7 +17,7 @@ router.get("/google", (req, res) => {

const redirectURL = `${googleAuthURL}?${params}`;

return res.status(201).json({ url: redirectURL });
return res.status(StatusCodes.CREATED).json({ url: redirectURL });
});

//* Route 6 - google authentication callback
Expand All @@ -41,8 +42,8 @@ router.get(
//* Route 7 - google authentication failed
router.get("/login/failed", (req, res) => {
res
.status(401)
.json({ error: true, message: "User failed to authenticate." });
.status(StatusCodes.UNAUTHORIZED)
.json({ error: true, message: StatusMessages.UNAUTHORIZED });
});

//* Route 8 - google authentication success
Expand All @@ -61,7 +62,7 @@ router.get("/login/success", (req, res) => {
}

res
.status(201)
.status(StatusCodes.CREATED)
.cookie("OAuthLoginInitiated", false, {
expires: new Date(0),
httpOnly: false,
Expand Down Expand Up @@ -90,18 +91,22 @@ router.get("/login/success", (req, res) => {
domain: process.env.ORIGIN_DOMAIN,
})
.json({
message: "Logged you in !",
message: StatusMessages.LOGIN_SUCCESS,
});
} else {
res.status(403).json({ error: true, message: "Not Authorized" });
res
.status(StatusCodes.UNAUTHORIZED)
.json({ error: true, message: StatusMessages.UNAUTHORIZED });
}
});

//* Route 9 - google authentication logout
router.get("/logout", (req, res) => {
req.logout(function (err) {
if (err) {
return res.status(500).json({ message: "Error while logging out." });
return res
.status(StatusCodes.INTERNAL_SERVER_ERROR)
.json({ message: StatusMessages.INTERNAL_SERVER_ERROR });
}

res
Expand All @@ -112,8 +117,8 @@ router.get("/logout", (req, res) => {
domain: process.env.ORIGIN_DOMAIN,
secure: true,
})
.status(201)
.json({ message: "Logged you out !" });
.status(StatusCodes.CREATED)
.json({ message: StatusMessages.LOGOUT_SUCCESS });
});
});

Expand Down
Loading

0 comments on commit 37fbfa4

Please sign in to comment.