Ver Fonte

Commodities and layouts

Ranghetti há 6 meses atrás
pai
commit
5934d7cb7e

+ 3 - 2
src/main/java/com/platform2easy/genesis/GenesisApplication.java

@@ -20,8 +20,9 @@ public class GenesisApplication {
     public CommandLineRunner initDataBase(UserRepository user) {
         return args -> {
             user.save(new User2Easy(null, "admin", new BCryptPasswordEncoder().encode("admin"), "Administrador", UserRole.ADMIN));
-            user.save(new User2Easy(null, "compra", new BCryptPasswordEncoder().encode("compra"), "Comprador", UserRole.BUYER_USER));
-            user.save(new User2Easy(null, "venda", new BCryptPasswordEncoder().encode("venda"), "Vendedor", UserRole.SELLER_USER));
+            user.save(new User2Easy(null, "operador", new BCryptPasswordEncoder().encode("1234"), "Operador Escrow", UserRole.ESCROW_USER));
+            user.save(new User2Easy(null, "produtor", new BCryptPasswordEncoder().encode("1234"), "Produtor", UserRole.TRADER_USER));
+            user.save(new User2Easy(null, "corretor", new BCryptPasswordEncoder().encode("1234"), "Corretor", UserRole.BROKER_USER));
         };
     }
 }

+ 5 - 0
src/main/java/com/platform2easy/genesis/domain/enums/TipoCommodity.java

@@ -0,0 +1,5 @@
+package com.platform2easy.genesis.domain.enums;
+
+public enum TipoCommodity {
+    SACA_GRAOS;
+}

+ 1 - 1
src/main/java/com/platform2easy/genesis/domain/enums/UserRole.java

@@ -1,5 +1,5 @@
 package com.platform2easy.genesis.domain.enums;
 
 public enum UserRole {
-    ADMIN, ESCROW_USER, SELLER_USER, BUYER_USER, TRADER_USER;
+    ADMIN, ESCROW_USER, TRADER_USER, BROKER_USER;
 }

+ 45 - 0
src/main/java/com/platform2easy/genesis/domain/model/Commoditiy.java

@@ -0,0 +1,45 @@
+package com.platform2easy.genesis.domain.model;
+
+import com.platform2easy.genesis.domain.enums.TipoCommodity;
+import jakarta.persistence.Entity;
+import jakarta.persistence.EnumType;
+import jakarta.persistence.Enumerated;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+
+@Entity
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode(onlyExplicitlyIncluded = true)
+public class Commoditiy {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @EqualsAndHashCode.Include
+    private Long id;
+
+    @Enumerated(EnumType.STRING)
+    private TipoCommodity tipoCommodity;
+
+    private String descricao;
+    private Integer quantidade;
+    private BigDecimal preco;
+    private LocalDate vencimentoPagamento;
+    private LocalDate dataLimiteEntrega;
+
+    private String cedulaProdutoRural;
+
+
+
+}

+ 7 - 0
src/main/java/com/platform2easy/genesis/domain/repository/CommodityRepository.java

@@ -0,0 +1,7 @@
+package com.platform2easy.genesis.domain.repository;
+
+import com.platform2easy.genesis.domain.model.Commoditiy;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface CommodityRepository extends JpaRepository<Commoditiy, Long> {
+}

+ 34 - 0
src/main/java/com/platform2easy/genesis/domain/service/CommodityService.java

@@ -0,0 +1,34 @@
+package com.platform2easy.genesis.domain.service;
+
+import com.platform2easy.genesis.domain.model.Commoditiy;
+import com.platform2easy.genesis.domain.repository.CommodityRepository;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Service
+@AllArgsConstructor
+public class CommodityService {
+
+    private final CommodityRepository repository;
+
+    @Transactional
+    public void salvar(Commoditiy commoditiy) {
+        repository.save(commoditiy);
+    }
+
+    public List<Commoditiy> listarTodos() {
+        return repository.findAll();
+    }
+
+    public Commoditiy buscarPorId(Long id) {
+        return repository.findById(id).orElseThrow();
+    }
+
+    public void deletarPorId(Long id) {
+        repository.deleteById(id);
+    }
+
+}

+ 1 - 1
src/main/java/com/platform2easy/genesis/security/config/SecurityConfiguration.java

@@ -35,7 +35,7 @@ public class SecurityConfiguration {
                 .authorizeHttpRequests(authorizationRegistry -> authorizationRegistry
                         .requestMatchers("/login", "/images/**", "/css/**").permitAll()
                         .requestMatchers(HttpMethod.POST, "/authentication/login").permitAll()
-                        .requestMatchers("/compra","/compra/**").hasRole(UserRole.ADMIN.toString())
+                        .requestMatchers("/compra", "/compra/**").hasRole(UserRole.ADMIN.toString())
                         .anyRequest().authenticated())
                 .addFilterBefore(authorizationFilter, UsernamePasswordAuthenticationFilter.class)
                 .formLogin(httpSecurityFormLoginConfigurer -> httpSecurityFormLoginConfigurer

+ 54 - 0
src/main/java/com/platform2easy/genesis/web/controller/CommodityController.java

@@ -0,0 +1,54 @@
+package com.platform2easy.genesis.web.controller;
+
+import com.platform2easy.genesis.domain.model.Commoditiy;
+import com.platform2easy.genesis.domain.service.CommodityService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+@RequestMapping("commodity")
+@AllArgsConstructor
+public class CommodityController {
+
+    private final CommodityService service;
+
+    private String abrirFormulario(Commoditiy commoditiy, String titulo, Model model) {
+        model.addAttribute("titulo", titulo);
+        model.addAttribute("commodity", commoditiy);
+        return "commodity/form";
+    }
+
+    @GetMapping()
+    public String iniciar(Commoditiy commoditiy, Model model) {
+        return abrirFormulario(commoditiy, "Cadastrar Commodity", model);
+    }
+
+    @GetMapping("edit/{id}")
+    public String editar(@PathVariable Long id, Model model) {
+        return abrirFormulario(service.buscarPorId(id), "Editar Commodity", model);
+    }
+
+    @PostMapping()
+    public String salvar(Commoditiy commoditiy, Model model) {
+        service.salvar(commoditiy);
+        return "redirect:/commodity/all";
+    }
+
+    @GetMapping("remove/{id}")
+    public String remover(@PathVariable Long id, Model model) {
+        service.deletarPorId(id);
+        return "redirect:/commodity/all";
+    }
+
+    @GetMapping("all")
+    public String listar(Model model) {
+        model.addAttribute("titulo", "Commodities");
+        model.addAttribute("commodities", service.listarTodos());
+        return "commodity/list";
+    }
+}

+ 1 - 1
src/main/resources/templates/Index.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html lang="en" xmlns:th="http://www.thymeleaf.org"
       xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
-      layout:decorate="~{layout}">
+      layout:decorate="~{fragments/layout}">
 <head>
     <meta charset="UTF-8">
     <title>Too Easy</title>

+ 52 - 0
src/main/resources/templates/commodity/form.html

@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org"
+      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
+      layout:decorate="~{fragments/layout}">
+<head>
+    <meta charset="UTF-8">
+    <title>Too Easy</title>
+</head>
+<body>
+<section layout:fragment="main-content">
+    <div class="container p-4 shadow bg-white rounded">
+        <h1 class="mb-4" th:text="${titulo}"></h1>
+        <form>
+            <div class="mb-3">
+                <input hidden="true" name="id" th:value="${commodity.id}" type="text">
+
+                <label class="form-label" for="tipoCommodity">Tipo</label>
+                <select class="form-select" id="tipoCommodity" th:field="${commodity.tipoCommodity}">
+                    <option value="" selected="selected">Selecione...</option>
+                    <option value="SACA_GRAOS">Grãos em sacas de 60kg</option>
+                </select>
+
+                <label class="form-label" for="descricao">Descricao</label>
+                <input class="form-control" id="descricao" name="descricao" th:value="${commodity.descricao}" type="text">
+
+                <label class="form-label" for="quantidade">Quantidade</label>
+                <input class="form-control autonumeric" id="quantidade" name="quantidade" th:value="${commodity.quantidade}" type="text">
+
+                <label class="form-label" for="preco">Preço</label>
+                <div class="input-group">
+                    <span class="input-group-text">R$</span>
+                    <input class="form-control autodecimal" id="preco" name="preco" th:value="${commodity.preco}" type="text" placeholder="0,00">
+                </div>
+
+                <label class="form-label" for="vencimentoPagamento">Vencimento do Pagamento</label>
+                <input class="form-control" id="vencimentoPagamento" name="vencimentoPagamento" th:value="${commodity.vencimentoPagamento}"
+                       type="date">
+
+                <label class="form-label" for="dataLimiteEntrega">Data Limite da Entrega</label>
+                <input class="form-control" id="dataLimiteEntrega" name="dataLimiteEntrega" th:value="${commodity.dataLimiteEntrega}" type="date">
+
+                <label class="form-label" for="cedulaProdutoRural">CPR</label>
+                <input class="form-control" id="cedulaProdutoRural" name="dataLimiteEntrega" th:value="${commodity.cedulaProdutoRural}" type="file">
+
+            </div>
+            <button class="btn btn-dark" formmethod="post" th:formaction="@{/commodity}" type="submit">Salvar
+            </button>
+        </form>
+    </div>
+</section>
+</body>
+</html>

+ 41 - 0
src/main/resources/templates/commodity/list.html

@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org"
+      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
+      layout:decorate="~{fragments/layout}">
+<head>
+    <meta charset="UTF-8">
+    <title>Too Easy</title>
+</head>
+<body>
+<section layout:fragment="main-content">
+    <div class="container p-4 shadow bg-white rounded">
+        <h1 class="mb-4" th:text="${titulo}"></h1>
+        <table class="table table-hover">
+            <thead>
+            <tr>
+                <th>Código</th>
+                <th>Descrição</th>
+                <th>Ações</th>
+            </tr>
+            </thead>
+            <tbody>
+            <tr th:each="comodity : ${commodities}">
+                <td th:text="${comodity.id}">0</td>
+                <td th:text="${comodity.descricao}">0</td>
+                <td>
+                    <a th:href="@{'/commodity/edit/' + ${comodity.id}}" type="button" class="btn btn-outline-dark"
+                       title="Editar">
+                        <i class="bi bi-pencil-square"></i>
+                    </a>
+                    <a th:href="@{'/commodity/remove/' + ${comodity.id}}" type="button" class="btn btn-outline-dark"
+                       title="Remover">
+                        <i class="bi bi-dash-square"></i>
+                    </a>
+                </td>
+            </tr>
+            </tbody>
+        </table>
+    </div>
+</section>
+</body>
+</html>

+ 1 - 1
src/main/resources/templates/compra/formulario.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html lang="en" xmlns:th="http://www.thymeleaf.org"
       xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
-      layout:decorate="~{layout}">
+      layout:decorate="~{fragments/layout}">
 <head>
     <meta charset="UTF-8">
     <title>Too Easy</title>

+ 1 - 1
src/main/resources/templates/compra/lista.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html lang="en" xmlns:th="http://www.thymeleaf.org"
       xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
-      layout:decorate="~{layout}">
+      layout:decorate="~{fragments/layout}">
 <head>
     <meta charset="UTF-8">
     <title>Too Easy</title>

+ 16 - 0
src/main/resources/templates/error/400.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head th:insert="~{layout :: head}">
+    <meta charset="UTF-8">
+</head>
+<body class="d-flex flex-column min-vh-100">
+<nav th:insert="~{layout :: nav-top}"></nav>
+<main class="container text-center my-auto">
+    <h1 class="display-4">400</h1>
+    <p class="lead">Houve uma situação inesperada em nossa Página.</p>
+    <a th:href="@{/}" class="btn btn-dark">Voltar para o início</a>
+</main>
+<footer th:insert="~{layout :: footer}"></footer>
+<div th:insert="~{layout :: script}"></div>
+</body>
+</html>

+ 16 - 0
src/main/resources/templates/error/500.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head th:insert="~{layout :: head}">
+    <meta charset="UTF-8">
+</head>
+<body class="d-flex flex-column min-vh-100">
+<nav th:insert="~{layout :: nav-top}"></nav>
+<main class="container text-center my-auto">
+    <h1 class="display-4">500</h1>
+    <p class="lead">Houve uma situação inesperada em nossa Página.</p>
+    <a th:href="@{/}" class="btn btn-dark">Voltar para o início</a>
+</main>
+<footer th:insert="~{layout :: footer}"></footer>
+<div th:insert="~{layout :: script}"></div>
+</body>
+</html>

+ 17 - 1
src/main/resources/templates/layout.html → src/main/resources/templates/fragments/layout.html

@@ -18,7 +18,8 @@
         <div class="navbar-brand">
             <img th:src="@{/images/too-easy-trade.png}" class="img-fluid" style="max-width: 100px;">
         </div>
-        <button sec:authorize="isAuthenticated()" class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mobileMenu">
+        <button sec:authorize="isAuthenticated()" class="navbar-toggler" type="button" data-bs-toggle="collapse"
+                data-bs-target="#mobileMenu">
             <span class="navbar-toggler-icon"></span>
         </button>
     </div>
@@ -46,6 +47,21 @@
     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.min.js"
             integrity="sha384-RuyvpeZCxMJCqVUGFI0Do1mQrods/hhxYlcVfGPOfQtPJh0JCw12tUAZ/Mv10S7D"
             crossorigin="anonymous"></script>
+    <script src="https://cdn.jsdelivr.net/npm/autonumeric@4.5.4/dist/autoNumeric.min.js"></script>
+    <script>
+        AutoNumeric.multiple('.autodecimal', {
+          digitGroupSeparator: '.',
+          decimalCharacter: ',',
+          decimalPlaces: 2,
+          unformatOnSubmit: true
+        });
+        AutoNumeric.multiple('.autonumeric', {
+          digitGroupSeparator: '.',
+          decimalCharacter: ',',
+          decimalPlaces: 0,
+          unformatOnSubmit: true
+        });
+    </script>
 </div>
 </body>
 </html>

+ 19 - 31
src/main/resources/templates/fragments/menu.html

@@ -7,55 +7,43 @@
 <body>
 <nav th:fragment="nav-mobileMenu" class="col-md-2 bg-dark sidebar collapse d-md-block" id="mobileMenu">
     <a th:href="@{/}">🏠 Início</a>
-    <a th:href="@{/user/listar}">👥 Usuários</a>
 
-    <a sec:authorize="hasRole('ADMIN')"
-       class="dropdown-toggle d-block text-white" data-bs-toggle="collapse" href="#compras-submenu"
-       role="button" aria-expanded="false" aria-controls="compras-submenu">
-        🏷️ Compras
+    <a class="dropdown-toggle d-block text-white" data-bs-toggle="collapse" href="#commodities-submenu"
+       role="button" aria-expanded="false" aria-controls="commodities-submenu">
+        🛢️ Commodities
     </a>
-    <div class="collapse ms-2" id="compras-submenu">
-        <a th:href="@{/compra/listar}" class="d-block text-white">📋 Listar</a>
-        <a th:href="@{/compra}" class="d-block text-white">➕ Cadastrar</a>
+    <div class="collapse ms-2" id="commodities-submenu">
+        <a th:href="@{/commodity}" class="d-block text-white">➕ Cadastrar</a>
+        <a th:href="@{/commodity/all}" class="d-block text-white">📋 Listar</a>
+        <a th:href="@{/commodity/all}" class="d-block text-white">🪙 Autorizar</a>
     </div>
 
-    <a class="dropdown-toggle d-block text-white" data-bs-toggle="collapse" href="#relatoriosSubmenu"
-       role="button" aria-expanded="false" aria-controls="relatoriosSubmenu">
-        📊 Relatórios
-    </a>
-    <div class="collapse ms-2" id="relatoriosSubmenu">
-        <a href="#" class="d-block text-white">➤ Vendas</a>
-        <a href="#" class="d-block text-white">➤ Estoque</a>
-    </div>
+    <a th:href="@{/}">🏦 Bank</a>
 
-    <a href="#">⚙️ Configurações</a>
-    <a th:href="@{/logout}">🚪 Sair</a>
-</nav><nav class="col-md-2 bg-dark sidebar collapse d-md-block" id="mobileMenu">
-    <a th:href="@{/}">🏠 Início</a>
-    <a th:href="@{/user/listar}">👥 Usuários</a>
-
-    <a sec:authorize="hasRole('ADMIN')"
-       class="dropdown-toggle d-block text-white" data-bs-toggle="collapse" href="#compras-submenu"
-       role="button" aria-expanded="false" aria-controls="compras-submenu">
-        🏷️ Compras
+    <a class="dropdown-toggle d-block text-white" data-bs-toggle="collapse" href="#operacoes-submenu"
+       role="button" aria-expanded="false" aria-controls="operacoes-submenu">
+        📈 Operação
     </a>
-    <div class="collapse ms-2" id="compras-submenu">
-        <a th:href="@{/compra/listar}" class="d-block text-white">📋 Listar</a>
-        <a th:href="@{/compra}" class="d-block text-white">➕ Cadastrar</a>
+    <div class="collapse ms-2" id="operacoes-submenu">
+        <a th:href="@{/}" class="d-block text-white">🏷️ Compra</a>
+        <a th:href="@{/}" class="d-block text-white">📦 Venda</a>
+        <a th:href="@{/}" class="d-block text-white">🤝 Escambo</a>
     </div>
 
+    <a th:href="@{/}">🛍️ Marketplace</a>
+
     <a class="dropdown-toggle d-block text-white" data-bs-toggle="collapse" href="#relatoriosSubmenu"
        role="button" aria-expanded="false" aria-controls="relatoriosSubmenu">
         📊 Relatórios
     </a>
     <div class="collapse ms-2" id="relatoriosSubmenu">
+        <a href="#" class="d-block text-white">➤ Compras</a>
         <a href="#" class="d-block text-white">➤ Vendas</a>
-        <a href="#" class="d-block text-white">➤ Estoque</a>
     </div>
 
+    <a th:href="@{/user/listar}" sec:authorize="hasRole('ADMIN')">👥 Usuários</a>
     <a href="#">⚙️ Configurações</a>
     <a th:href="@{/logout}">🚪 Sair</a>
 </nav>
-
 </body>
 </html>

+ 6 - 6
src/main/resources/templates/login.html

@@ -1,20 +1,20 @@
 <!DOCTYPE html>
 <html lang="pt-br" xmlns:th="http://www.thymeleaf.org">
-<head th:insert="~{layout :: head}">
+<head th:insert="~{fragments/layout :: head}">
     <meta charset="UTF-8">
 </head>
 <body class="bg-light">
 
-<nav th:insert="~{layout :: nav-top}"></nav>
+<nav th:insert="~{fragments/layout :: nav-top}"></nav>
 
 <div class="container d-flex justify-content-center align-items-center" style="height: 100vh;">
     <form class="p-5 shadow bg-white rounded w-100" style="max-width: 400px;" method="post" th:action="@{/login}">
         <h4 class="mb-4">Login Admin</h4>
         <div class="mb-3">
-            <input class="form-control" type="text" name="username" placeholder="Usuário">
+            <input class="form-control" type="text" name="username" placeholder="Usuário" required>
         </div>
         <div class="mb-3">
-            <input class="form-control" type="password" name="password" placeholder="Senha">
+            <input class="form-control" type="password" name="password" placeholder="Senha" required>
         </div>
         <div class="d-grid">
             <button class="btn btn-dark" type="submit">Entrar</button>
@@ -22,7 +22,7 @@
     </form>
 </div>
 
-<footer th:insert="~{layout :: footer}"></footer>
-<div th:insert="~{layout :: script}"></div>
+<footer th:insert="~{fragments/layout :: footer}"></footer>
+<div th:insert="~{fragments/layout :: script}"></div>
 </body>
 </html>

+ 1 - 1
src/main/resources/templates/users/form.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html lang="en" xmlns:th="http://www.thymeleaf.org"
       xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
-      layout:decorate="~{layout}">
+      layout:decorate="~{fragments/layout}">
 <head>
     <meta charset="UTF-8">
     <title>Too Easy</title>

+ 1 - 1
src/main/resources/templates/users/list.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html lang="en" xmlns:th="http://www.thymeleaf.org"
       xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
-      layout:decorate="~{layout}">
+      layout:decorate="~{fragments/layout}">
 <head>
     <meta charset="UTF-8">
     <title>Too Easy</title>