Mock Shop is a simple backend API for a shopping outlet
- Nodejs
- PostgreSQL
- Sequelize
- Redis
- Docker
- Users can
- Sign in
- Add products to carts
- Remove products from carts
- view carts
- Admin can
- Sign in
- manage products (add, remove, edit, view)
To run this API locally simply follow the instructions below:
You need to have or install the following:
- Git bash
- Npm
- Postman
-
clone repo
git clone https://github.com/fegoworks/mock-shop.git -
navigate to api folder
-
run installation
npm install -
create a
.envfile with this templateDATABASE_URL = 'Your postgres database url' DATABASE_URL_TEST = 'Your postgres test database url' DATABASE_URL_DEVELOPMENT = 'Your postgres database url' PORT = 'Your local port' SECRET = 'Your secret phrase' CLOUD_NAME = 'Your cloudinary cloud name' CLOUDINARY_API_KEY = 'cloudinary api key' CLOUDINARY_API_SECRET = 'cloudinary api secret' -
run migrations and seeding
sequelize db:migratesequelize db:seed:all -
start app
npm run start:dev -
you can now make requests using postman to
localhost:3000/api/v1/
To run tests simply run the following command in your git bash or command line
npm run test
Heroku: Mock-Shop-API Documentation: Mock-EPL-API-Docs
| Endpoints | Functionality |
|---|---|
| POST /auth/create-user | Create new user account |
| POST /auth/signin | Login a user |
| POST /products | Create a product |
| POST /carts | Add products to a cart |
| PATCH /products/:productId | Edit a product |
| PATCH /products/:productId/upload | Update a product with image |
| DELETE /carts/:productId | Remove a product from cart |
| DELETE /products/:productId | Delete a specific product |
| GET /carts/ | View cart |
| GET /products/ | View all products |
Send a POST request to /api/v1/auth/create-user with the following JSON structure:
{
"firstName": "Sensei",
"lastName": "Saitama",
"email": "saitama@mail.com",
"password": "password",
"isAdmin": "true"
}For admins isAdmin is provided with true while for users it is set to false. POST and PATCH requests to /products are restricted to only the admin accounts. User accounts can send requests to /carts.
Send a POST request to /api/v1/auth/signin, with the following:
{
"email": ,
"password":
}When you signin you'll receive a Bearer token. You'll need this token to send any request related to products and carts.
Frow now on, every request described here will require you send the Bearer token
Send a POST request to /api/v1/products, with the following:
{
"name": "bread",
"description": "food",
"category": "Bromate free",
"price": 350,
"inStock": true
}Send a GET request to /api/v1/products/
Send a PATCH request to /api/v1/products/:productId, with the following:
{
"name": "burger",
"description": "food",
"category": "Bromate free",
"price": 650,
"inStock": false
}Send a PATCH request in a multipart form to /api/v1/products/:productId/upload, with image as the field name and a picture file
Delete a team by placing its id in the DELETE request URL
/api/v1/products/:productId.
Send a POST request to /carts/:productId
Send a GET request to /api/v1/carts/
Delete a product by placing its id in the DELETE request URL
/carts/:productId.
Edafe Oghenefego @realFego