Skip to content

AlanSyue/ec-shop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ec-shop

Technical usage

Technical requirements Usage
API Service NestJS
Database MySQL
Test Framework Jest
API document Stoplight
Version Control Git
Hosting Linode
CI/CD GitHub Action

CI/CD

Use GitHub Action

see link

Requirement

docker and docker-compose: https://www.docker.com/products/docker-d

Getting Started

  1. Set up the container
$ cp docker/.env.example docker/.env
$ docker-compose -f ./docker/docker-compose.yml --env-file ./docker/.env up -d
  1. Run database migrations
$ cp app/.env.example app/.env
$ cd docker/
$ docker compose exec app sh
$ yarn migration:run
  1. Start the API server
$ yarn start:dev

API document

see Stoplight

How to use API document

Choose the API

test

API information

截圖 2022-08-07 上午8 09 29

Test the API after you start the server

test

Sequence

  1. Sign up the account
curl --request POST \
  --url https://ec.newideas.com.tw/auth/signup \
  --header 'Content-Type: application/json' \
  --data '{
  "email": "b123105@gmail.com",
  "password": "123456"
}'

singup

  1. Login and get the access token
curl --request POST \
  --url https://ec.newideas.com.tw/auth/login \
  --header 'Content-Type: application/json' \
  --data '{
  "email": "b123105@gmail.com",
  "password": "123456"
}'

login

  1. See your profile
curl --request GET \
  --url https://ec.newideas.com.tw/user/profile \
  --header 'Authorization: Bearer ${your access token}' \
  --header 'Content-Type: application/json'

profile

  1. See all products in the shop
curl --request GET \
  --url https://ec.newideas.com.tw/product \
  --header 'Content-Type: application/json'

Product

  1. Add the product to shopping cart
curl --request POST \
  --url https://ec.newideas.com.tw/cart/1 \
  --header 'Authorization: Bearer ${your access token}' \
  --header 'Content-Type: application/json' \
  --data '{
  "amount": 1
}'

AddToCart

  1. See your shopping cart
curl --request GET \
  --url https://ec.newideas.com.tw/cart \
  --header 'Authorization: Bearer ${your access token}' \
  --header 'Content-Type: application/json'

Find Cart

  1. Checkout
curl --request POST \
  --url https://ec.newideas.com.tw/cart/checkout \
  --header 'Authorization: Bearer ${your access token}' \
  --header 'Content-Type: application/json'

checkout

  1. See your orders
curl --request GET \
  --url https://ec.newideas.com.tw/order \
  --header 'Authorization: Bearer ${your access token}' \
  --header 'Content-Type: application/json'

orders

Automated test

Run unit test

$ cd docker
$ docker compose exec app sh
$ yarn test

See coverage

$ cd docker
$ docker compose exec app sh
$ yarn test:cov

--------------------------------|---------|----------|---------|---------|-------------------

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 66.66 90.47 55.85 68.06
src 39.39 100 75 33.33
app.controller.ts 100 100 100 100
app.module.ts 0 100 100 0 1-26
app.service.ts 100 100 100 100
main.ts 0 100 0 0 1-15
src/auth 0 100 100 0
auth.module.ts 0 100 100 0 1-26
constants.ts 0 100 100 0 1-3
src/auth/applications 100 100 100 100
auth.controller.ts 100 100 100 100
src/auth/dtos 71.42 100 0 71.42
auth-dto.ts 71.42 100 0 71.42 22-26
src/auth/errors 100 100 100 100
email-exist-error.ts 100 100 100 100
src/auth/services 100 100 100 100
auth.service.ts 100 100 100 100
src/auth/strategies 27.77 0 0 21.42
jwt-auth.guard.ts 100 100 100 100
jwt.strategy.ts 0 100 0 0 1-17
local-auth.guard.ts 100 100 100 100
local.strategy.ts 0 0 0 0 1-24
src/cart 0 100 100 0
cart.module.ts 0 100 100 0 1-16
src/cart/aggregates 100 100 100 100
cart-aggregate.ts 100 100 100 100
src/cart/applications 87.87 100 100 87.09
cart.controller.ts 87.87 100 100 87.09 34,48,63,78
src/cart/dtos 100 100 100 100
cart-dto.ts 100 100 100 100
src/cart/errors 88.88 66.66 50 88.88
product-out-of-stock-error.ts 88.88 66.66 50 88.88 19
src/cart/services 81.81 100 90 81.13
cart.service.ts 81.81 100 90 81.13 100,125-154
src/entities 69.09 100 2.85 75
cart.entity.ts 68 100 0 75 23,28,33,36,39
order-item.entity.ts 71.42 100 0 76.47 22,27,32,35
order.entity.ts 66.66 100 0 73.68 26,31,36,39,42
product.entity.ts 71.42 100 14.28 76.47 19,24,29,32
user.entity.ts 68.42 100 0 73.33 16,21,26,29
src/migrations 0 100 0 0
1659825406414-migrations.ts 0 100 0 0 3-31
1659826861827-migrations.ts 0 100 0 0 3-7
src/order 0 100 100 0
order.module.ts 0 100 100 0 1-13
src/order/aggregates 100 100 100 100
order-aggregate.ts 100 100 100 100
src/order/applications 91.66 100 100 90.9
order.controller.ts 91.66 100 100 90.9 25,47
src/order/errors 100 100 100 100
invalid-order-error.ts 100 100 100 100
src/order/services 100 100 100 100
order.service.ts 100 100 100 100
src/product 0 100 100 0
product.module.ts 0 100 100 0 1-12
src/product/applications 91.3 100 100 90.47
product.controller.ts 91.3 100 100 90.47 32,54
src/product/dtos 100 100 100 100
product-query-dto.ts 100 100 100 100
src/product/errors 100 100 100 100
product-not-found-error.ts 100 100 100 100
src/product/services 100 100 100 100
product.service.ts 100 100 100 100
src/user 0 100 100 0
user.module.ts 0 100 100 0 1-13
src/user/applications 100 100 100 100
user.controller.ts 100 100 100 100
-------------------------------- --------- ---------- --------- --------- -------------------

About

E-commerce API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages