This project only contains API only.
How to run :*
- Make sure you have install elasticsearch in your local machine and ruby 2.7.1
- checkout project from github : https://github.com/syafik/my-simple-cart/tree/master
- bundle install
- rake db:create
- rake db:migrate
- rake db:seed
- run elasticsearch in your local machine
- rails s
API path and sample how to call
- Registration
POST /api/v1/auth.
Host: localhost:3000.
Content-Type: application/json.
{
"email": "your@email.com",
"password": "yourpassword123",
"passwrod_confirmation": "yourpassword123",
"name": "Your Name"
}
-
Login
POST /api/v1/auth/sign_in. Host: localhost:3000. Content-Type: application/json. { "email": "your@email.com", "password": "yourpassword123" }
** From Registration and Login API we will have response headers that we will use to define user session in each API request that required login user.
- access-token
- client
- token-type
- expiry
- uid
-
API for listing products
GET /api/v1/products. Host: localhost:3000. * for search by name of product: GET /api/v1/products?q=shirt * for filter by store : GET /api/v1/products?store_id=1
-
API for adding to cart
POST /api/v1/carts/add/:product_variant_id Host: localhost:3000 access-token: access_token_mu token-type: Bearer client: client_mu expiry: 1611053732 uid: uid_mu Content-Type: application/json { "cart": { "quantity": 1, "notes": "test notes" } }
-
API for listing user cart
GET /api/v1/carts Host: localhost:3000 access-token: access_token_mu token-type: Bearer client: client_mu expiry: 1611053732 uid: uid_mu
-
API for modifying cart
PUT /api/v1/carts/item/updates/:cart_item_id
Host: localhost:3000
access-token: access_token_mu
token-type: Bearer
client: client_mu
expiry: 1611053732
uid: uid_mu
Content-Type: application/json
{
"cart": {
"quantity": 1,
"notes": "hayang jago"
}
}
- API for removing cart
DELETE /api/v1/carts/item/delete/:cart_item_id
Host: localhost:3000
access-token: access_token_mu
token-type: Bearer
client: client_mu
expiry: 1611053732
uid: uid_mu
Content-Type: application/json
- API for checkout
POST /api/v1/orders/checkout
Host: localhost:3000
access-token: access_token_mu
token-type: Bearer
client: client_mu
expiry: 1611053732
uid: uid_mu
Content-Type: application/json
{
"checkout":[
{
"store_id": 1,
"items": [
{"product_variant_id": 15, "quantity": 1, "notes": "test order"}
],
"courier": {"id": 1, "price": 10000}
}
]
}
9 API for listing order
GET /api/v1/orders
Host: localhost:3000
access-token: access_token_mu
token-type: Bearer
client: client_mu
expiry: 1611053732
uid: uid_mu
collection API postman for testing, can be imported with this link:
https://www.getpostman.com/collections/049d7e17cecab86318a9
=Running RSPEC Unit Test
bundle exec rspec -f d spec/models/