Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entrega Semana 7 - williancbertini #36

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.1</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>br.com.alura</groupId>
<artifactId>comex</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand All @@ -36,10 +33,27 @@
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.7.1</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.27.Final</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
</dependencies>

</project>
11 changes: 11 additions & 0 deletions src/main/java/br/com/alura/comex/ComexApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package br.com.alura.comex;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ComexApplication {
public static void main(String[] args) {
SpringApplication.run(ComexApplication.class, args);
}
}
13 changes: 13 additions & 0 deletions src/main/java/br/com/alura/comex/JPAUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package br.com.alura.comex;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

public class JPAUtil {

public static EntityManager getEntityManager() {
return Persistence
.createEntityManagerFactory("mysql")
.createEntityManager();
}
}
4 changes: 3 additions & 1 deletion src/main/java/br/com/alura/comex/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);

public static void main(String[] args) throws IOException, URISyntaxException {
Pedido[] pedidos = ProcessadorDeCsv.processaArquivo("pedidos.csv");
/* Pedido[] pedidos = ProcessadorDeCsv.processaArquivo("pedidos.csv");

int totalDeProdutosVendidos = 0;
int totalDePedidosRealizados = 0;
Expand Down Expand Up @@ -77,5 +77,7 @@ public static void main(String[] args) throws IOException, URISyntaxException {
logger.info("PEDIDO MAIS BARATO: {} ({})", NumberFormat.getCurrencyInstance(new Locale("pt", "BR")).format(pedidoMaisBarato.getPreco().multiply(new BigDecimal(pedidoMaisBarato.getQuantidade())).setScale(2, RoundingMode.HALF_DOWN)), pedidoMaisBarato.getProduto());
logger.info("PEDIDO MAIS CARO: {} ({})\n", NumberFormat.getCurrencyInstance(new Locale("pt", "BR")).format(pedidoMaisCaro.getPreco().multiply(new BigDecimal(pedidoMaisCaro.getQuantidade())).setScale(2, RoundingMode.HALF_DOWN)), pedidoMaisCaro.getProduto());
logger.info("### FIM DO RELATÓRIO ###");

*/
}
}
62 changes: 0 additions & 62 deletions src/main/java/br/com/alura/comex/Pedido.java

This file was deleted.

7 changes: 4 additions & 3 deletions src/main/java/br/com/alura/comex/ProcessadorDeCsv.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class ProcessadorDeCsv {

public static Pedido[] processaArquivo(String nomeDoArquivo) {
/* public static Pedido[] processaArquivo(String nomeDoArquivo) {
try {
URL recursoCSV = ClassLoader.getSystemResource(nomeDoArquivo);
Path caminhoDoArquivo = caminhoDoArquivo = Path.of(recursoCSV.toURI());
Expand Down Expand Up @@ -50,5 +50,6 @@ public static Pedido[] processaArquivo(String nomeDoArquivo) {
} catch (IOException e) {
throw new RuntimeException("Erro ao abrir Scanner para processar arquivo!");
}
}
}
} */
}

15 changes: 15 additions & 0 deletions src/main/java/br/com/alura/comex/TestaCategoria.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package br.com.alura.comex;

import br.com.alura.comex.dao.CategoriaDao;
import br.com.alura.comex.model.Categoria;
import br.com.alura.comex.model.StatusCategoriaEnum;

public class TestaCategoria {

public static void main(String[] args) {

Categoria novaCategoria = new Categoria("Esporte", StatusCategoriaEnum.ATIVO);
CategoriaDao categoriaDao = new CategoriaDao();
categoriaDao.cadastra(novaCategoria);
}
}
26 changes: 26 additions & 0 deletions src/main/java/br/com/alura/comex/TestaJpaPedido.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package br.com.alura.comex;

import br.com.alura.comex.dao.CategoriaDao;
import br.com.alura.comex.dao.ClienteDao;
import br.com.alura.comex.dao.PedidoDao;
import br.com.alura.comex.dao.ProdutoDao;
import br.com.alura.comex.model.*;

import java.math.BigDecimal;
import java.time.LocalDate;

public class TestaJpaPedido {
public static void main(String[] args) {

ClienteDao clienteDao = new ClienteDao();
Cliente cliente = clienteDao.buscaPorId(2L);

Pedido novoPedido = new Pedido(LocalDate.now(),cliente, new BigDecimal(140.80),
TipoDescontoPedidoEnum.FIDELIDADE);

PedidoDao pedidoDao = new PedidoDao();
pedidoDao.cadastra(novoPedido);


}
}
23 changes: 23 additions & 0 deletions src/main/java/br/com/alura/comex/TestaJpaProduto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package br.com.alura.comex;

import br.com.alura.comex.dao.CategoriaDao;
import br.com.alura.comex.dao.ProdutoDao;
import br.com.alura.comex.model.Categoria;
import br.com.alura.comex.model.Produto;

import javax.persistence.EntityManager;
import java.math.BigDecimal;

public class TestaJpaProduto {
public static void main(String[] args) {

Categoria categoriaDoBanco = new CategoriaDao().buscaPorId(1L);

Produto celular = new Produto("Samsung S21","Android 512GB",
new BigDecimal("940.58"), 2, categoriaDoBanco);

ProdutoDao produtoDao = new ProdutoDao();
produtoDao.cadastra(celular);

}
}
26 changes: 26 additions & 0 deletions src/main/java/br/com/alura/comex/TestaPedido.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package br.com.alura.comex;

import br.com.alura.comex.model.Cliente;
import br.com.alura.comex.model.Endereco;
import br.com.alura.comex.model.Pedido;

import java.math.BigDecimal;

public class TestaPedido {
public static void main(String[] args) {
Cliente clienteUm = new Cliente();
clienteUm.setNome("Fulano da Silva");
clienteUm.setCpf("357.852.014-77");
clienteUm.setEmail("[email protected]");
clienteUm.setProfissao("Assistente Administrativo");
clienteUm.setTelefone("(11)99852-4141");
Endereco enderecoClienteUm = new Endereco("Alto","São Paulo","Apto 12","SP","Silva Jardim", "112");
clienteUm.setEndereco(enderecoClienteUm);

// Pedido pedido = new Pedido(clienteUm,new BigDecimal("2500.0"), 42L);
// System.out.println(pedido);

// BigDecimal valorTotal = pedido.getValorTotal();
//System.out.println(valorTotal);
}
}
20 changes: 20 additions & 0 deletions src/main/java/br/com/alura/comex/TesteCliente.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package br.com.alura.comex;

import br.com.alura.comex.model.Cliente;
import br.com.alura.comex.model.Endereco;

public class TesteCliente {

public static void main(String[] args) {
Cliente clienteUm = new Cliente();
clienteUm.setNome("Fulano da Silva");
clienteUm.setCpf("357.852.014-77");
clienteUm.setEmail("[email protected]");
clienteUm.setProfissao("Assistente Administrativo");
clienteUm.setTelefone("(11)99852-4141");
Endereco enderecoClienteUm = new Endereco("Alto","São Paulo","Apto 12","SP","Silva Jardim", "112");
clienteUm.setEndereco(enderecoClienteUm);

System.out.println(clienteUm);
}
}
88 changes: 88 additions & 0 deletions src/main/java/br/com/alura/comex/TesteJpaComHibernate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package br.com.alura.comex;

import br.com.alura.comex.dao.ClienteDao;
import br.com.alura.comex.model.Cliente;
import br.com.alura.comex.model.Endereco;


public class TesteJpaComHibernate {

public static void main(String[] args) {

/* Cria o cliente Willian - ID 1
Cliente novoCliente = new Cliente("Willian","88777885445","[email protected]","Desenvolvedor",
"(16)99999999",
new Endereco("Rua XXX","855","Bairro AAA", "Apto 98","Piracicaba",
"SP"));

ClienteDao clienteDao = new ClienteDao();
clienteDao.cadastra(novoCliente);

*/

/* Cria o cliente Cristiano - ID 2
Cliente novoCliente = new Cliente("Cristiano","74258741255","[email protected]","Programador",
"(16)99999999",
new Endereco("Rua ZZZ","855","Bairro BBB", "Casa 02","Piracicaba",
"SP"));
ClienteDao clienteDao = new ClienteDao();
clienteDao.cadastra(novoCliente);
*/

/*
// Cria o cliente Silvia - ID 3
Cliente novoCliente = new Cliente("Silvia","56776543222","[email protected]","Programador",
"(16)545487877",
new Endereco("Rua WWW","567","Bairro BBB", "Casa 2","Piracicaba",
"SP"));
ClienteDao clienteDao = new ClienteDao();
clienteDao.cadastra(novoCliente);
System.out.println(novoCliente);
*/

//Teste da Busca pelo ID
/*
ClienteDao clienteDao = new ClienteDao();
Cliente cliente = clienteDao.buscaPorId(2L);
System.out.println(cliente);
*/

//Teste da Busca pelo listaTodos()
/*

List<Cliente> clientes = clienteDao.listaTodos();
for (Cliente cliente : clientes) {
System.out.println(cliente);
}
*/

//Teste da Busca listaPorNome()
/*
List<Cliente> clientes = clienteDao.listaPorNome("Cristiano");
for (Cliente cliente : clientes) {
System.out.println(cliente);
}
*/

/*
//Teste do método atualiza (Cliente cliente)
//primeiro é necessário encontrar o cliente pelo ID (por exemplo)
ClienteDao clienteDao = new ClienteDao();
Cliente cliente = clienteDao.buscaPorId(2L);
//Após isso, atualizar o que for necessário:
cliente.setEmail("[email protected]");
cliente.getEndereco().setCidade("Campinas"); //atualização da cidade no endereço
clienteDao.atualiza(cliente);
System.out.println("Cliente atualizado: " + cliente);
*/

//Teste do método remove(Cliente cliente)
ClienteDao clienteDao = new ClienteDao();
//primeiro é necessário encontrar o cliente pelo ID (por exemplo)
Cliente cliente = clienteDao.buscaPorId(3L);

clienteDao.remove(cliente);
System.out.println("Cliente ID " + cliente.getId() + " removido");
}

}
Loading