- Introduction
- Getting Started
- Working Routes
- Assumption made (Thought process)
- Improvements to be made
- Requirement not covered
- License
This is a RESTful API for a simple cart service.
Airbnb (Javascript style guide)
├── src
├── components
├── auth
├── cart
├── product
├── user
├── database
├── lib
├── typings
├── express
├── .env.sample
├── .gitignore
├── .sequelizerc
├── package.json
├── README.json
├── tsconfig.json
└── yarn.lock
Each response will be returned with one of the following HTTP status codes:
200
OK
The request was successful201
New Resource
The request was successful and created a new resource400
Bad Request
There was a problem with the request (security, malformed)404
Not Found
An attempt was made to access a resource that does not exist in the API500
Server Error
An error on the server occurred
- Users can sign up.
- Users can login.
- Users can get product lisitings
- Users can search product by title and description
- Users can add product to cart
- Users can remove product from cart
- Users can get cart items
- Users can initiate cart checkout process
This project uses Express.js v4.16. It has the following dependencies:
- Node.js
>=
12.18.3 - PostgreSQL Database
- Sequelize
- Mocha & Chai
- ESLint & Prettier
- Ensure you have NodeJS installed by entering
node -v
on your terminal If you don't have NodeJS installed, go to the NodeJS Website, and follow the download instructions
You can clone this project directly using this command:
git clone https://github.com/mekzy-o/myos-backend.git
- Create a PostgreSQL database by running the
cmd
below:
createdb -h localhost -p 5432 -U postgres <database_name>
- After cloning the repository, create a
.env
file from.env.example
and set your local.env.
variable(s).
cp .env.example .env
- Install the dependencies
yarn install
- Run database migrations
yarn run db:migrate
- Run database seed
yarn run db:seed
- You can run the development server using
yarn run start:dev
- Other
yarn
scripts are also available for handling database migrations and database seeding:yarn run db:migrate
runs script that is responsible for creating tables and their columns in the database,db:migrate:undo
: undoes the effect ofnpm run db:migrate
,db:reset
: undoes all the migrations, then runs migration on the database,db:seed
: responsible for seeding records in the database,
- Public API documentation of this project is available on postman docs
Endpoint | Functionality | HTTP method |
---|---|---|
/api/v1/users/register | Create a user account | POST |
/api/v1/users/login | Login a user | POST |
/api/v1/products | Get All Product Listing | GET |
/api/v1/products?title=title&description='description' | Search Books by Title and Description | GET |
/api/v1/carts | Add Items to cart | POST |
/api/v1/carts/:cartId | Get A Cart and Items in it | GET |
/api/v1/carts/:cartId/products/:productId | Remove a single product from cart | DELETE |
/api/v1/carts/:cartId/checkout | Checkout Cart | GET |
- Admins are not required for this MVP, hence every logged-in user can perform all actions
- Since there are no admins to add products. I created a seed data with each of products with each asset image file (hosted on cloudinary) (this can be found in my
src/database/seeders
). - I did not authenticate product listings and product search routes, this needs to be available to non-logged in users.
- I assumed only users that are logged-in would be able to access cart, this may not be optimal and can be improved.
- There are no payment gateway integration, so Check-Out process displays a summary showing total amount, cart id and user id
- An order is created in the order table on successful Check-Out
- non-logged in users should be able to access cart
- Redis can be used as a store to persist cart. This would reduce the latency of read/write operations to the database
- Checkout process can be optimized
This project is under the MIT LICENSE