Skip to content

Commit 7ebcc8d

Browse files
committed
Merge branch 'dev'
2 parents dafd9ae + 4280602 commit 7ebcc8d

15 files changed

+747
-0
lines changed

docker-compose.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
networks:
2+
db-network:
3+
driver: bridge
4+
5+
services:
6+
db:
7+
image: mysql
8+
container_name: mysql
9+
restart: always
10+
environment:
11+
- 'MYSQL_DATABASE=${MYSQL_DATABASE}'
12+
- 'MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}'
13+
- 'MYSQL_USER=${MYSQL_USER}'
14+
- 'MYSQL_PASSWORD=${MYSQL_PASSWORD}'
15+
ports:
16+
- '${MYSQL_PORT}:${MYSQL_PORT}'
17+
expose:
18+
- '${MYSQL_PORT}'
19+
networks:
20+
- 'db-network'
21+
healthcheck:
22+
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
23+
interval: 5s
24+
timeout: 5s
25+
retries: 5
26+
# volumes:
27+
# - './mysql:/var/lib/mysql'
28+
29+
app:
30+
depends_on:
31+
db:
32+
condition: service_healthy
33+
build:
34+
context: .
35+
dockerfile: Dockerfile
36+
container_name: catalog-app
37+
ports:
38+
- '${APP_PORT}:${APP_PORT}'
39+
expose:
40+
- '${APP_PORT}'
41+
networks:
42+
- 'db-network'
43+
env_file:
44+
- '.env'
45+
46+
# Se necessário manipular o banco de dados
47+
#
48+
# phpmyadmin:
49+
# depends_on:
50+
# - 'mysql'
51+
# image: phpmyadmin/phpmyadmin
52+
# restart: always
53+
# ports:
54+
# - '80:80'
55+
# environment:
56+
# - 'PMA_ARBITRARY=1'
57+
# networks:
58+
# - 'db-network'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package br.com.catalog.configs;
2+
3+
import io.swagger.v3.oas.models.OpenAPI;
4+
import io.swagger.v3.oas.models.info.Contact;
5+
import io.swagger.v3.oas.models.info.Info;
6+
import io.swagger.v3.oas.models.info.License;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
@Configuration
11+
public class DocSwaggerConfig {
12+
@Bean
13+
public OpenAPI openAPI() {
14+
return new OpenAPI()
15+
.info(new Info()
16+
.title("API de gerenciamento de produtos")
17+
.description("CRUD de produtos e marcas + operações de domínio")
18+
.version("v1")
19+
.license(new License().name("MIT License").url("https://opensource.org/licenses/MIT"))
20+
.contact(new Contact().name("maxjdev").email("[email protected]").url("https://www.linkedin.com/in/maxjdev/")));
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package br.com.catalog.controller;
2+
3+
import br.com.catalog.controller.responses.Response;
4+
import br.com.catalog.services.IAdmService;
5+
import br.com.catalog.services.impls.dtos.BrandDTO;
6+
import br.com.catalog.services.impls.dtos.ProductDTO;
7+
import io.swagger.v3.oas.annotations.Operation;
8+
import io.swagger.v3.oas.annotations.media.Content;
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
12+
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.ResponseEntity;
14+
import org.springframework.web.bind.annotation.*;
15+
16+
@RestController
17+
@RequestMapping("/api/admin")
18+
public class AdminController {
19+
private final IAdmService<ProductDTO> admProductService;
20+
private final IAdmService<BrandDTO> admBrandService;
21+
22+
public AdminController(IAdmService<ProductDTO> admProductService,
23+
IAdmService<BrandDTO> admBrandService) {
24+
this.admProductService = admProductService;
25+
this.admBrandService = admBrandService;
26+
}
27+
28+
/*
29+
* Brand
30+
*/
31+
@Operation(summary = "Deleta uma marca permanentemente (ADM)")
32+
@ApiResponses(value = {
33+
@ApiResponse(responseCode = "204", description = "Marca deletada com sucesso"),
34+
@ApiResponse(responseCode = "404", description = "Marca não encontrada")
35+
})
36+
@DeleteMapping("/brand/fullDelete/{id}")
37+
public ResponseEntity<Response<Void>> fullDeleteBrand(@PathVariable Long id) throws Exception {
38+
admBrandService.fullDelete(id);
39+
return ResponseEntity.noContent().build();
40+
}
41+
42+
@Operation(summary = "Desativa uma marca (ADM)")
43+
@ApiResponses(value = {
44+
@ApiResponse(responseCode = "200", description = "Marca desativada com sucesso"),
45+
@ApiResponse(responseCode = "404", description = "Marca não encontrada")
46+
})
47+
@PutMapping("/brand/disable/{id}")
48+
public ResponseEntity<Response<Void>> disableBrand(@PathVariable Long id) throws Exception {
49+
admBrandService.disable(id);
50+
return ResponseEntity.noContent().build();
51+
}
52+
53+
@Operation(summary = "Ativa uma marca desativada (ADM)")
54+
@ApiResponses(value = {
55+
@ApiResponse(responseCode = "200", description = "Marca ativada com sucesso",
56+
content = @Content(mediaType = "application/json",
57+
schema = @Schema(implementation = BrandDTO.class))),
58+
@ApiResponse(responseCode = "404", description = "Marca não encontrada")
59+
})
60+
@PutMapping("/brand/activate/{id}")
61+
public ResponseEntity<Response<BrandDTO>> activateBrand(@PathVariable Long id) throws Exception {
62+
return ResponseEntity.ok(new Response<>(
63+
HttpStatus.OK.toString(),
64+
"Brand activated successfully",
65+
admBrandService.activate(id)));
66+
}
67+
68+
/*
69+
* Product
70+
*/
71+
@Operation(summary = "Exclui permanentemente um produto (ADM)")
72+
@ApiResponses(value = {
73+
@ApiResponse(responseCode = "204", description = "Produto excluído permanentemente"),
74+
@ApiResponse(responseCode = "404", description = "Produto não encontrado")
75+
})
76+
@DeleteMapping("/product/fullDelete/{id}")
77+
public ResponseEntity<Response<Void>> fullDeleteProduct(@PathVariable Long id) throws Exception {
78+
admProductService.fullDelete(id);
79+
return ResponseEntity.noContent().build();
80+
}
81+
82+
@Operation(summary = "Desativa um produto (ADM)")
83+
@ApiResponses(value = {
84+
@ApiResponse(responseCode = "204", description = "Produto desativado com sucesso"),
85+
@ApiResponse(responseCode = "404", description = "Produto não encontrado")
86+
})
87+
@PutMapping("/product/disable/{id}")
88+
public ResponseEntity<Response<Void>> disableProduct(@PathVariable Long id) throws Exception {
89+
admProductService.disable(id);
90+
return ResponseEntity.noContent().build();
91+
}
92+
93+
@Operation(summary = "Ativa um produto (ADM)")
94+
@ApiResponses(value = {
95+
@ApiResponse(responseCode = "200", description = "Produto ativado com sucesso",
96+
content = @Content(mediaType = "application/json",
97+
schema = @Schema(implementation = ProductDTO.class))),
98+
@ApiResponse(responseCode = "404", description = "Produto não encontrado")
99+
})
100+
@PutMapping("/product/activate/{id}")
101+
public ResponseEntity<Response<ProductDTO>> activateProduct(@PathVariable Long id) throws Exception {
102+
return ResponseEntity.ok(new Response<>(
103+
HttpStatus.OK.toString(),
104+
"Product activated successfully",
105+
admProductService.activate(id)));
106+
}
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package br.com.catalog.controller;
2+
3+
import br.com.catalog.controller.responses.Response;
4+
import br.com.catalog.services.IAuthenticationService;
5+
import br.com.catalog.services.impls.AuthenticationServiceImpl;
6+
import br.com.catalog.services.impls.dtos.AuthenticationDTO;
7+
import br.com.catalog.services.impls.dtos.RegisterDTO;
8+
import br.com.catalog.services.impls.dtos.UserResponseDTO;
9+
import jakarta.validation.Valid;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
import org.springframework.web.bind.annotation.RequestBody;
14+
import org.springframework.web.bind.annotation.RequestMapping;
15+
import org.springframework.web.bind.annotation.RestController;
16+
17+
18+
@RestController
19+
@RequestMapping("/auth")
20+
public class AuthenticationController {
21+
private final IAuthenticationService<AuthenticationDTO, UserResponseDTO, RegisterDTO> authenticationService;
22+
23+
public AuthenticationController(AuthenticationServiceImpl authenticationServiceImpl) {
24+
this.authenticationService = authenticationServiceImpl;
25+
}
26+
27+
@PostMapping("/login")
28+
public ResponseEntity<Response<String>> login(@RequestBody @Valid AuthenticationDTO dto) {
29+
return ResponseEntity.ok(new Response<>(
30+
HttpStatus.OK.toString(),
31+
"User logged in successfully",
32+
authenticationService.login(dto)));
33+
}
34+
35+
@PostMapping("/register")
36+
public ResponseEntity<Response<UserResponseDTO>> register(@RequestBody @Valid RegisterDTO dto) {
37+
return ResponseEntity.ok(new Response<>(
38+
HttpStatus.CREATED.toString(),
39+
"User created successfully",
40+
authenticationService.register(dto)));
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package br.com.catalog.controller;
2+
3+
import br.com.catalog.controller.responses.PaginationResponse;
4+
import br.com.catalog.controller.responses.Response;
5+
import br.com.catalog.services.ICrudService;
6+
import br.com.catalog.services.impls.dtos.BrandDTO;
7+
import io.swagger.v3.oas.annotations.Operation;
8+
import io.swagger.v3.oas.annotations.media.Content;
9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
12+
import jakarta.validation.Valid;
13+
import org.springframework.http.HttpStatus;
14+
import org.springframework.http.ResponseEntity;
15+
import org.springframework.web.bind.annotation.*;
16+
17+
@RestController
18+
@RequestMapping("/api/v1/brand")
19+
public class BrandController {
20+
private final ICrudService<BrandDTO, BrandDTO> brandService;
21+
22+
public BrandController(ICrudService<BrandDTO, BrandDTO> service) {
23+
this.brandService = service;
24+
}
25+
26+
@Operation(summary = "Retorna todas as marcas em paginação")
27+
@ApiResponses(value = {
28+
@ApiResponse(responseCode = "200", description = "Retorna a paginação de marcas",
29+
content = @Content(mediaType = "application/json",
30+
schema = @Schema(implementation = PaginationResponse.class))),
31+
@ApiResponse(responseCode = "400", description = "Erro de validação dos parâmetros")
32+
})
33+
@GetMapping("/getAll")
34+
public ResponseEntity<Response<PaginationResponse<BrandDTO>>> findAll(
35+
@RequestParam(defaultValue = "0") int page,
36+
@RequestParam(defaultValue = "10") int size) {
37+
return ResponseEntity.ok(new Response<>(
38+
HttpStatus.OK.toString(),
39+
"Brands found successfully",
40+
brandService.findAll(page, size)));
41+
}
42+
43+
@Operation(summary = "Busca uma marca pelo ID")
44+
@ApiResponses(value = {
45+
@ApiResponse(responseCode = "200", description = "Marca encontrada com sucesso",
46+
content = @Content(mediaType = "application/json",
47+
schema = @Schema(implementation = BrandDTO.class))),
48+
@ApiResponse(responseCode = "404", description = "Marca não encontrada")
49+
})
50+
@GetMapping("/getById/{id}")
51+
public ResponseEntity<Response<BrandDTO>> findBrandById(@PathVariable Long id) throws Exception {
52+
return ResponseEntity.ok(new Response<>(
53+
HttpStatus.OK.toString(),
54+
"Brand found successfully",
55+
brandService.findById(id)));
56+
}
57+
58+
@Operation(summary = "Busca uma marca pelo nome")
59+
@ApiResponses(value = {
60+
@ApiResponse(responseCode = "200", description = "Marca encontrada com sucesso",
61+
content = @Content(mediaType = "application/json",
62+
schema = @Schema(implementation = BrandDTO.class))),
63+
@ApiResponse(responseCode = "404", description = "Marca não encontrada")
64+
})
65+
@GetMapping("/getByName/{name}")
66+
public ResponseEntity<Response<BrandDTO>> findBrandByName(@PathVariable String name) throws Exception {
67+
return ResponseEntity.ok(new Response<>(
68+
HttpStatus.OK.toString(),
69+
"Brand found successfully",
70+
brandService.findByName(name)));
71+
}
72+
73+
@Operation(summary = "Cria uma nova marca")
74+
@ApiResponses(value = {
75+
@ApiResponse(responseCode = "201", description = "Marca criada com sucesso",
76+
content = @Content(mediaType = "application/json",
77+
schema = @Schema(implementation = BrandDTO.class))),
78+
@ApiResponse(responseCode = "400", description = "Dados inválidos")
79+
})
80+
@PostMapping("/create")
81+
public ResponseEntity<Response<BrandDTO>> createbrand(@RequestBody @Valid BrandDTO dto) {
82+
return ResponseEntity.ok(new Response<>(
83+
HttpStatus.CREATED.toString(),
84+
"Brand created successfully",
85+
brandService.create(dto)));
86+
}
87+
88+
@Operation(summary = "Atualiza uma marca existente")
89+
@ApiResponses(value = {
90+
@ApiResponse(responseCode = "200", description = "Marca atualizada com sucesso",
91+
content = @Content(mediaType = "application/json",
92+
schema = @Schema(implementation = BrandDTO.class))),
93+
@ApiResponse(responseCode = "404", description = "Marca não encontrada"),
94+
@ApiResponse(responseCode = "400", description = "Dados inválidos")
95+
})
96+
@PutMapping("/update/{id}")
97+
public ResponseEntity<Response<BrandDTO>> updateBrand(@PathVariable Long id,
98+
@RequestBody @Valid BrandDTO dto) throws Exception {
99+
return ResponseEntity.ok(new Response<>(
100+
HttpStatus.OK.toString(),
101+
"Brand updated successfully",
102+
brandService.update(id, dto)));
103+
}
104+
105+
@Operation(summary = "Deleta uma marca logicamente")
106+
@ApiResponses(value = {
107+
@ApiResponse(responseCode = "204", description = "Marca deletada com sucesso"),
108+
@ApiResponse(responseCode = "404", description = "Marca não encontrada")
109+
})
110+
@DeleteMapping("/delete/{id}")
111+
public ResponseEntity<Void> deleteBrand(@PathVariable Long id) throws Exception {
112+
brandService.delete(id);
113+
return ResponseEntity.noContent().build();
114+
}
115+
}

0 commit comments

Comments
 (0)