Skip to content

Commit f8ea071

Browse files
committed
Upgrade em várias coisas (-_-)
1 parent 8f81242 commit f8ea071

File tree

68 files changed

+830
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+830
-224
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ DB_URL=
33
DB_USERNAME=
44
DB_PASSWORD=
55
JWT_SECRET_KEY=
6+
REDIS_HOST=
7+
REDIS_PORT=

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gradle"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ ENTRYPOINT ["java", "-XX:+UseContainerSupport", "-XX:InitialRAMPercentage=50.0",
5151
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
5252
CMD curl -f http://localhost:8080/actuator/health || exit 1
5353

54-
54+
LABEL org.opencontainers.image.title="Library API"
55+
LABEL org.opencontainers.image.version="1.0.0"
56+
LABEL org.opencontainers.image.authors="erichiroshi"
5557

5658
# docker compose up -d
5759

60+
# docker exec -i library-api-postgres-1 psql -U postgres -d library < seed_realistic_dataset.sql
61+
5862
# docker build -t library-api .
5963

6064
# docker compose -f docker-compose.dev.yml up -d

build.gradle

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
plugins {
22
id 'java'
3-
id 'org.springframework.boot' version '4.0.2'
3+
id 'org.springframework.boot' version '4.0.3'
44
id 'io.spring.dependency-management' version '1.1.7'
55
id 'jacoco'
66
id "org.sonarqube" version "7.2.2.6593"
7+
id 'com.google.cloud.tools.jib' version '3.4.0'
78
}
89

910
group = 'com.example'
@@ -16,6 +17,12 @@ java {
1617
}
1718
}
1819

20+
jib {
21+
to {
22+
image = "library-api:${version}"
23+
}
24+
}
25+
1926
repositories {
2027
mavenCentral()
2128
}
@@ -50,6 +57,8 @@ configurations {
5057
ext {
5158
mapstructVersion = "1.6.3"
5259
lombokMapstructBindingVersion = "0.2.0"
60+
springdocVersion = "3.0.1"
61+
jjwtVersion = "0.12.5"
5362
testcontainersVersion = "1.19.7"
5463
}
5564

@@ -74,9 +83,9 @@ dependencies {
7483
implementation 'org.flywaydb:flyway-database-postgresql'
7584

7685
// JWT
77-
implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
78-
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5'
79-
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5'
86+
implementation "io.jsonwebtoken:jjwt-api:${jjwtVersion}"
87+
runtimeOnly "io.jsonwebtoken:jjwt-impl:${jjwtVersion}"
88+
runtimeOnly "io.jsonwebtoken:jjwt-jackson:${jjwtVersion}"
8089

8190
// Caching + Redis
8291
implementation 'org.springframework.boot:spring-boot-starter-cache'
@@ -91,7 +100,7 @@ dependencies {
91100
annotationProcessor "org.projectlombok:lombok-mapstruct-binding:${lombokMapstructBindingVersion}"
92101

93102
// OpenAPI / Swagger
94-
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.1'
103+
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springdocVersion}"
95104

96105
// Tests
97106
testImplementation 'org.springframework.boot:spring-boot-starter-test'

docker-compose.dev.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ services:
6565
volumes:
6666
- redis_data:/data
6767
restart: unless-stopped
68+
healthcheck:
69+
test: ["CMD", "redis-cli", "ping"]
70+
interval: 10s
71+
timeout: 3s
72+
retries: 5
6873
networks:
6974
- backend
7075

docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ services:
6565
volumes:
6666
- redis_data:/data
6767
restart: unless-stopped
68+
healthcheck:
69+
test: ["CMD", "redis-cli", "ping"]
70+
interval: 10s
71+
timeout: 3s
72+
retries: 5
6873
networks:
6974
- backend
7075

@@ -83,7 +88,7 @@ services:
8388
postgres:
8489
condition: service_healthy
8590
redis:
86-
condition: service_started
91+
condition: service_healthy
8792
networks:
8893
- backend
8994
restart: unless-stopped

readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ Exemplo de métrica customizada:
147147

148148
A documentação interativa está disponível via Swagger:
149149

150-
```
151-
http://localhost:8080/swagger-ui.html
152-
```
150+
151+
Swagger UI: http://localhost:8080/swagger-ui/index.html
152+
153+
OpenAPI JSON: http://localhost:8080/v3/api-docs
154+
153155

154156
---
155157

seed_realistic_dataset.sql

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
-- ============================
2+
-- Categorias
3+
-- ============================
4+
INSERT INTO tb_category (name) VALUES ('Tecnologia');
5+
INSERT INTO tb_category (name) VALUES ('Literatura');
6+
INSERT INTO tb_category (name) VALUES ('História');
7+
INSERT INTO tb_category (name) VALUES ('Ciência');
8+
INSERT INTO tb_category (name) VALUES ('Filosofia');
9+
INSERT INTO tb_category (name) VALUES ('Fantasia');
10+
INSERT INTO tb_category (name) VALUES ('Negócios');
11+
12+
-- ============================
13+
-- Autores
14+
-- ============================
15+
INSERT INTO tb_author (name, biography) VALUES ('Robert C. Martin', 'Autor reconhecido internacionalmente.');
16+
INSERT INTO tb_author (name, biography) VALUES ('Joshua Bloch', 'Autor reconhecido internacionalmente.');
17+
INSERT INTO tb_author (name, biography) VALUES ('George Orwell', 'Autor reconhecido internacionalmente.');
18+
INSERT INTO tb_author (name, biography) VALUES ('J.K. Rowling', 'Autor reconhecido internacionalmente.');
19+
INSERT INTO tb_author (name, biography) VALUES ('Stephen King', 'Autor reconhecido internacionalmente.');
20+
INSERT INTO tb_author (name, biography) VALUES ('Yuval Noah Harari', 'Autor reconhecido internacionalmente.');
21+
INSERT INTO tb_author (name, biography) VALUES ('Sun Tzu', 'Autor reconhecido internacionalmente.');
22+
INSERT INTO tb_author (name, biography) VALUES ('Adam Smith', 'Autor reconhecido internacionalmente.');
23+
INSERT INTO tb_author (name, biography) VALUES ('Daniel Kahneman', 'Autor reconhecido internacionalmente.');
24+
INSERT INTO tb_author (name, biography) VALUES ('Carl Sagan', 'Autor reconhecido internacionalmente.');
25+
INSERT INTO tb_author (name, biography) VALUES ('Isaac Asimov', 'Autor reconhecido internacionalmente.');
26+
INSERT INTO tb_author (name, biography) VALUES ('Jane Austen', 'Autor reconhecido internacionalmente.');
27+
INSERT INTO tb_author (name, biography) VALUES ('Ernest Hemingway', 'Autor reconhecido internacionalmente.');
28+
INSERT INTO tb_author (name, biography) VALUES ('Fiódor Dostoiévski', 'Autor reconhecido internacionalmente.');
29+
INSERT INTO tb_author (name, biography) VALUES ('Machado de Assis', 'Autor reconhecido internacionalmente.');
30+
INSERT INTO tb_author (name, biography) VALUES ('Clarice Lispector', 'Autor reconhecido internacionalmente.');
31+
INSERT INTO tb_author (name, biography) VALUES ('Neil Gaiman', 'Autor reconhecido internacionalmente.');
32+
INSERT INTO tb_author (name, biography) VALUES ('Brandon Sanderson', 'Autor reconhecido internacionalmente.');
33+
INSERT INTO tb_author (name, biography) VALUES ('Malcolm Gladwell', 'Autor reconhecido internacionalmente.');
34+
INSERT INTO tb_author (name, biography) VALUES ('Nassim Taleb', 'Autor reconhecido internacionalmente.');
35+
36+
-- ============================
37+
-- Livros (Realistas)
38+
-- ============================
39+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Clean Code', '9780000000001', 2008, 7, 1);
40+
INSERT INTO tb_book_author (book_id, author_id) VALUES (1, 17);
41+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Effective Java', '9780000000002', 2018, 7, 1);
42+
INSERT INTO tb_book_author (book_id, author_id) VALUES (2, 18);
43+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('1984', '9780000000003', 1949, 13, 2);
44+
INSERT INTO tb_book_author (book_id, author_id) VALUES (3, 9);
45+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Animal Farm', '9780000000004', 1945, 11, 2);
46+
INSERT INTO tb_book_author (book_id, author_id) VALUES (4, 16);
47+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Harry Potter and the Sorcerers Stone', '9780000000005', 1997, 1, 6);
48+
INSERT INTO tb_book_author (book_id, author_id) VALUES (5, 19);
49+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('The Shining', '9780000000006', 1977, 10, 2);
50+
INSERT INTO tb_book_author (book_id, author_id) VALUES (6, 8);
51+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Sapiens', '9780000000007', 2011, 10, 3);
52+
INSERT INTO tb_book_author (book_id, author_id) VALUES (7, 9);
53+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('The Art of War', '9780000000008', -500, 3, 3);
54+
INSERT INTO tb_book_author (book_id, author_id) VALUES (8, 8);
55+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('The Wealth of Nations', '9780000000009', 1776, 12, 7);
56+
INSERT INTO tb_book_author (book_id, author_id) VALUES (9, 20);
57+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Thinking, Fast and Slow', '9780000000010', 2011, 2, 4);
58+
INSERT INTO tb_book_author (book_id, author_id) VALUES (10, 7);
59+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Cosmos', '9780000000011', 1980, 3, 4);
60+
INSERT INTO tb_book_author (book_id, author_id) VALUES (11, 18);
61+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Foundation', '9780000000012', 1951, 2, 6);
62+
INSERT INTO tb_book_author (book_id, author_id) VALUES (12, 16);
63+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Pride and Prejudice', '9780000000013', 1813, 2, 2);
64+
INSERT INTO tb_book_author (book_id, author_id) VALUES (13, 12);
65+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('The Old Man and the Sea', '9780000000014', 1952, 5, 2);
66+
INSERT INTO tb_book_author (book_id, author_id) VALUES (14, 2);
67+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Crime and Punishment', '9780000000015', 1866, 5, 2);
68+
INSERT INTO tb_book_author (book_id, author_id) VALUES (15, 3);
69+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Dom Casmurro', '9780000000016', 1899, 7, 2);
70+
INSERT INTO tb_book_author (book_id, author_id) VALUES (16, 7);
71+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('A Hora da Estrela', '9780000000017', 1977, 12, 2);
72+
INSERT INTO tb_book_author (book_id, author_id) VALUES (17, 1);
73+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('American Gods', '9780000000018', 2001, 11, 6);
74+
INSERT INTO tb_book_author (book_id, author_id) VALUES (18, 15);
75+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Mistborn', '9780000000019', 2006, 11, 6);
76+
INSERT INTO tb_book_author (book_id, author_id) VALUES (19, 3);
77+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('Outliers', '9780000000020', 2008, 9, 7);
78+
INSERT INTO tb_book_author (book_id, author_id) VALUES (20, 7);
79+
INSERT INTO tb_book (title, isbn, publication_year, available_copies, category_id) VALUES ('The Black Swan', '9780000000021', 2007, 3, 7);
80+
INSERT INTO tb_book_author (book_id, author_id) VALUES (21, 16);
81+
82+
-- ============================
83+
-- Usuários
84+
-- ============================
85+
INSERT INTO tb_user (name, email, phone, password) VALUES
86+
('João Silva', 'joao.silva@email.com', '11999999999', '{bcrypt}$2a$12$HKylhM2ZGJ6fmQa2mr2eHuSZ4htjXOlD3EjpFP7L3FQmzr1ZBUdky'),
87+
('Maria Souza', 'maria.souza@email.com', '11888888888', '{bcrypt}$2a$12$HKylhM2ZGJ6fmQa2mr2eHuSZ4htjXOlD3EjpFP7L3FQmzr1ZBUdky'),
88+
('Admin', 'admin@admin.com', '11999999899', '{bcrypt}$2a$12$oqR2CMQMn03KTkO6sHr8y.t//zDSetEIueMq4mPBfLD8XaSVkbIzS'),
89+
('User', 'user@user.com', '11999999997', '{bcrypt}$2a$12$duyl2ugEqZovBPIIhlkzueeMd5Qccz.etOCo.ceI1/yk7sr.7Gamq');
90+
91+
INSERT INTO tb_user_roles (user_id, role) VALUES
92+
(1, 'ROLE_ADMIN'),
93+
(1, 'ROLE_USER'),
94+
(2, 'ROLE_USER'),
95+
(3, 'ROLE_ADMIN'),
96+
(4, 'ROLE_USER');
97+
98+
-- ============================
99+
-- Empréstimos (25 variados)
100+
-- ============================
101+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-21', '2026-01-28', NULL, 'OVERDUE', 1);
102+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2025-12-21', '2025-12-28', NULL, 'WAITING_RETURN', 2);
103+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-21', '2026-01-28', '2026-01-28', 'RETURNED', 2);
104+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2025-12-30', '2026-01-06', NULL, 'CANCELED', 1);
105+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-12', '2026-01-19', NULL, 'CANCELED', 2);
106+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-02-06', '2026-02-13', NULL, 'WAITING_RETURN', 2);
107+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-02', '2026-01-09', NULL, 'WAITING_RETURN', 2);
108+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2025-12-27', '2026-01-03', NULL, 'OVERDUE', 1);
109+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-06', '2026-01-13', NULL, 'OVERDUE', 2);
110+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-29', '2026-02-05', NULL, 'CANCELED', 2);
111+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-03', '2026-01-10', NULL, 'CANCELED', 2);
112+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2025-12-30', '2026-01-06', NULL, 'CANCELED', 1);
113+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-02-18', '2026-02-25', '2026-02-24', 'RETURNED', 2);
114+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2025-12-29', '2026-01-05', NULL, 'OVERDUE', 1);
115+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-02-12', '2026-02-19', '2026-02-17', 'RETURNED', 1);
116+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-02-07', '2026-02-14', NULL, 'WAITING_RETURN', 1);
117+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2025-12-28', '2026-01-04', NULL, 'WAITING_RETURN', 2);
118+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-20', '2026-01-27', NULL, 'CANCELED', 2);
119+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-05', '2026-01-12', NULL, 'OVERDUE', 1);
120+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2025-12-23', '2025-12-30', NULL, 'WAITING_RETURN', 2);
121+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-09', '2026-01-16', NULL, 'WAITING_RETURN', 1);
122+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-02', '2026-01-09', '2026-01-09', 'RETURNED', 1);
123+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-15', '2026-01-22', NULL, 'WAITING_RETURN', 2);
124+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-05', '2026-01-12', '2026-01-09', 'RETURNED', 2);
125+
INSERT INTO tb_loan (loan_date, due_date, return_date, status, user_id) VALUES ('2026-01-03', '2026-01-10', NULL, 'CANCELED', 1);
126+
127+
-- ============================
128+
-- Itens dos Empréstimos
129+
-- ============================
130+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (1, 16, 1);
131+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (2, 1, 2);
132+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (3, 1, 1);
133+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (4, 15, 2);
134+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (5, 12, 3);
135+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (6, 10, 3);
136+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (7, 8, 2);
137+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (8, 13, 3);
138+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (9, 6, 1);
139+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (10, 6, 1);
140+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (11, 16, 3);
141+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (12, 2, 3);
142+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (13, 17, 1);
143+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (14, 15, 2);
144+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (15, 7, 2);
145+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (16, 4, 3);
146+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (17, 11, 1);
147+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (18, 10, 3);
148+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (19, 19, 1);
149+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (20, 12, 2);
150+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (21, 15, 2);
151+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (22, 10, 2);
152+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (23, 13, 2);
153+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (24, 4, 2);
154+
INSERT INTO tb_loan_item (loan_id, book_id, quantity) VALUES (25, 21, 2);

src/integrationTest/java/com/example/library/config/BaseControllerIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.security.crypto.password.PasswordEncoder;
77
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
88

9-
import com.example.library.jwt.JwtService;
9+
import com.example.library.security.jwt.JwtService;
1010
import com.example.library.user.User;
1111
import com.example.library.user.UserRepository;
1212

0 commit comments

Comments
 (0)