Skip to content

nicolasperussi/script-burger-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Script Burger 🍔

TechnologiesGetting StartedAPI EndpointsContribute

This is a simple API created for a fictitious food company specialized only in delivery.

💻 Technologies

  • Java
  • Spring
  • H2 Database

🚀 Getting started

Prerequisites

These are the requirements you will need to run the project:

Cloning

git clone https://github.com/nicolasperussi/script-burger-server.git

Config .env variables

Use the .env.example as reference to create your configuration file .env with your JWT secret key.

JWT_SECRET=

Starting

You may open the project using your IDE of choice and run it normally, or you can follow the steps below to run it directly from the terminal.

Make sure you have JAVA_HOME set up correctly in your system's Environment Variables.

cd script-burger-server
./mvnw spring-boot:run

📍 API Endpoints

These are the available endpoints in this API: ​

User

route description
POST /auth/register registers a new user - see details
POST /auth/login authenticate a user - see details

POST /auth/register

REQUEST

{
  "name": "John Doe",
  "email": "[email protected]",
  "password": "test1234",
  "phone": "999999999"
}

POST /auth/login

REQUEST

{
  "email": "[email protected]",
  "password": "test1234"
}

RESPONSE

{
  // This is a JWT token signed with the
  // secret you provided on the .env file
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzY3JpcHRidXJnZXItYXBpIiwic3ViIjoiYWRtaW5AYWRtaW4uY29tIiwiZXhwIjoxNzA1NzEyNTI2fQ.BhBb3FiDnd3eF2L4purdjAN9WIk4zBC-Tommg5fz2xg",
  "user": {
    "id": 1,
    "name": "John Doe",
    "email": "[email protected]",
    "phone": "999999999",
    "role": "CLIENT",
    "address": [{ "cep": "01001-000", "street": "Praça da Sé", "number": "0" }],
    "username": "[email protected]"
  }
}

Products

route description
GET /products fetch all products - see details
GET /products/:id fetch product by id - see details
POST /products create new product - see details

GET /products

RESPONSE

[
  {
    "id": 1,
    "name": "JavaScript Burger",
    "description": "O JavaScript Burger é feito com 100% de carne bovina, alface crocante, tomate fresco, cebola suavemente temperada, picles em conserva e queijo derretido. É uma combinação deliciosa e suculenta, perfeita para satisfazer o seu desejo por hambúrguer. ",
    "slug": "javascript-burger",
    "overview": "Hambúrguer favorito de todos os tempos",
    "price": 20.99,
    "category": "SANDWICH"
  }
  // and all the other products
]

GET /products/7

{
  "id": 7,
  "name": "PHP Bacon Cheeseburger",
  "description": "O PHP Bacon Cheeseburger é feito com 100% de carne bovina, queijo cheddar cremoso e delicioso bacon crocante. Este hambúrguer clássico é perfeito para quem adora um sabor defumado e suculento.",
  "slug": "php-bacon-cheeseburger",
  "overview": "Hambúrguer clássico com bacon",
  "price": 23.99,
  "category": "SANDWICH"
}

POST /products

REQUEST

This is a multipart/form-data request. These are the parameters:

name: string;
description: string;
overview: string;
price: number;
category: SANDWICH | SIDE | DESSERT | DRINK;
image: file;

Orders

route description
GET /orders fetch all orders - see details
GET /orders/user/:id fetch product by client id - see details
POST /orders place new order - see details
PATCH /orders/:id advance order to next step - see details
PATCH /orders/cancel/:id cancel order - see details

GET /orders

RESPONSE

Click here to show
[
  {
    "id": 1,
    "moment": "2024-01-19T03:22:18Z",
    "status": "WAITING",
    "client": {
      "id": 1,
      "name": "John Doe",
      "email": "[email protected]",
      "phone": "999999999",
      "role": "CLIENT",
      "address": [
        { "cep": "01001-000", "street": "Praça da Sé", "number": "0" }
      ],
      "username": "[email protected]"
    },
    "items": [
      {
        "quantity": 2,
        "totalPrice": 22.99,
        "product": {
          "id": 2,
          "name": "Python Burger",
          "description": "O Python Burger é feito com 100% de carne bovina, queijo cheddar derretido, cebolas crocantes e molho BBQ com sabor agridoce. Essa combinação de sabores é uma verdadeira explosão para o paladar. ",
          "slug": "python-burger",
          "overview": "Explosão de sabor agridoce de churrasco",
          "price": 22.99,
          "category": "SANDWICH"
        }
      }
    ],
    "totalPrice": 45.98
  }
  // and other orders
]

GET /orders/user/1

RESPONSE

Click here to show
[
  {
    "id": 1,
    "moment": "2024-01-19T03:22:18Z",
    "status": "WAITING",
    "items": [
      {
        "quantity": 2,
        "totalPrice": 22.99,
        "product": {
          "id": 2,
          "name": "Python Burger",
          "description": "O Python Burger é feito com 100% de carne bovina, queijo cheddar derretido, cebolas crocantes e molho BBQ com sabor agridoce. Essa combinação de sabores é uma verdadeira explosão para o paladar. ",
          "slug": "python-burger",
          "overview": "Explosão de sabor agridoce de churrasco",
          "price": 22.99,
          "category": "SANDWICH"
        }
      }
    ],
    "totalPrice": 45.98
  }
  // and other orders
]

POST /orders

REQUEST

{
  "userId": 1,
  "items": [
    {
      "productId": 7,
      "quantity": 1
    },
    {
      "productId": 2,
      "quantity": 1
    },
    {
      "productId": 24,
      "quantity": 2
    }
  ]
}

PATCH /orders/1

RESPONSE

Click here to show
{
  "id": 1,
  "moment": "2024-01-19T03:22:18Z",
  "status": "IN_PRODUCTION", // this will be update to next step
  "client": {
    "id": 1,
    "name": "John Doe",
    "email": "[email protected]",
    "phone": "999999999",
    "role": "CLIENT",
    "address": [{ "cep": "01001-000", "street": "Praça da Sé", "number": "0" }],
    "username": "[email protected]"
  },
  "items": [
    {
      "quantity": 2,
      "totalPrice": 22.99,
      "product": {
        "id": 2,
        "name": "Python Burger",
        "description": "O Python Burger é feito com 100% de carne bovina, queijo cheddar derretido, cebolas crocantes e molho BBQ com sabor agridoce. Essa combinação de sabores é uma verdadeira explosão para o paladar. ",
        "slug": "python-burger",
        "overview": "Explosão de sabor agridoce de churrasco",
        "price": 22.99,
        "category": "SANDWICH"
      }
    }
  ],
  "totalPrice": 45.98
}

PATCH /orders/cancel/1

RESPONSE

Click here to show
{
  "id": 1,
  "moment": "2024-01-19T03:22:18Z",
  "status": "CANCELED", // this will be changed to CANCELED
  "client": {
    "id": 1,
    "name": "John Doe",
    "email": "[email protected]",
    "phone": "999999999",
    "role": "CLIENT",
    "address": [{ "cep": "01001-000", "street": "Praça da Sé", "number": "0" }],
    "username": "[email protected]"
  },
  "items": [
    {
      "quantity": 2,
      "totalPrice": 22.99,
      "product": {
        "id": 2,
        "name": "Python Burger",
        "description": "O Python Burger é feito com 100% de carne bovina, queijo cheddar derretido, cebolas crocantes e molho BBQ com sabor agridoce. Essa combinação de sabores é uma verdadeira explosão para o paladar. ",
        "slug": "python-burger",
        "overview": "Explosão de sabor agridoce de churrasco",
        "price": 22.99,
        "category": "SANDWICH"
      }
    }
  ],
  "totalPrice": 45.98
}

📫 Contribute

Would like to contribute? Please do so following these steps:

  1. git clone https://github.com/nicolasperussi/script-burger-server.git
  2. git checkout -b feature/NAME
  3. Follow commit patterns
  4. Open a Pull Request explaining the problem solved or feature made, if exists, append screenshot of visual modifications and wait for the review!

Documentations that might help

📝 How to create a Pull Request

💾 Commit pattern

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages