Skip to content

Commit f1a1b26

Browse files
author
andres
committed
Updated Controllers
1 parent 9f323cf commit f1a1b26

15 files changed

+829
-263
lines changed

pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,12 @@
4444
<optional>true</optional>
4545
</dependency>
4646

47-
<!-- SWAGGER WITH OPENAPI-UI -->
47+
<!-- OPENAPI-UI -->
4848
<dependency>
4949
<groupId>org.springdoc</groupId>
5050
<artifactId>springdoc-openapi-ui</artifactId>
5151
<version>1.6.4</version>
5252
</dependency>
53-
<!-- ANOTATIONS SWAGGER -->
54-
<!-- https://mvnrepository.com/artifact/io.swagger/swagger-annotations -->
55-
<dependency>
56-
<groupId>io.swagger</groupId>
57-
<artifactId>swagger-annotations</artifactId>
58-
<version>1.6.3</version>
59-
</dependency>
60-
6153

6254

6355

src/main/java/com/api/rest/microelectronica/ApiRestMicroelectronicaApplication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

6+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
7+
68
@SpringBootApplication
9+
@OpenAPIDefinition
710
public class ApiRestMicroelectronicaApplication {
811

912
public static void main(String[] args) {

src/main/java/com/api/rest/microelectronica/controllers/ComponenteCapacitorElectroliticoController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
@RestController
21-
@RequestMapping("/componentes-capacitores-electroliticos")
21+
@RequestMapping("/v1/componentes-capacitores-electroliticos")
2222
public class ComponenteCapacitorElectroliticoController {
2323

2424
@Autowired
Lines changed: 161 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.api.rest.microelectronica.controllers;
22

3-
import java.util.List;
3+
44
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.data.domain.Page;
56
import org.springframework.data.domain.Pageable;
67
import org.springframework.web.bind.annotation.DeleteMapping;
78
import org.springframework.web.bind.annotation.GetMapping;
@@ -15,9 +16,13 @@
1516
import com.api.rest.microelectronica.entities.ComponenteEntity;
1617
import com.api.rest.microelectronica.services.ComponenteService;
1718

19+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
20+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
21+
import io.swagger.v3.oas.annotations.media.Content;
22+
import io.swagger.v3.oas.annotations.Operation;
1823

1924
@RestController
20-
@RequestMapping("/componentes")
25+
@RequestMapping("/v1/componentes")
2126
public class ComponenteController {
2227

2328
@Autowired
@@ -27,31 +32,67 @@ public class ComponenteController {
2732
// ============= MÉTODOS HTTP CRUD ==============
2833
// ===============================================
2934

30-
// ----POST----
35+
// ================
36+
// ===== POST =====
37+
// =================
38+
@Operation(summary = "Inserción de un Componente")
39+
@ApiResponses(value = {
40+
@ApiResponse(responseCode = "200", description = "Se ha Insertado el Componente Correctamente", content = {
41+
@Content(mediaType = "application/json") }),
42+
@ApiResponse(responseCode = "400", description = "No se pudo Insertar el Componente. Comprobar la Solicitud", content = @Content),
43+
@ApiResponse(responseCode = "404", description = "La Inserción del Componente no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
44+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
3145
@PostMapping("/")
32-
public boolean addComponente(@RequestBody ComponenteEntity componente) {
46+
public void addComponente(@RequestBody ComponenteEntity componente) {
3347

34-
return componenteService.addComponente(componente);
48+
componenteService.addComponente(componente);
3549
}
3650

37-
// ----PUT-----
51+
// ================
52+
// ===== PUT=====
53+
// =================
54+
@Operation(summary = "Actualización de un Componente")
55+
@ApiResponses(value = {
56+
@ApiResponse(responseCode = "200", description = "Se ha Actualizado el Componente Correctamente", content = {
57+
@Content(mediaType = "application/json") }),
58+
@ApiResponse(responseCode = "400", description = "No se pudo Actualizar el Componente. Comprobar la Solicitud", content = @Content),
59+
@ApiResponse(responseCode = "404", description = "La Actualización del Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
60+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
3861
@PutMapping("/")
39-
public boolean updateComponente(@RequestBody ComponenteEntity componente) {
62+
public void updateComponente(@RequestBody ComponenteEntity componente) {
4063

41-
return componenteService.updateComponente(componente);
64+
componenteService.updateComponente(componente);
4265
}
4366

44-
// ---DELETE---
67+
// ==================
68+
// ===== DELETE =====
69+
// ==================
70+
@Operation(summary = "Eliminación de un Componente por su ID")
71+
@ApiResponses(value = {
72+
@ApiResponse(responseCode = "200", description = "Se ha Eliminado el Componente Correctamente", content = {
73+
@Content(mediaType = "application/json") }),
74+
@ApiResponse(responseCode = "400", description = "No se pudo Eliminar el Componente. Comprobar la Solicitud", content = @Content),
75+
@ApiResponse(responseCode = "404", description = "La Eliminación del Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
76+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
4577
@DeleteMapping("/{id}")
46-
public boolean deleteComponente(@PathVariable("id") int id) {
78+
public void deleteComponente(@PathVariable("id") int id) {
4779

48-
return componenteService.deleteComponente(id);
80+
componenteService.deleteComponente(id);
4981
}
5082

51-
// ---GET---
83+
// ===============
84+
// ===== GET =====
85+
// ===============
5286
// ---LISTADO PAGINADO Y COMPLETO---
87+
@Operation(summary = "Listado Paginado de Componentes")
88+
@ApiResponses(value = {
89+
@ApiResponse(responseCode = "200", description = "Se ha Traído el Listado de Componentes", content = {
90+
@Content(mediaType = "application/json") }),
91+
@ApiResponse(responseCode = "400", description = "No se pudo traer el Listado de Componentes. Comprobar la Solicitud", content = @Content),
92+
@ApiResponse(responseCode = "404", description = "El Listado de Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
93+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
5394
@GetMapping("/listado")
54-
public List<ComponenteEntity> getAll(Pageable pageable) {
95+
public Page<ComponenteEntity> getAll(Pageable pageable) {
5596

5697
return componenteService.getAllComponente(pageable);
5798
}
@@ -60,69 +101,148 @@ public List<ComponenteEntity> getAll(Pageable pageable) {
60101
// ============= MÉTODOS HTTP BÚSQUEDA =============
61102
// ==================================================
62103

63-
// ---GET---
64-
@PostMapping("/id/{id}")
104+
// ===============
105+
// ===== GET =====
106+
// ===============
107+
@Operation(summary = "Búsqueda de un Componente por su ID")
108+
@ApiResponses(value = {
109+
@ApiResponse(responseCode = "200", description = "Se ha Traído el Componente Correctamente", content = {
110+
@Content(mediaType = "application/json") }),
111+
@ApiResponse(responseCode = "400", description = "No se pudo Encontrar el Componente. Comprobar la Solicitud", content = @Content),
112+
@ApiResponse(responseCode = "404", description = "La Búsqueda del Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
113+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
114+
@GetMapping("/id/{id}")
65115
public ComponenteEntity getById(@PathVariable("id") int id) {
66116

67117
return componenteService.findById(id);
68118
}
69119

70-
// ---GET---
120+
// ===============
121+
// ===== GET =====
122+
// ===============
123+
@Operation(summary = "Búsqueda Paginada de Componentes por su Código")
124+
@ApiResponses(value = {
125+
@ApiResponse(responseCode = "200", description = "Se han Traído los Componentes Correctamente", content = {
126+
@Content(mediaType = "application/json") }),
127+
@ApiResponse(responseCode = "400", description = "No se pudieron Encontrar los Componentes. Comprobar la Solicitud", content = @Content),
128+
@ApiResponse(responseCode = "404", description = "La Búsqueda de los Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
129+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
71130
@GetMapping("/codigo/{codigo}")
72-
public List<ComponenteEntity> getByCodigo(@PathVariable("codigo") String codigo) {
131+
public Page<ComponenteEntity> getByCodigo(@PathVariable("codigo") String codigo, Pageable pageable) {
73132

74-
return componenteService.findByCodigo(codigo);
133+
return componenteService.findByCodigo(codigo, pageable);
75134
}
76135

77-
// ---GET---
136+
// ===============
137+
// ===== GET =====
138+
// ===============
139+
@Operation(summary = "Búsqueda Paginada de Componentes por su Imagen")
140+
@ApiResponses(value = {
141+
@ApiResponse(responseCode = "200", description = "Se han Traído los Componentes Correctamente", content = {
142+
@Content(mediaType = "application/json") }),
143+
@ApiResponse(responseCode = "400", description = "No se pudieron Encontrar los Componentes. Comprobar la Solicitud", content = @Content),
144+
@ApiResponse(responseCode = "404", description = "La Búsqueda de los Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
145+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
78146
@GetMapping("/imagen/{imagen}")
79-
public List<ComponenteEntity> getByImagen(@PathVariable("imagen") String imagen) {
147+
public Page<ComponenteEntity> getByImagen(@PathVariable("imagen") String imagen, Pageable pageable) {
80148

81-
return componenteService.findByImagen(imagen);
149+
return componenteService.findByImagen(imagen, pageable);
82150
}
83151

84-
// ---GET---
152+
// ===============
153+
// ===== GET =====
154+
// ===============
155+
@Operation(summary = "Búsqueda Paginada de Componentes por su Número de Piezas")
156+
@ApiResponses(value = {
157+
@ApiResponse(responseCode = "200", description = "Se han Traído los Componentes Correctamente", content = {
158+
@Content(mediaType = "application/json") }),
159+
@ApiResponse(responseCode = "400", description = "No se pudieron Encontrar los Componentes. Comprobar la Solicitud", content = @Content),
160+
@ApiResponse(responseCode = "404", description = "La Búsqueda de los Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
161+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
85162
@GetMapping("/nro-de-pieza/{nroPieza}")
86-
public List<ComponenteEntity> getByNroPieza(@PathVariable("nroPieza") String nroPieza) {
163+
public Page<ComponenteEntity> getByNroPieza(@PathVariable("nroPieza") String nroPieza, Pageable pageable) {
87164

88-
return componenteService.findByNroPieza(nroPieza);
165+
return componenteService.findByNroPieza(nroPieza, pageable);
89166
}
90167

91-
// ---GET---
168+
// ===============
169+
// ===== GET =====
170+
// ===============
171+
@Operation(summary = "Búsqueda Paginada de Componentes por su Categoría")
172+
@ApiResponses(value = {
173+
@ApiResponse(responseCode = "200", description = "Se han Traído los Componentes Correctamente", content = {
174+
@Content(mediaType = "application/json") }),
175+
@ApiResponse(responseCode = "400", description = "No se pudieron Encontrar los Componentes. Comprobar la Solicitud", content = @Content),
176+
@ApiResponse(responseCode = "404", description = "La Búsqueda de los Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
177+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
92178
@GetMapping("/categoria/{categoria}")
93-
public List<ComponenteEntity> getByCategoria(@PathVariable("nroPieza") String nroPieza) {
179+
public Page<ComponenteEntity> getByCategoria(@PathVariable("nroPieza") String nroPieza, Pageable pageable) {
94180

95-
return componenteService.findByNroPieza(nroPieza);
181+
return componenteService.findByNroPieza(nroPieza, pageable);
96182
}
97183

98-
// ---GET---
184+
// ===============
185+
// ===== GET =====
186+
// ===============
187+
@Operation(summary = "Búsqueda Paginada de Componentes por su Descripción")
188+
@ApiResponses(value = {
189+
@ApiResponse(responseCode = "200", description = "Se han Traído los Componentes Correctamente", content = {
190+
@Content(mediaType = "application/json") }),
191+
@ApiResponse(responseCode = "400", description = "No se pudieron Encontrar los Componentes. Comprobar la Solicitud", content = @Content),
192+
@ApiResponse(responseCode = "404", description = "La Búsqueda de los Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
193+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
99194
@GetMapping("/descripcion/{descripcion}")
100-
public List<ComponenteEntity> getByDescripcion(@PathVariable("descripcion") String descripcion) {
195+
public Page<ComponenteEntity> getByDescripcion(@PathVariable("descripcion") String descripcion, Pageable pageable) {
101196

102-
return componenteService.findByDescripcion(descripcion);
197+
return componenteService.findByDescripcion(descripcion, pageable);
103198
}
104199

105-
// ---GET---
200+
// ===============
201+
// ===== GET =====
202+
// ===============
203+
@Operation(summary = "Búsqueda Paginada de Componentes por su Fabricante")
204+
@ApiResponses(value = {
205+
@ApiResponse(responseCode = "200", description = "Se han Traído los Componentes Correctamente", content = {
206+
@Content(mediaType = "application/json") }),
207+
@ApiResponse(responseCode = "400", description = "No se pudieron Encontrar los Componentes. Comprobar la Solicitud", content = @Content),
208+
@ApiResponse(responseCode = "404", description = "La Búsqueda de los Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
209+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
106210
@GetMapping("/fabricante/{fabricante}")
107-
public List<ComponenteEntity> getByFabricante(@PathVariable("fabricante") String fabricante) {
211+
public Page<ComponenteEntity> getByFabricante(@PathVariable("fabricante") String fabricante, Pageable pageable) {
108212

109-
return componenteService.findByFabricante(fabricante);
213+
return componenteService.findByFabricante(fabricante, pageable);
110214
}
111215

112-
// ---GET---
216+
// ===============
217+
// ===== GET =====
218+
// ===============
219+
@Operation(summary = "Búsqueda Paginada de Componentes por su Stock")
220+
@ApiResponses(value = {
221+
@ApiResponse(responseCode = "200", description = "Se han Traído los Componentes Correctamente", content = {
222+
@Content(mediaType = "application/json") }),
223+
@ApiResponse(responseCode = "400", description = "No se pudieron Encontrar los Componentes. Comprobar la Solicitud", content = @Content),
224+
@ApiResponse(responseCode = "404", description = "La Búsqueda de los Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
225+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
113226
@GetMapping("/stock/{stock}")
114-
public List<ComponenteEntity> getByStock(@PathVariable("stock") int stock) {
227+
public Page<ComponenteEntity> getByStock(@PathVariable("stock") int stock, Pageable pageable) {
115228

116-
return componenteService.findByStock(stock);
229+
return componenteService.findByStock(stock, pageable);
117230
}
118231

119-
// ---GET---
232+
// ===============
233+
// ===== GET =====
234+
// ===============
235+
@Operation(summary = "Búsqueda Paginada de Componentes por su Precio")
236+
@ApiResponses(value = {
237+
@ApiResponse(responseCode = "200", description = "Se han Traído los Componentes Correctamente", content = {
238+
@Content(mediaType = "application/json") }),
239+
@ApiResponse(responseCode = "400", description = "No se pudieron Encontrar los Componentes. Comprobar la Solicitud", content = @Content),
240+
@ApiResponse(responseCode = "404", description = "La Búsqueda de los Componentes no está Disponible ya que el recurso pedido no existe. Comprobar solicitud", content = @Content),
241+
@ApiResponse(responseCode = "500", description = "Se ha producido un error interno en el Servidor", content = @Content) })
120242
@GetMapping("/precio/{precio}")
121-
public List<ComponenteEntity> getByPrecio(@PathVariable("precio") double precio) {
243+
public Page<ComponenteEntity> getByPrecio(@PathVariable("precio") double precio, Pageable pageable) {
122244

123-
return componenteService.findByPrecio(precio);
245+
return componenteService.findByPrecio(precio, pageable);
124246
}
125247

126-
127-
128248
}

0 commit comments

Comments
 (0)