Skip to content

πŸ₯€πŸ§ƒπŸ« This Node.js and Express API provides CRUD and authentication for a vending machine.

Notifications You must be signed in to change notification settings

ahmedeid6842/Vending

Repository files navigation

logo-no-background

Vending Machine API

This API provides endpoints for a vending machine that is accessible to both buyers and sellers. The API includes endpoints for adding, updating, and removing products, as well as depositing coins and making purchases. Authentication and authorization are used to control access to the endpoints based on user role (buyer or seller), and caching is implemented to improve performance. The API requires authentication tokens for requests that require a specific role (buyer or seller), and uses a time-to-live (TTL) value to cache frequently-requested queries.

Contributors Stargazers Issues MIT License LinkedIn

πŸ“— Table of Contents

external-vending-machine-food-technology-wanicon-flat-wanicon Vending

πŸ›  Built With

Tech Stack

Server

Node Express JWT NPM

Database

MongoDB Redis

DevOps

Docker Docker Compose

Docs

Postman Swagger

Key Features

  • Uses authentication and authorization to control access based on user role.
  • Validates requests with Joi and supports CRUD operations for products, coins, purchases, and charges.
  • Allows admins to create machines at specific locations and add products.
  • Supports geolocation to find the nearest machine or product.
  • Implements caching for improved performance using Redis.

(back to top)

πŸ’» Getting Started

To get a local copy up and running, follow these steps.

Prerequisites ❗

In order to run this project you need:

OR

Environment Variables πŸ”‘

To run this project, you will need to add the following environment variables to your .env file

PORT : port where you application start on it

ACCESS_TOKEN_SECRET : string, access token secret (Example: JwtKey)

MONGODB_URI : string, mongo database uri ( Example: mongodb://127.0.0.1/vending).

REDIS_HOST : string, redis database host ( Example: localhost ).

REDIS_PORT : number, redis working port (Example: 6379)

SALT_WORK_FACTOR : number of rounds to create salt for hashing ( Example: 10 )

Setup ⬇️

Clone this repository to your desired folder:

cd my-folder
git clone https://github.com/ahmedeid6842/Vending.git

Install βœ”οΈ

Install this project with NPM:

npm install

Install this project with Docker-compose:

docker-compose build

Usage 🀿 πŸƒβ€β™‚οΈ

  • To run the project using NPM:
  npm start
  npm run dev #if your are a developer 

npm-start

  • To run the project using Docker-compose:
  docker compose up -d

npm-start


After following the above steps you can now use Vending API

Import this JSON file into Postman, and you will be able to use all REST APIs.

Import_Postman_GIF

If you don't know how to do it, watch this video.


Importing data to MongoDB

If you would like to import data to mongo collection you will

  1. Go to you project your project folder path
cd ./your-folder
  1. Run the following commands
mongoimport --db vending --collection users --file import/users.json
mongoimport --db vending --collection machines --file import/machines.json
mongoimport --db vending --collection products --file import/products.json

Import_Data_GIF

(back to top)

API Reference

Swagger 🀩

Here it's swagger REST API reference : Swagger Docs Vending

Swagger_Docs_GIF

Postman 🀩

Here it's Postman docs : Postman docs Vending

Postman_Docs_GIF

(back to top)

πŸ‘€ Author

Ahmed Eid πŸ™‹β€β™‚οΈ

(back to top)

🀝 Contributing

Contributions are always welcomeπŸ’Ÿ, and as a thank you, vending will give you something for free πŸ˜….

(back to top)

⭐️ Show your support

If you find this project helpful, I would greatly appreciate it if you could leave a star! 🌟 πŸ’Ÿ

(back to top)

πŸ”­ Up next

  • Forget password: πŸ’
  • Real time services with socket.io πŸ“£
  • allow adding products' images πŸ“·
  • Using Microservice ✨

(back to top)

πŸ’Ž Lessons Learned

  • handle edge cases
  • Build a strong authorization authentication
  • There is always something new to learn πŸ‘¨β€πŸ’».

(back to top)

About

πŸ₯€πŸ§ƒπŸ« This Node.js and Express API provides CRUD and authentication for a vending machine.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages