This is a Ruby on Rails E-Commerce application with features for managing products, orders, users, and payments. It uses JWT for user authentication and has API endpoints for performing CRUD operations on products and purchasing products. Products are organized into categories and there is an active admin console for managing orders, products, categories, and users.
Create an E-Commerce application with the option to manage products, orders, users, and payments.
- Use JWT for user authentication
- Create API endpoints to perform CRUD operations on products
- Create endpoints to purchase a product
- Products need to be divided into categories
- Setup an active admin console for performing CRUD operations on orders, products, categories, and users
- Use RSpec for writing unit tests
Clone this repository:
git clone https://github.com/Don-PhDev/aglipay-swe-jwt.git
Install the required gems:
bundle install
Create the database and run the migrations:
rails db:create
rails db:migrate
Seed the database with initial data:
rails db:seed
Start the server:
rails server
To run tests, run the following command:
rspec
To register a new user, send a POST
request to /api/v1/users
with the following parameters:
email
password
password_confirmation
Using Postman or your favourite software testing API platform
{
"user": {
"email": "example@example.com",
"password": "password",
"password_confirmation": "password"
}
}
or you can use cURL command like this:
curl -H "Content-Type: application/json" -X POST -d '{"user": {"email": "[email protected]", "password": "password", "password_confirmation": "password"}}' http://localhost:3000/users
To log in a user, send a POST
request to /api/v1/login
with the following parameters:
email
password
{
"user": {
"email": "example@example.com",
"password": "password"
}
}
curl -i -H "Content-Type: application/json" -X POST -d '{"user": {"email": "[email protected]", "password": "password"}}' http://localhost:3000/users/sign_in
This will return a JWT token that should be included in the headers of subsequent requests.
To log out a user, send a DELETE
request to /api/v1/logout
.
curl -H "Content-Type: application/json" -X DELETE -d '' -H 'Authorization: <AUTH_TOKEN>' http://localhost:3000/users/sign_out
Note: Replace <AUTH_TOKEN>
with the user's authentication token.
To check if a user is logged in, send a GET
request to /users/member-data
with the user's authentication token in the Authorization header:
curl -H "Content-Type: application/json" -H 'Authorization: <AUTH_TOKEN>' http://localhost:3000/users/member-data
Note: Replace <AUTH_TOKEN>
with the user's authentication token.
Send a POST
request to /api/v1/products
with the following parameters:
name
price
category_id
Include the JWT token in the headers of the request.
Send a PUT
request to /api/v1/products/:id
with the following parameters:
name
price
category_id
Include the JWT token in the headers of the request.
Send a DELETE
request to /api/v1/products/:id
.
Include the JWT token in the headers of the request.
Send a POST
request to /api/v1/orders
with the following parameters:
product_id
quantity
Include the JWT token in the headers of the request.
To access the admin console, go to /admin
.
This Ruby on Rails E-commerce application is available as open source under the terms of the MIT License.