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.
- π About the Project
- π» Getting Started
- π API Reference
- π₯ Authors
- π€ Contributing
- βοΈ Show your support
- π Up next
- π Lesson Learned
- 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.
To get a local copy up and running, follow these steps.
In order to run this project you need:
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 )
Clone this repository to your desired folder:
cd my-folder
git clone https://github.com/ahmedeid6842/Vending.git
Install this project with NPM:
npm install
Install this project with Docker-compose:
docker-compose build
- To run the project using NPM:
npm start
npm run dev #if your are a developer
- To run the project using Docker-compose:
docker compose up -d
Import this JSON file into Postman, and you will be able to use all REST APIs.
If you don't know how to do it, watch this video.
If you would like to import data to mongo collection you will
- Go to you project your project folder path
cd ./your-folder
- 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
Here it's swagger REST API reference : Swagger Docs Vending
Here it's Postman docs : Postman docs Vending
Ahmed Eid πββοΈ
- Github: @ahmedeid6842
- LinkedIn : Ahmed Eid
- Twitter: @ahmedeid2684
Contributions are always welcomeπ, and as a thank you, vending will give you something for free π .
If you find this project helpful, I would greatly appreciate it if you could leave a star! π π
- Forget password: π
- Real time services with socket.io π£
- allow adding products' images π·
- Using Microservice β¨
- handle edge cases
- Build a strong authorization authentication
- There is always something new to learn π¨βπ».