Skip to content

Commit

Permalink
alterado para usar h2 datavase em memoria e adicionado lombok removen…
Browse files Browse the repository at this point in the history
…do get e set do entity Task
  • Loading branch information
artodeschini committed Apr 4, 2024
1 parent 1891f62 commit 5ae8e06
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 81 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A Simple RestFull Sample Quarkus
* Java 11
* Maven 3.8.4
* Quarkus
* JPA / Panache with Postgres
* JPA / Panache with h2 Databases
* JSON
* jQuery (only use to bootstrap)
* Bootstrap 5
Expand All @@ -22,4 +22,5 @@ mvn clean install

```bash
java -jar target/quarkus-app/quarkus-run.jar
```
```

37 changes: 31 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<jacoco.version>0.8.7</jacoco.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -31,6 +32,13 @@
</dependencies>
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
Expand All @@ -39,9 +47,13 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<!-- <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency> -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -79,9 +91,9 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<configuration>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</configuration>
<!-- <configuration>-->
<!-- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>-->
<!-- </configuration>-->
<executions>
<execution>
<goals>
Expand All @@ -99,7 +111,6 @@
<target>11</target>
</configuration>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
Expand Down Expand Up @@ -153,6 +164,20 @@
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-jar-plugin</artifactId>-->
<!-- <version>3.1.0</version>-->
<!-- <configuration>-->
<!-- <archive>-->
<!-- <manifest>-->
<!-- <addClasspath>true</addClasspath>-->
<!-- <classpathPrefix>lib/</classpathPrefix>-->
<!-- <mainClass>org.todeschini.App</mainClass>-->
<!-- </manifest>-->
<!-- </archive>-->
<!-- </configuration>-->
<!-- </plugin>-->
</plugins>
</build>
<profiles>
Expand Down Expand Up @@ -193,4 +218,4 @@
</properties>
</profile>
</profiles>
</project>
</project>
4 changes: 3 additions & 1 deletion src/main/java/org/todeschini/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import io.quarkus.runtime.Quarkus;
import io.quarkus.runtime.annotations.QuarkusMain;
import lombok.extern.slf4j.Slf4j;

@QuarkusMain
@Slf4j
public class App {

public static void main(String ... args) {
System.out.println("start task app");
log.info("start task app");
Quarkus.run(args);
}
}
57 changes: 4 additions & 53 deletions src/main/java/org/todeschini/entity/Task.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.todeschini.entity;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import javax.persistence.Basic;
Expand All @@ -16,10 +19,9 @@
*/
@Entity
@Table(name = "task")
@Data
public class Task extends PanacheEntity implements Serializable {

private static final long serialVersionUID = 1L;

@Basic(optional = false)
@NotNull
@Size(min = 1, max = 45)
Expand Down Expand Up @@ -51,55 +53,4 @@ public Task(String titulo, int status, String descricao) {
this.status = status;
this.descricao = descricao;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getTitulo() {
return titulo;
}

public void setTitulo(String titulo) {
this.titulo = titulo;
}

public int getStatus() {
return status;
}

public void setStatus(int status) {
this.status = status;
}

public String getDescricao() {
return descricao;
}

public void setDescricao(String descricao) {
this.descricao = descricao;
}

@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
if (!(object instanceof Task)) {
return false;
}
Task other = (Task) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/todeschini/resource/TaskResource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.todeschini.resource;

import lombok.extern.slf4j.Slf4j;
import org.todeschini.entity.Task;
import org.todeschini.service.AbstractFacade;

Expand All @@ -20,6 +21,7 @@
* @author Artur
*/
@Path("/tasks")
@Slf4j
public class TaskResource extends AbstractFacade<Task> {


Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tarefas</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<style>
.margin-left {
margin-left: 80px !important;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
Expand Down
33 changes: 18 additions & 15 deletions src/main/resources/META-INF/resources/js/main.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const api = "/api/tasks";

function createTextCell(newRow, index, value) {
let cell = newRow.insertCell(index);
const cell = newRow.insertCell(index);

let p = document.createElement('p');
let b = document.createElement('b');
const p = document.createElement('p');
const b = document.createElement('b');
b.innerHTML = value;
p.appendChild(b);

cell.appendChild(p);
}

function createCellStatus(newRow, index, isStatusConcluido) {
let cell = newRow.insertCell(index);
let s = document.createElement('span');
const cell = newRow.insertCell(index);
const s = document.createElement('span');


if ( isStatusConcluido ) {
Expand All @@ -36,7 +36,7 @@ function loadTask(id) {
* @type type
*/
function changeStatus(id) {
let url = `${api}/${id}`;
const url = `${api}/${id}`;

fetch(url).then(response => {
console.log(response);
Expand Down Expand Up @@ -70,7 +70,7 @@ function changeStatus(id) {
}

function deleteTask(id) {
let url = `${api}/${id}`;
const url = `${api}/${id}`;

fetch(url, {
method: 'DELETE',
Expand All @@ -86,15 +86,18 @@ function deleteTask(id) {
}

function createButtonGrid(id, label) {
let button = document.createElement('button');
const button = document.createElement('button');
button.innerHTML = label;

//actions
if (label === 'Editar') {
button.classList.add("btn btn-info margin-left")
button.addEventListener('click', () => { loadTask(id) });
} else if (label === 'Deletar') {
button.classList.add("btn btn-danger margin-left")
button.addEventListener('click', () => { deleteTask(id) });
} else if (label === 'Desmarcar Concluida' || label === 'Marcar como Concluida') {
button.classList.add("btn btn-secondary margin-left")
button.addEventListener('click', () => { changeStatus(id) });
}

Expand All @@ -112,17 +115,17 @@ function checkStatusConcluido(status) {
function findTasksAll() {
//onload page

let rows = document.getElementById('rows');
const rows = document.getElementById('rows');
let index = 1;

fetch(api).then(response => {
response.json().then(tasks => {
tasks.forEach(t => {
// Insert a row at tde end of table
let newRow = rows.insertRow(index++);
const newRow = rows.insertRow(index++);

// status
let isStatusConcluido = checkStatusConcluido(t.status);
const isStatusConcluido = checkStatusConcluido(t.status);

// elemetros da grid

Expand All @@ -139,14 +142,14 @@ function findTasksAll() {
createTextCell(newRow, 3, t.descricao);

//botoes
let cellBotoes = newRow.insertCell(4);
const cellBotoes = newRow.insertCell(4);

// btn editar
let btnEdit = createButtonGrid(t.id, 'Editar');
const btnEdit = createButtonGrid(t.id, 'Editar');
cellBotoes.appendChild(btnEdit);

// btn deletar
let btnDel = createButtonGrid(t.id, 'Deletar');
const btnDel = createButtonGrid(t.id, 'Deletar');
cellBotoes.appendChild(btnDel);

let label = '';
Expand All @@ -157,7 +160,7 @@ function findTasksAll() {
}

// btn patch
let btnStatus = createButtonGrid(t.id, label);
const btnStatus = createButtonGrid(t.id, label);
cellBotoes.appendChild(btnStatus);
});
});
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
%prod.quarkus.datasource.db-kind=postgresql
%prod.quarkus.datasource.username=postgres
%prod.quarkus.datasource.password=postgres
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/tasks
%prod.quarkus.datasource.db-kind=h2
%prod.quarkus.datasource.username=root
%prod.quarkus.datasource.password=root
%prod.quarkus.datasource.jdbc.url=jdbc:h2:mem:tasks
%prod.quarkus.datasource.jdbc.max-size=8
%prod.quarkus.datasource.jdbc.min-size=2

#quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.log.sql=true
#quarkus.hibernate-orm.sql-load-script=import.sql

Expand Down

0 comments on commit 5ae8e06

Please sign in to comment.