Skip to content

Commit

Permalink
Merge pull request #11 from GEdO23/dev
Browse files Browse the repository at this point in the history
Usuario (1)
  • Loading branch information
Gabriel Eringer authored Oct 1, 2024
2 parents 706451e + dc0f5ea commit 482062e
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 88 deletions.
3 changes: 1 addition & 2 deletions src/main/java/br/com/cpsb/CpsbApiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
@SpringBootApplication
public class CpsbApiApplication {

//TODO: Criar model, repository e controller de Usuário
//TODO: Criar controller de Usuário
//TODO: Cadastro e Login de Usuário
//TODO: CRUD de Usuário
//TODO: Testes com Selenium e Cucumber
//TODO: Utilizar fragmentos
//TODO: Internacionalização (pt-br, en)
//TODO: Segurança
//TODO: Serviço
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/br/com/cpsb/controller/UsuarioController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package br.com.cpsb.controller;

import br.com.cpsb.model.Usuario;
import br.com.cpsb.repository.UsuarioRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Optional;

@Controller
public class UsuarioController {

@Autowired
private UsuarioRepository usuarioRepository;

@GetMapping("/login")
public ModelAndView login() {
ModelAndView mv = new ModelAndView("formulario_login_usuario");

mv.addObject("usuario", new Usuario());

return mv;
}

@PostMapping("/login")
public ModelAndView logar(Usuario usuario) {

Optional<Usuario> usuarioEncontrado = usuarioRepository.findAll().stream().filter(u ->
u.getNome().equals(usuario.getNome())
).findFirst();

if (usuarioEncontrado.isPresent()) {
return new ModelAndView("redirect:/");
} else {
ModelAndView mv = new ModelAndView("/formulario_login_usuario");
mv.addObject("usuario", new Usuario());
return mv;
}
}

}
25 changes: 25 additions & 0 deletions src/main/java/br/com/cpsb/model/Usuario.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package br.com.cpsb.model;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "TB_CPSB_USUARIO")
public class Usuario {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_usuario")
private Long id;

@Column(name = "nm_usuario")
private String nome;

}
7 changes: 7 additions & 0 deletions src/main/java/br/com/cpsb/repository/UsuarioRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package br.com.cpsb.repository;

import br.com.cpsb.model.Usuario;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UsuarioRepository extends JpaRepository<Usuario, Long> {
}
4 changes: 3 additions & 1 deletion src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ INSERT INTO TB_CPSB_RACA (nm_raca, ds_raca) VALUES ( 'Poodle', 'Fisicamente, o t
INSERT INTO TB_CPSB_PET (nm_pet, id_raca) VALUES ('Brendan', 1);
INSERT INTO TB_CPSB_PET (nm_pet, id_raca) VALUES ('Rex', 4);
INSERT INTO TB_CPSB_PET (nm_pet, id_raca) VALUES ('Toby', 3);
INSERT INTO TB_CPSB_PET (nm_pet, id_raca) VALUES ('Spike', 2);
INSERT INTO TB_CPSB_PET (nm_pet, id_raca) VALUES ('Spike', 2);

INSERT INTO TB_CPSB_USUARIO (nm_usuario) VALUES ( 'Gabriel' )
10 changes: 1 addition & 9 deletions src/main/resources/templates/detalhes_pet.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Detalhes de pet</title>
</head>
<head th:replace="~{fragmentos :: cabecalho('Detalhes de Pet')}"></head>
<body>

<div class="container mt-5">
Expand Down
10 changes: 1 addition & 9 deletions src/main/resources/templates/detalhes_raca.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Detalhes da raça</title>
</head>
<head th:replace="~{fragmentos :: cabecalho('Detalhes de Raça')}"></head>
<body>

<div class="container mt-5">
Expand Down
11 changes: 1 addition & 10 deletions src/main/resources/templates/error.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">


<title>Erro encontrado</title>
</head>
<head th:replace="~{fragmentos :: cabecalho('Erro')}"></head>
<body>

<div class="container mt-5">
Expand Down
10 changes: 1 addition & 9 deletions src/main/resources/templates/formulario_atualizar_pet.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Editar Pet</title>
</head>
<head th:replace="~{fragmentos :: cabecalho('Atualizar Pet')}"></head>
<body>

<div class="container mt-5">
Expand Down
10 changes: 1 addition & 9 deletions src/main/resources/templates/formulario_cadastrar_pet.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Cadastrar Pet</title>
</head>
<head th:replace="~{fragmentos :: cabecalho('Cadastrar Pet')}"></head>
<body>
<div class="container mt-5">
<div class="row">
Expand Down
10 changes: 1 addition & 9 deletions src/main/resources/templates/formulario_cadastrar_raca.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Cadastrar Raça</title>
</head>
<head th:replace="~{fragmentos :: cabecalho('Cadastrar Raça')}"></head>
<body>
<div class="container mt-5">
<div class="row">
Expand Down
35 changes: 35 additions & 0 deletions src/main/resources/templates/formulario_login_usuario.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{fragmentos :: cabecalho('Login')}"></head>
<body>

<div class="container mt-5">
<div class="row">
<h1>Cutcute Petshop</h1>
</div>

<div class="row">
<h2>Login</h2>
</div>

<div class="row">
<form th:action="@{/login}" method="post" th:object="${usuario}">

<div class="form-group">
<label for="nome">Nome</label>
<input class="form-control" type="text" id="nome" th:field="*{nome}">
</div>

<button class="btn btn-primary mt-4" type="submit">Entrar</button>

</form>
</div>

</div>

<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"
crossorigin="anonymous"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions src/main/resources/templates/fragmentos.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<head th:fragment="cabecalho(parametro)">

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1"
crossorigin="anonymous">

<title th:text="${parametro}">AQUI!</title>

</head>
16 changes: 4 additions & 12 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Home</title>
</head>
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml">
<head th:replace="~{fragmentos :: cabecalho('Home')}"></head>
<body>

<div class="container">
<div class="row mt-5">
<h1>Home</h1>
</div>

<div class="row gap-2">
<div class="row">
<div class="col-auto">
<a href="/lista_racas">Lista de Raças</a>
</div>

<div class="col-auto">
<a href="/lista_pets">Lista de Pets</a>
</div>
Expand Down
10 changes: 1 addition & 9 deletions src/main/resources/templates/lista_pets.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Lista de Pets</title>
</head>
<head th:replace="~{fragmentos :: cabecalho('Lista de Pets')}"></head>
<body>

<div class="container">
Expand Down
10 changes: 1 addition & 9 deletions src/main/resources/templates/lista_racas.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="pt-br" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<title>Lista de Raças</title>
</head>
<head th:replace="~{fragmentos :: cabecalho('Lista de Raças')}"></head>
<body>

<div class="container">
Expand Down

0 comments on commit 482062e

Please sign in to comment.