Skip to content

rodpedrassi/blacksmithing

Repository files navigation

Medieval Store API


Descrição 📜

This is a medieval store API where you can create and read unique items for sale, create and read orders, register and login users.

Built with:


Features 📋

  • Create and read unique items
  • Create and read orders
  • Register and login users
  • Authentication with JWT

Installation 🛠

Installation with Docker 🐳
  1. Clone the repository
git clone [email protected]:lucasdximenes/medieval-store-api.git
  1. Enter the project folder
cd medieval-store-api
  1. You need to have Docker and Docker Compose installed on your machine. If you don't have it, you can download it here and here.

  2. Run the following command to start the containers

docker-compose up -d
  1. Connect to container
docker exec -it trybesmith
  1. Install dependencies and initialize API

In terminal of container

npm install && npm start
  1. The API will be running on port 3000. You can access it by going to http://localhost:3000
Installation without Docker 🌊
  1. Clone the repository
git clone [email protected]:lucasdximenes/medieval-store-api.git
  1. Enter the project folder
cd medieval-store-api
  1. Install the dependencies
npm install
  1. You need to have MySQL installed on your machine. If you don't have it, you can download it here.

  2. Create an .env file in the root of the project and add the following environment variables

MYSQL_USER=YOUR_MYSQL_USER
MYSQL_PASSWORD=YOUR_MYSQL_PASSWORD
MYSQL_HOST=YOUR_MYSQL_HOST
JWT_SECRET=YOUR_JWT_SECRET
  1. Run the migration script in a database manager like DBeaver

migration

  1. Initialize the API
npm start
  1. The API will be running on port 3000. You can access it by going to http://localhost:3000

Documentation 📚

Login route

POST:

  • /login: - Login user

    • Request:

      • {
          "username": "username",
          "password": "password"
        }
    • Response:

      • {
          "token": "token"
        }

Order routes

GET

  • /orders - Get all orders
    • Response:
      • [
          {
            "id": 1,
            "userId": 1,
            "productsIds": [1]
          }
        ]

POST

  • /orders - Create an order

    • Request:

      • Headers:
        • Authorization: Token
      • Body:
        • {
            "userId": 1,
            "productsIds": [1]
          }
    • Response:

      • Body:
        • {
            "userId": 1,
            "productsIds": [1]
          }

Product routes

GET

  • /products - get all products
    • Response:
      • [
          {
            "id": 1,
            "name": "Espada curta",
            "amount": "10 peças de ouro",
            "orderId": 4
          }
        ]

POST

  • /products - Create an product

    • Request:

      • Body:
        • {
            "name": "product name",
            "amount": "product value"
          }
    • Response:

      • Body:

        • {
            "id": 10,
            "name": "product name",
            "amount": "product value"
          }

User routes

POST

  • /users - Register an user

    • Request:

      • Body:
        • {
            "username": "username",
            "vocation": "vocation",
            "level": 999,
            "password": "password"
          }
    • Response:

      • Body:
        • {
            "token": "token"
          }

credits for readme: Lucas Ximenes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published