/delivery-back-end-app

This back-end application consumes a Postgres database with the goal to provide data to a delivery pizza app.

Primary LanguageJava

Delivery back-end app

The goal of this project is to review some main concepts of the object oriented programming using Java language. Here, some products and orders are recovered from the database and processed in order to be sent to a front-end application. Considering the goal of reviewing OOP Concepts, ORM tools were not used.

Some of the these concepts reviewed are:

  • Classes and objects

  • Encapsulation and usage of get and set

  • Enumerations types

  • Colections (List and Map)

  • Access to a relational database and instantiation of the corresponding objects

    The project was developed based on the Youtube class "Super revisão de OO e SQL - DevSuperior Nelio Alves" from the Brazilian tech channel DevSuperior

Technologies

  • Java
  • Postgres
  • pgAdmin
  • JDBC

Creating and instantiating the database

create table tb_order (
    id int8 generated by default as identity, 
    latitude float8, 
    longitude float8, 
    moment TIMESTAMP WITHOUT TIME ZONE, 
    status int4, 
    primary key (id)
);

create table tb_order_product (
    order_id int8 not null, 
    product_id int8 not null, 
    primary key (order_id, product_id)
);

create table tb_product (
    id int8 generated by default as identity, 
    description TEXT, 
    image_uri varchar(255), 
    name varchar(255), 
    price float8, 
    primary key (id)
);

alter table if exists tb_order_product add constraint fk_tb_order_product_tb_product 
foreign key (product_id) references tb_product;

alter table if exists tb_order_product add constraint fk_tb_order_product_tb_order 
foreign key (order_id) references tb_order;

INSERT INTO tb_product (name, price, image_Uri, description) VALUES 
('Pizza de Calabresa', 50.0, 'https://github.com/devsuperior/1.png', 'Pizza calabresa com queijo, molho e massa especial'),
('Pizza Quatro Queijos', 40.0, 'https://github.com/devsuperior/2.png', 'Pizza quatro queijos muito boa'),
('Pizza de Escarola', 60.0, 'https://github.com/devsuperior/3.png', 'Pizza escarola muito boa');

INSERT INTO tb_order (status, latitude, longitude, moment) VALUES 
(0, 213123, 12323, TIMESTAMP WITH TIME ZONE '2021-01-04T11:00:00Z'),
(1, 3453453, 3534534, TIMESTAMP WITH TIME ZONE '2021-01-05T11:00:00Z');

INSERT INTO tb_order_product (order_id, product_id) VALUES 
(1 , 1),
(1 , 2),
(2 , 2),
(2 , 3);

Recovering order with products

SELECT * FROM tb_order
INNER JOIN tb_order_product ON tb_order.id = tb_order_product.order_id
INNER JOIN tb_product ON tb_product.id = tb_order_product.product_id

Start and stop Postgres manually

$ pg_ctl -D /usr/local/var/postgres start
$ pg_ctl -D /usr/local/var/postgres stop