Skip to content

Commit 0e3c3a0

Browse files
committed
Merge branch 'controllers' into dev
2 parents b8532e6 + 9ee8a86 commit 0e3c3a0

File tree

6 files changed

+420
-0
lines changed

6 files changed

+420
-0
lines changed
Lines changed: 107 additions & 0 deletions
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+
}
Lines changed: 42 additions & 0 deletions
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+
}
Lines changed: 115 additions & 0 deletions
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+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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.ProductDTO;
7+
import br.com.catalog.services.impls.dtos.UpdatedProductDTO;
8+
import io.swagger.v3.oas.annotations.Operation;
9+
import io.swagger.v3.oas.annotations.media.Content;
10+
import io.swagger.v3.oas.annotations.media.Schema;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
12+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
13+
import jakarta.validation.Valid;
14+
import org.springframework.http.HttpStatus;
15+
import org.springframework.http.ResponseEntity;
16+
import org.springframework.web.bind.annotation.*;
17+
18+
@RestController
19+
@RequestMapping("/api/v1/product")
20+
public class ProductController {
21+
private final ICrudService<ProductDTO, UpdatedProductDTO> productService;
22+
23+
public ProductController(ICrudService<ProductDTO, UpdatedProductDTO> productService) {
24+
this.productService = productService;
25+
}
26+
27+
@Operation(summary = "Retorna todos os produtos em paginação")
28+
@ApiResponses(value = {
29+
@ApiResponse(responseCode = "200", description = "Retorna a paginação de produtos",
30+
content = @Content(mediaType = "application/json",
31+
schema = @Schema(implementation = PaginationResponse.class))),
32+
@ApiResponse(responseCode = "400", description = "Erro de validação dos parâmetros")
33+
})
34+
@GetMapping("/getAll")
35+
public ResponseEntity<Response<PaginationResponse<ProductDTO>>> getAllProducts(
36+
@RequestParam(defaultValue = "0") int page,
37+
@RequestParam(defaultValue = "10")int size) {
38+
return ResponseEntity.ok(new Response<>(
39+
HttpStatus.OK.toString(),
40+
"Products found successfully",
41+
productService.findAll(page, size)));
42+
}
43+
44+
@Operation(summary = "Cria um novo produto")
45+
@ApiResponses(value = {
46+
@ApiResponse(responseCode = "201", description = "Produto criado com sucesso",
47+
content = @Content(mediaType = "application/json",
48+
schema = @Schema(implementation = ProductDTO.class))),
49+
@ApiResponse(responseCode = "400", description = "Erro de validação dos parâmetros")
50+
})
51+
@PostMapping("/create")
52+
public ResponseEntity<Response<ProductDTO>> createProduct(@RequestBody @Valid ProductDTO dto) {
53+
return ResponseEntity.ok(new Response<>(
54+
HttpStatus.CREATED.toString(),
55+
"Product created successfully",
56+
productService.create(dto)));
57+
}
58+
59+
@Operation(summary = "Retorna um produto pelo ID")
60+
@ApiResponses(value = {
61+
@ApiResponse(responseCode = "200", description = "Produto encontrado com sucesso",
62+
content = @Content(mediaType = "application/json",
63+
schema = @Schema(implementation = ProductDTO.class))),
64+
@ApiResponse(responseCode = "404", description = "Produto não encontrado")
65+
})
66+
@GetMapping("/getById/{id}")
67+
public ResponseEntity<Response<ProductDTO>> getProductById(@PathVariable Long id) throws Exception {
68+
return ResponseEntity.ok(new Response<>(
69+
HttpStatus.OK.toString(),
70+
"Product found successfully",
71+
productService.findById(id)));
72+
}
73+
74+
@Operation(summary = "Retorna um produto pelo nome")
75+
@ApiResponses(value = {
76+
@ApiResponse(responseCode = "200", description = "Produto encontrado com sucesso",
77+
content = @Content(mediaType = "application/json",
78+
schema = @Schema(implementation = ProductDTO.class))),
79+
@ApiResponse(responseCode = "404", description = "Produto não encontrado")
80+
})
81+
@GetMapping("/getByName/{name}")
82+
public ResponseEntity<Response<ProductDTO>> getProductByName(@PathVariable String name) throws Exception {
83+
return ResponseEntity.ok(new Response<>(
84+
HttpStatus.OK.toString(),
85+
"Product found successfully",
86+
productService.findByName(name)));
87+
}
88+
89+
@Operation(summary = "Atualiza um produto")
90+
@ApiResponses(value = {
91+
@ApiResponse(responseCode = "200", description = "Produto atualizado com sucesso",
92+
content = @Content(mediaType = "application/json",
93+
schema = @Schema(implementation = ProductDTO.class))),
94+
@ApiResponse(responseCode = "400", description = "Erro de validação dos parâmetros"),
95+
@ApiResponse(responseCode = "404", description = "Produto não encontrado")
96+
})
97+
@PutMapping("/update/{id}")
98+
public ResponseEntity<Response<ProductDTO>> updateProduct(@PathVariable Long id,
99+
@RequestBody @Valid UpdatedProductDTO dto) throws Exception {
100+
return ResponseEntity.ok(new Response<>(
101+
HttpStatus.OK.toString(),
102+
"Product updated successfully",
103+
productService.update(id, dto)));
104+
}
105+
106+
@Operation(summary = "Deleta logicamente um produto")
107+
@ApiResponses(value = {
108+
@ApiResponse(responseCode = "204", description = "Produto deletado com sucesso"),
109+
@ApiResponse(responseCode = "404", description = "Produto não encontrado")
110+
})
111+
@DeleteMapping("/delete/{id}")
112+
public ResponseEntity<Void> deleteProduct(@PathVariable Long id) throws Exception {
113+
productService.delete(id);
114+
return ResponseEntity.noContent().build();
115+
}
116+
}

0 commit comments

Comments
 (0)