Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
BackEnd-V2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joel Andres Molina Velez
BackEnd-V2
Commits
c9dc2578
Commit
c9dc2578
authored
Jun 26, 2023
by
Joel Andres Molina Velez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se corrigen los servicios de ModelUzyTLineaOperativa
parent
f085138d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
51 deletions
+100
-51
UzyTavCabComcaController.java
...idad/MovilidadWS/Controller/UzyTavCabComcaController.java
+16
-10
UzyTavCabComcaMapper.java
...lidadWS/Mapper/Components_Class/UzyTavCabComcaMapper.java
+30
-3
ModelUzyTavCabComca.java
...espe/movilidad/MovilidadWS/Model/ModelUzyTavCabComca.java
+4
-10
IServiceUzyTavCabComca.java
...idadWS/Service/UzyTavCabComca/IServiceUzyTavCabComca.java
+7
-6
ServiceUzyTavCabComca.java
...lidadWS/Service/UzyTavCabComca/ServiceUzyTavCabComca.java
+43
-22
No files found.
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Controller/UzyTavCabComcaController.java
View file @
c9dc2578
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Controller
;
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Controller
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Service.UzyTavCabComca.IServiceUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Service.UzyTavCabComca.IServiceUzyTavCabComca
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
...
@@ -22,31 +23,36 @@ public class UzyTavCabComcaController {
...
@@ -22,31 +23,36 @@ public class UzyTavCabComcaController {
@GetMapping
(
"/exampleFindId/{id}"
)
@GetMapping
(
"/exampleFindId/{id}"
)
public
ResponseEntity
<
Model
UzyTavCabComca
>
ListarPorID
(
@PathVariable
Long
id
)
{
public
ResponseEntity
<
Dto
UzyTavCabComca
>
ListarPorID
(
@PathVariable
Long
id
)
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
ListarPorID
(
id
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
ListarPorID
(
id
),
HttpStatus
.
OK
);
}
}
@GetMapping
(
"/getAll"
)
@GetMapping
(
"/getAll"
)
public
ResponseEntity
<
List
<
Model
UzyTavCabComca
>>
ListarRegistros
()
{
public
ResponseEntity
<
List
<
Dto
UzyTavCabComca
>>
ListarRegistros
()
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
ListarRegistros
(),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
ListarRegistros
(),
HttpStatus
.
OK
);
}
}
@PostMapping
(
"/guardar"
)
@PostMapping
(
"/guardar"
)
public
ResponseEntity
<
ModelUzyTavCabComca
>
guardar
(
@RequestBody
ModelUzyTavCabComca
model
UzyTavCabComca
)
{
public
ResponseEntity
<
DtoUzyTavCabComca
>
guardar
(
@RequestBody
DtoUzyTavCabComca
dto
UzyTavCabComca
)
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
guardar
(
model
UzyTavCabComca
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
guardar
(
dto
UzyTavCabComca
),
HttpStatus
.
OK
);
}
}
@PutMapping
(
"/editar/{id}"
)
@PutMapping
(
"/editar/{id}"
)
public
ResponseEntity
<
ModelUzyTavCabComca
>
editar
(
@PathVariable
Long
id
,
@RequestBody
ModelUzyTavCabComca
model
UzyTavCabComca
)
{
public
ResponseEntity
<
DtoUzyTavCabComca
>
editar
(
@PathVariable
Long
id
,
@RequestBody
DtoUzyTavCabComca
dto
UzyTavCabComca
)
{
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
editar
(
id
,
model
UzyTavCabComca
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
serviceUzyTavCabComca
.
editar
(
id
,
dto
UzyTavCabComca
),
HttpStatus
.
OK
);
}
}
@DeleteMapping
(
"/eliminar/{id}"
)
@DeleteMapping
(
"/eliminar/{id}"
)
public
ResponseEntity
<
Void
>
eliminar
(
@PathVariable
Long
id
)
{
public
ResponseEntity
<
String
>
eliminar
(
@PathVariable
Long
id
){
serviceUzyTavCabComca
.
eliminar
(
id
);
boolean
eliminado
=
serviceUzyTavCabComca
.
eliminar
(
id
);
return
ResponseEntity
.
ok
().
build
();
if
(
eliminado
)
{
return
ResponseEntity
.
ok
(
"El registro se eliminó exitosamente."
);
}
else
{
return
ResponseEntity
.
notFound
().
build
();
}
}
}
}
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Mapper/Components_Class/UzyTavCabComcaMapper.java
View file @
c9dc2578
...
@@ -2,15 +2,23 @@ package ec.edu.espe.movilidad.MovilidadWS.Mapper.Components_Class;
...
@@ -2,15 +2,23 @@ package ec.edu.espe.movilidad.MovilidadWS.Mapper.Components_Class;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavConsolca
;
import
org.modelmapper.ModelMapper
;
import
org.modelmapper.ModelMapper
;
import
org.modelmapper.PropertyMap
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.persistence.EntityManager
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Component
@Component
public
class
UzyTavCabComcaMapper
{
public
class
UzyTavCabComcaMapper
{
private
final
ModelMapper
modelMapper
;
private
final
ModelMapper
modelMapper
;
private
final
EntityManager
entityManager
;
public
UzyTavCabComcaMapper
(
ModelMapper
modelMapper
)
{
public
UzyTavCabComcaMapper
(
ModelMapper
modelMapper
,
EntityManager
entityManager
)
{
this
.
modelMapper
=
modelMapper
;
this
.
modelMapper
=
modelMapper
;
this
.
entityManager
=
entityManager
;
configureMappings
();
}
}
public
DtoUzyTavCabComca
entityToDto
(
ModelUzyTavCabComca
entity
)
{
public
DtoUzyTavCabComca
entityToDto
(
ModelUzyTavCabComca
entity
)
{
...
@@ -18,6 +26,25 @@ public class UzyTavCabComcaMapper {
...
@@ -18,6 +26,25 @@ public class UzyTavCabComcaMapper {
}
}
public
ModelUzyTavCabComca
dtoToEntity
(
DtoUzyTavCabComca
dto
)
{
public
ModelUzyTavCabComca
dtoToEntity
(
DtoUzyTavCabComca
dto
)
{
return
modelMapper
.
map
(
dto
,
ModelUzyTavCabComca
.
class
);
ModelUzyTavCabComca
entity
=
modelMapper
.
map
(
dto
,
ModelUzyTavCabComca
.
class
);
Long
consolcaID
=
dto
.
getUzytavconsolca_id
();
ModelUzyTavConsolca
valorPar
=
entityManager
.
find
(
ModelUzyTavConsolca
.
class
,
consolcaID
);
entity
.
setUzytavconsolca
(
valorPar
);
return
entity
;
}
public
List
<
DtoUzyTavCabComca
>
entitiesToDtos
(
List
<
ModelUzyTavCabComca
>
entities
)
{
return
entities
.
stream
()
.
map
(
this
::
entityToDto
)
.
collect
(
Collectors
.
toList
());
}
private
void
configureMappings
()
{
modelMapper
.
addMappings
(
new
PropertyMap
<
ModelUzyTavCabComca
,
DtoUzyTavCabComca
>()
{
@Override
protected
void
configure
()
{
map
().
setUzytavcabcomca_id
(
source
.
getUzytavcabcomca_id
());
map
().
setUzytavconsolca_id
(
source
.
getUzytavconsolca
().
getUzytavconsolca_id
());
}
});
}
}
}
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Model/ModelUzyTavCabComca.java
View file @
c9dc2578
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Model
;
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Model
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.Set
;
import
java.util.Set
;
@Data
@Getter
@Setter
@Entity
@Entity
@Table
(
name
=
"uzytavcabcomca"
,
schema
=
"UTIC1"
)
@Table
(
name
=
"uzytavcabcomca"
,
schema
=
"UTIC1"
)
public
class
ModelUzyTavCabComca
{
public
class
ModelUzyTavCabComca
{
...
@@ -27,28 +29,20 @@ public class ModelUzyTavCabComca {
...
@@ -27,28 +29,20 @@ public class ModelUzyTavCabComca {
//RELACION CON PROYECT- cabcomca es la padre
//RELACION CON PROYECT- cabcomca es la padre
//@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
//@JoinColumn(name = "uzytavcabcomca_id", referencedColumnName = "uzytavcabcomca_id")
//Set<ModelUzyTavProyec> modelUzyTavProyecss = new HashSet<>();
@JsonIgnore
@JsonIgnore
@OneToMany
(
mappedBy
=
"uzytavcabcomca"
,
cascade
=
CascadeType
.
ALL
)
@OneToMany
(
mappedBy
=
"uzytavcabcomca"
,
cascade
=
CascadeType
.
ALL
)
private
Set
<
ModelUzyTavProyec
>
modelUzyTavProyecs
;
private
Set
<
ModelUzyTavProyec
>
modelUzyTavProyecs
;
//RELACION CON DETCOMCA-Tabla Hija
//RELACION CON DETCOMCA-Tabla Hija
//
@JsonIgnore
@JsonIgnore
@OneToMany
(
mappedBy
=
"uzytavcabcomca"
,
cascade
=
CascadeType
.
ALL
)
@OneToMany
(
mappedBy
=
"uzytavcabcomca"
,
cascade
=
CascadeType
.
ALL
)
private
Set
<
ModelUzyTavDetComca
>
modelUzyTavDetComcas
;
private
Set
<
ModelUzyTavDetComca
>
modelUzyTavDetComcas
;
///fetch = FetchType.LAZY
//RELACIÓN CON CONSOLCA- TABLA PADRE
//RELACIÓN CON CONSOLCA- TABLA PADRE
@JsonIgnore
@JsonIgnore
@ManyToOne
@ManyToOne
@JoinColumn
(
name
=
"uzytavconsolca_id"
)
@JoinColumn
(
name
=
"uzytavconsolca_id"
)
private
ModelUzyTavConsolca
uzytavconsolca
;
private
ModelUzyTavConsolca
uzytavconsolca
;
}
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Service/UzyTavCabComca/IServiceUzyTavCabComca.java
View file @
c9dc2578
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Service
.
UzyTavCabComca
;
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Service
.
UzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
java.util.List
;
import
java.util.List
;
public
interface
IServiceUzyTavCabComca
{
public
interface
IServiceUzyTavCabComca
{
public
Model
UzyTavCabComca
ListarPorID
(
Long
id
);
Dto
UzyTavCabComca
ListarPorID
(
Long
id
);
public
List
<
Model
UzyTavCabComca
>
ListarRegistros
();
List
<
Dto
UzyTavCabComca
>
ListarRegistros
();
public
ModelUzyTavCabComca
guardar
(
ModelUzyTavCabComca
model
UzyTavCabComca
);
DtoUzyTavCabComca
guardar
(
DtoUzyTavCabComca
dto
UzyTavCabComca
);
public
ModelUzyTavCabComca
editar
(
Long
id
,
ModelUzyTavCabComca
model
UzyTavCabComca
);
DtoUzyTavCabComca
editar
(
Long
id
,
DtoUzyTavCabComca
dto
UzyTavCabComca
);
void
eliminar
(
Long
id
);
boolean
eliminar
(
Long
id
);
}
}
src/main/java/ec/edu/espe/movilidad/MovilidadWS/Service/UzyTavCabComca/ServiceUzyTavCabComca.java
View file @
c9dc2578
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Service
.
UzyTavCabComca
;
package
ec
.
edu
.
espe
.
movilidad
.
MovilidadWS
.
Service
.
UzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dao.DaoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dao.DaoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Dto.DtoUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Exceptions.ResourceNotFoundException
;
import
ec.edu.espe.movilidad.MovilidadWS.Mapper.Components_Class.UzyTavCabComcaMapper
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
ec.edu.espe.movilidad.MovilidadWS.Model.ModelUzyTavCabComca
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
@@ -10,40 +12,59 @@ import java.util.List;
...
@@ -10,40 +12,59 @@ import java.util.List;
@Service
@Service
public
class
ServiceUzyTavCabComca
implements
IServiceUzyTavCabComca
{
public
class
ServiceUzyTavCabComca
implements
IServiceUzyTavCabComca
{
@Autowired
private
final
DaoUzyTavCabComca
daoUzyTavCabComca
;
DaoUzyTavCabComca
daoUzyTavCabComca
;
private
final
UzyTavCabComcaMapper
mapper
;
public
ServiceUzyTavCabComca
(
DaoUzyTavCabComca
daoUzyTavCabComca
,
UzyTavCabComcaMapper
mapper
)
{
this
.
daoUzyTavCabComca
=
daoUzyTavCabComca
;
this
.
mapper
=
mapper
;
}
@Override
@Override
public
ModelUzyTavCabComca
ListarPorID
(
@PathVariable
Long
id
)
{
public
DtoUzyTavCabComca
ListarPorID
(
@PathVariable
Long
id
)
{
return
daoUzyTavCabComca
.
findById
(
id
).
get
();
ModelUzyTavCabComca
entity
=
daoUzyTavCabComca
.
findById
(
id
)
.
orElseThrow
(()
->
new
ResourceNotFoundException
(
"No se encontró el registro con ID: "
+
id
));
return
mapper
.
entityToDto
(
entity
);
}
}
@Override
@Override
public
List
<
ModelUzyTavCabComca
>
ListarRegistros
()
{
public
List
<
DtoUzyTavCabComca
>
ListarRegistros
()
{
return
daoUzyTavCabComca
.
findAll
();
List
<
ModelUzyTavCabComca
>
entities
=
daoUzyTavCabComca
.
findAll
();
return
mapper
.
entitiesToDtos
(
entities
);
}
}
@Override
@Override
public
ModelUzyTavCabComca
guardar
(
ModelUzyTavCabComca
modelUzyTavCabComca
)
{
public
DtoUzyTavCabComca
guardar
(
DtoUzyTavCabComca
dtoUzyTavCabComca
)
{
return
daoUzyTavCabComca
.
save
(
modelUzyTavCabComca
);
ModelUzyTavCabComca
entity
=
mapper
.
dtoToEntity
(
dtoUzyTavCabComca
);
ModelUzyTavCabComca
nuevoEntity
=
daoUzyTavCabComca
.
save
(
entity
);
return
mapper
.
entityToDto
(
nuevoEntity
);
}
}
@Override
@Override
public
ModelUzyTavCabComca
editar
(
@PathVariable
Long
id
,
ModelUzyTavCabComca
modelUzyTavCabComca
)
{
public
DtoUzyTavCabComca
editar
(
@PathVariable
Long
id
,
DtoUzyTavCabComca
dtoUzyTavCabComca
)
{
ModelUzyTavCabComca
dato
=
daoUzyTavCabComca
.
findById
(
id
).
get
();
try
{
//.orElseThrow(()->new ControlExcepciones("No existe el registro con el ID : " + id));
ModelUzyTavCabComca
entity
=
daoUzyTavCabComca
.
findById
(
id
).
get
();
//Seteamos los nuevos datos del registro
dato
.
setUzytavcabcomca_id
(
modelUzyTavCabComca
.
getUzytavcabcomca_id
());
dato
.
setUzytavcabcomca_decsrip
(
modelUzyTavCabComca
.
getUzytavcabcomca_decsrip
());
dato
.
setUzytavcabcomca_fech_crea
(
modelUzyTavCabComca
.
getUzytavcabcomca_fech_crea
());
ModelUzyTavCabComca
datoActualizado
=
daoUzyTavCabComca
.
save
(
dato
);
if
(
entity
!=
null
)
{
return
datoActualizado
;
entity
.
setUzytavcabcomca_decsrip
(
dtoUzyTavCabComca
.
getUzytavcabcomca_decsrip
());
entity
.
setUzytavcabcomca_fech_crea
(
dtoUzyTavCabComca
.
getUzytavcabcomca_fech_crea
());
ModelUzyTavCabComca
updatedEntity
=
daoUzyTavCabComca
.
save
(
entity
);
return
mapper
.
entityToDto
(
updatedEntity
);
}
else
{
throw
new
ResourceNotFoundException
(
"No se encontró el registro con ID: "
+
id
);
}
}
catch
(
Exception
e
)
{
throw
new
ResourceNotFoundException
(
"Error al editar el registro: "
+
e
.
getMessage
());
}
}
}
@Override
@Override
public
void
eliminar
(
@PathVariable
Long
id
)
{
public
boolean
eliminar
(
Long
id
)
{
ModelUzyTavCabComca
dato
=
daoUzyTavCabComca
.
findById
(
id
).
get
();
ModelUzyTavCabComca
entity
=
daoUzyTavCabComca
.
findById
(
id
).
orElse
(
null
);
//.orElseThrow(() -> new ControlExcepciones("No existe el registro con el ID : " + id));
if
(
entity
!=
null
)
{
daoUzyTavCabComca
.
delete
(
dato
);
daoUzyTavCabComca
.
delete
(
entity
);
return
true
;
}
return
false
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment