Skip to content

Commit f6ee887

Browse files
committed
Merge branch 'base-project'
2 parents b3157f4 + 7a06ffd commit f6ee887

File tree

6 files changed

+210
-0
lines changed

6 files changed

+210
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package br.com.catalog;
2+
3+
import br.com.catalog.models.enums.UserRole;
4+
import br.com.catalog.services.IAuthenticationService;
5+
import br.com.catalog.services.impls.dtos.AuthenticationDTO;
6+
import br.com.catalog.services.impls.dtos.RegisterDTO;
7+
import br.com.catalog.services.impls.dtos.UserResponseDTO;
8+
import org.springframework.boot.CommandLineRunner;
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
12+
@SpringBootApplication
13+
public class CatalogApplication implements CommandLineRunner {
14+
private final IAuthenticationService<AuthenticationDTO, UserResponseDTO, RegisterDTO> authenticationService;
15+
16+
public CatalogApplication(IAuthenticationService<AuthenticationDTO, UserResponseDTO, RegisterDTO> authenticationService) {
17+
this.authenticationService = authenticationService;
18+
}
19+
20+
public static void main(String[] args) {
21+
SpringApplication.run(CatalogApplication.class, args);
22+
}
23+
24+
@Override
25+
public void run(String... args) throws Exception {
26+
authenticationService.register(new RegisterDTO("useradmin", "passwordadmin", UserRole.ADMIN));
27+
authenticationService.register(new RegisterDTO("userstandard", "passwordstandard", UserRole.USER));
28+
}
29+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#spring:
2+
# h2:
3+
# console:
4+
# enabled: true
5+
# path: /h2-console
6+
# datasource:
7+
# driverClassName: org.h2.Driver
8+
# url: jdbc:h2:mem:testdb
9+
# username: sa
10+
# password:
11+
# jpa:
12+
# database-platform: org.hibernate.dialect.H2Dialect
13+
# hibernate:
14+
# ddl-auto: update
15+
# show-sql: true
16+
# format-sql: true
17+
# flyway:
18+
# enabled: true
19+
# locations: classpath:db/migration
20+
# baselineOnMigrate: true
21+
#
22+
#logging:
23+
# level:
24+
# root: INFO
25+
# org.springframework.web: INFO
26+
# org.hibernate: INFO
27+
28+
server:
29+
port: 8080
30+
31+
spring:
32+
application:
33+
name: catalog
34+
datasource:
35+
driver-class-name: com.mysql.cj.jdbc.Driver
36+
url: jdbc:mysql://localhost:3306/catalog
37+
username: cataloguser
38+
password: catalogpass
39+
jpa:
40+
database-platform: org.hibernate.dialect.MySQLDialect
41+
show-sql: true
42+
properties:
43+
hibernate:
44+
format_sql: true
45+
hibernate:
46+
ddl-auto: validate
47+
h2:
48+
console:
49+
enabled: false
50+
flyway:
51+
enabled: true
52+
locations: classpath:db/migration
53+
validate-on-migrate: true
54+
55+
api:
56+
security:
57+
token:
58+
secret: Zk5osQLbp;B$7XP)
59+
60+
springdoc:
61+
api-docs:
62+
path: /api-docs
63+
swagger-ui:
64+
path: /swagger-ui.html
65+
66+
logging:
67+
level:
68+
root: INFO
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
server:
2+
port: ${APP_PORT}
3+
4+
spring:
5+
application:
6+
name: ${APP_NAME}
7+
datasource:
8+
driver-class-name: com.mysql.cj.jdbc.Driver
9+
url: jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}
10+
username: ${MYSQL_USER}
11+
password: ${MYSQL_PASSWORD}
12+
jpa:
13+
database-platform: org.hibernate.dialect.MySQLDialect
14+
show-sql: true
15+
properties:
16+
hibernate:
17+
format_sql: true
18+
hibernate:
19+
ddl-auto: validate
20+
h2:
21+
console:
22+
enabled: false
23+
flyway:
24+
enabled: true
25+
locations: classpath:db/migration
26+
validate-on-migrate: true
27+
28+
api:
29+
security:
30+
token:
31+
secret: ${JWT_SECRET:secret-key}
32+
33+
springdoc:
34+
api-docs:
35+
path: /api-docs
36+
swagger-ui:
37+
path: /swagger-ui.html
38+
39+
logging:
40+
level:
41+
root: INFO
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CREATE TABLE IF NOT EXISTS tb_brand (
2+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
3+
name VARCHAR(50) NOT NULL UNIQUE,
4+
status VARCHAR(10) NOT NULL,
5+
created_at DATETIME NOT NULL,
6+
updated_at DATETIME NOT NULL
7+
);
8+
9+
CREATE TABLE IF NOT EXISTS tb_product (
10+
id BIGINT AUTO_INCREMENT PRIMARY KEY,
11+
name VARCHAR(50) NOT NULL UNIQUE,
12+
brand_id BIGINT NOT NULL,
13+
description TEXT NOT NULL,
14+
price DECIMAL(7, 2) NOT NULL,
15+
stock_quantity INT NOT NULL,
16+
status VARCHAR(10) NOT NULL,
17+
created_at DATETIME NOT NULL,
18+
updated_at DATETIME NOT NULL,
19+
FOREIGN KEY (brand_id) REFERENCES tb_brand(id)
20+
);
21+
22+
CREATE TABLE IF NOT EXISTS tb_user (
23+
id VARCHAR(255) PRIMARY KEY,
24+
status VARCHAR(10) NOT NULL,
25+
created_at datetime NOT NULL,
26+
updated_at datetime NOT NULL,
27+
login VARCHAR(255) NOT NULL,
28+
password VARCHAR(255) NOT NULL,
29+
role VARCHAR(10) NOT NULL
30+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
INSERT INTO tb_brand (name, status, created_at, updated_at)
2+
VALUES
3+
('Taurus', 'ACTIVE', NOW(), NOW()),
4+
('Imbel', 'ACTIVE', NOW(), NOW()),
5+
('Glock', 'ACTIVE', NOW(), NOW()),
6+
('Colt', 'ACTIVE', NOW(), NOW()),
7+
('Sig Sauer', 'ACTIVE', NOW(), NOW()),
8+
('Beretta', 'ACTIVE', NOW(), NOW()),
9+
('Smith & Wesson', 'ACTIVE', NOW(), NOW()),
10+
('Heckler & Koch', 'ACTIVE', NOW(), NOW());
11+
12+
INSERT INTO tb_product (name, brand_id, description, price, stock_quantity, status, created_at, updated_at)
13+
VALUES
14+
('Pistola G2C', 1, 'Pistola compacta e leve, ideal para porte velado.', 2500.00, 15, 'ACTIVE', NOW(), NOW()),
15+
('Pistola TS9', 1, 'Pistola para uso tático e esportivo, com alta precisão.', 3200.00, 10, 'ACTIVE', NOW(), NOW()),
16+
('Carabina IA2', 2, 'Carabina de alta resistência, utilizada por forças armadas.', 4500.00, 8, 'ACTIVE', NOW(), NOW()),
17+
('Pistola .40', 2, 'Pistola popular para uso policial, confiável e durável.', 2800.00, 20, 'ACTIVE', NOW(), NOW()),
18+
('Glock 17', 3, 'Modelo clássico da Glock, confiável e amplamente utilizado.', 3000.00, 25, 'ACTIVE', NOW(), NOW()),
19+
('Glock 19', 3, 'Modelo compacto da Glock, ideal para porte velado.', 3100.00, 18, 'ACTIVE', NOW(), NOW()),
20+
('Colt M1911', 4, 'Pistola lendária com mais de um século de uso militar.', 3500.00, 12, 'ACTIVE', NOW(), NOW()),
21+
('Colt Python', 4, 'Revólver de alta precisão e construção robusta.', 3700.00, 5, 'ACTIVE', NOW(), NOW()),
22+
('Sig Sauer P320', 5, 'Pistola modular e confiável, usada por forças militares.', 3300.00, 10, 'INACTIVE', NOW(), NOW()),
23+
('Sig Sauer P226', 5, 'Pistola clássica de serviço, com alta precisão.', 3400.00, 6, 'DELETED', NOW(), NOW()),
24+
('Beretta 92FS', 6, 'Pistola de alto desempenho com design clássico.', 3100.00, 12, 'INACTIVE', NOW(), NOW()),
25+
('Beretta PX4 Storm', 6, 'Pistola compacta, ideal para defesa pessoal.', 2900.00, 5, 'DELETED', NOW(), NOW()),
26+
('S&W M&P9', 7, 'Pistola de polímero com ergonomia avançada.', 3200.00, 9, 'INACTIVE', NOW(), NOW()),
27+
('S&W 686', 7, 'Revólver robusto, projetado para alto desempenho.', 3600.00, 3, 'DELETED', NOW(), NOW()),
28+
('HK USP', 8, 'Pistola versátil, projetada para uso militar e policial.', 3500.00, 8, 'INACTIVE', NOW(), NOW()),
29+
('HK VP9', 8, 'Pistola leve com sistema de disparo inovador.', 3400.00, 4, 'DELETED', NOW(), NOW());
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package br.com.catalog;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class CatalogApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}

0 commit comments

Comments
 (0)