Skip to content

Commit 9ee8a86

Browse files
committed
feat: implement adm controller with ADMIN-Ops
1 parent a997f11 commit 9ee8a86

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-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+
}

0 commit comments

Comments
 (0)