Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
users
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
viccall
users
Commits
27476fe9
Commit
27476fe9
authored
4 months ago
by
Victor
Browse files
Options
Downloads
Patches
Plain Diff
finsihs
parent
d63d63b7
No related branches found
Branches containing commit
Tags
2.3_Ejercicio_1
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/uva/users/Controller/ControllerVinos.java
+46
-12
46 additions, 12 deletions
src/main/java/com/uva/users/Controller/ControllerVinos.java
with
46 additions
and
12 deletions
src/main/java/com/uva/users/Controller/ControllerVinos.java
+
46
−
12
View file @
27476fe9
...
...
@@ -12,6 +12,8 @@ import com.uva.users.Repository.BodegaRepository;
import
com.uva.users.Repository.VinoConRelacionRepository
;
import
com.uva.users.Repository.VinoRepository
;
import
jakarta.persistence.Column
;
import
java.util.*
;
@RestController
...
...
@@ -33,10 +35,52 @@ public class ControllerVinos {
}
@PutMapping
(
"/{id}"
)
public
String
putVinos
(
@RequestBody
String
body
,
@PathVariable
(
"id"
)
Long
identificador
)
{
return
"Realizada operación Put. Con Id: "
+
identificador
+
". Contenido del cuerpo de la petición: "
+
body
;
public
String
putVinos
(
@RequestBody
Vino
vino
,
@PathVariable
(
"id"
)
Integer
identificador
)
{
Optional
<
Vino
>
vinoExistente
=
repository
.
findById
(
identificador
);
if
(
vinoExistente
.
isPresent
())
{
Vino
vinoActualizado
=
vinoExistente
.
get
();
vinoActualizado
.
setNombreComercial
(
vino
.
getNombreComercial
());
vinoActualizado
.
setBodegaId
(
vino
.
getBodegaId
());
vinoActualizado
.
setPrecio
(
vino
.
getPrecio
());
vinoActualizado
.
setDenominacion
(
vino
.
getDenominacion
());
vinoActualizado
.
setCategoria
(
vino
.
getCategoria
());
repository
.
save
(
vinoActualizado
);
// Guarda el vino actualizado
return
"Vino con ID "
+
identificador
+
" actualizado correctamente."
;
}
else
{
return
"Vino con ID "
+
identificador
+
" no encontrado."
;
}
}
@DeleteMapping
(
"/{id}"
)
public
String
deleteVino
(
@PathVariable
(
"id"
)
Integer
identificador
)
{
Optional
<
Vino
>
vinoExistente
=
repository
.
findById
(
identificador
);
// Buscar vino por ID
if
(
vinoExistente
.
isPresent
())
{
repository
.
delete
(
vinoExistente
.
get
());
// Eliminar el vino
return
"Vino con ID "
+
identificador
+
" eliminado correctamente."
;
}
else
{
return
"Vino con ID "
+
identificador
+
" no encontrado."
;
}
}
@PostMapping
(
"/newVino"
)
public
String
newVino
(
@RequestBody
Vino
newVino
)
{
try
{
repository
.
save
(
newVino
);
return
"Nuevo registro creado"
;
}
catch
(
Exception
e
)
{
throw
new
VinoException
(
"Error al crear el nuevo registro."
);
}
}
// CODIGO NO IMPORTANTE PARA ESTA ENTREGA
@PostMapping
(
"/vinos"
)
public
String
postVinos
(
@RequestBody
String
body
)
{
return
"Post: "
+
body
;
...
...
@@ -83,16 +127,6 @@ public class ControllerVinos {
return
respuesta
.
toString
();
}
@PostMapping
(
"/newVino"
)
public
String
newVino
(
@RequestBody
Vino
newVino
)
{
try
{
repository
.
save
(
newVino
);
return
"Nuevo registro creado"
;
}
catch
(
Exception
e
)
{
throw
new
VinoException
(
"Error al crear el nuevo registro."
);
}
}
@GetMapping
(
"/VinoPorNombre/{nombre}"
)
public
Vino
getVinoPorNombre_Comercial
(
@PathVariable
String
nombre
)
{
Vino
vino
=
repository
.
findByNombreComercial
(
nombre
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment